Newsgroup: it.hobby.elettronica.digitale
Titolo: Problemi compilazione programma per pic12c509

Vediamo se potete aiutarmi, ho trovato in rete uno schema per costruire un
regolatore di velocità per motorini elettrici con pic. Ho trovato il file
.asm, il file . inc e anche il file .hex, volevo provare a compilare io il
programma ma riscontro grosse difficoltà, il compilatore MPASM mi trova
molti errori nel file .inc con esattezza mi dice:
 Error[118]   C:\MOTORE\SPEED400.INC 8 : Overwriting previous address
contents (0200)
......
......
Error[118]   C:\MOTORE\SPEED400.INC 146 : Overwriting previous address
contents (028A)
non capisco come posso fare a risolvere il problema.
Se può esservi d'aiuto allego il listato dei file .asm e .inc
Grazie anticipatamente a chiunque risolva il problema
----------------------------------------------------------------------------
-----------------------------------
SPEED400.ASM
; ==========================================================================
; Speed 400 speed controller embedded program
; speed400.asm
;
; ################ Copyright 1998 Michael J. Norton ######################
; ######## May be copied as desired and modified as needed ###############
; ######### so long as this copyright notice is preserved ################
;
; The processor and radix statement are commented out because the mplab
; environment provides them on the command line, and the assembler issues
; messages as a result of the dual definition.
;               PROCESSOR PIC12C509
                INCLUDE   <P12C509.inc>
;               radix     dec
; ==========================================================================
; Configuration is:
;   Master clear pin is disabled (used as input)
;   Code protection is OFF
;   Watchdog timer is ON
;   Oscillator is internal RC
                __config  _MCLRE_OFF & _CP_OFF & _WDT_ON & _IntRC_OSC
; Erasable unit control - set to 1 of osccal value has been erased.  It will
; use a nominal half scale value.  Set to 0 for OTP parts.
NO_OSCCAL_VALUE EQU       0
; Bit definitions for the GPIO register and theTRIS register
StopBit         EQU       1               ; Turns on brake
RunBit          EQU       2               ; Turns on motor
ServoBit        EQU       0               ; Input servo pulse
BattOkBit       EQU       3               ; Input battery status
GreenLedBit     EQU       4               ;
RedLedBit       EQU       5
TrisBits        EQU       H'FF' & ~((1 << StopBit) | (1 << RunBit) | (1 <<
GreenLedBit) | (1 << RedLedBit))
; Bits to be set with the OPTION instruction
;   No wake up
;   No weak pullups
;   Timer 0 source internal
;   Which edge is don't care
;   Prescaler to watchdog, set to give 16*17 ms timeout
OptionBits      EQU       B'11011100'
; ==========================================================================
; Algorithm constants
PWM_Period      EQU       47              ; Number of 7-instr code cycles
PWM_Start       EQU       4               ; Lowest cycle count
InvalidPulseBit EQU       7               ; 0x80
BrakeEnableBit  EQU       6               ; 0x40
ArmPulsesReqd   EQU       5               ; consecutive in-range pulses
; ==========================================================================
; GP Register Definitions.  First, a home for the Boolean flags
Flags           EQU       8
BattLow         EQU       0
PriorServoBit   EQU       1
; Now, the home for the values
PwmCount        EQU       Flags + 1
PwmWidth        EQU       PwmCount + 1
ServoCount      EQU       PwmWidth + 1
Command         EQU       ServoCount + 1
ArmPulseCount   EQU       Command + 1
; =========================================================================
; Helper for making strings of no-op instructions
NO_OP           MACRO     count
NO_OP_COUNT     SET       count
                WHILE     NO_OP_COUNT
                nop
NO_OP_COUNT     SET       NO_OP_COUNT - 1
                ENDW
                ENDM
; =========================================================================
; Macro to set the initial state of the motor fet.  W contains the count
; on exit
DoRunBit        MACRO                          ; 5 instructions
                movf      PwmWidth, W
                skpz
                bsf       GPIO, RunBit
                skpnz
                bcf       GPIO, RunBit
                ENDM
; =========================================================================
; Macro to keep up with the servo pulse duration
DoServoCount    MACRO                          ; 2 instructions
                btfsc     GPIO, ServoBit
                incf      ServoCount, F
                ENDM
; =========================================================================
; =========================================================================
; =========================================================================
; Now for some code
Coldstart:      ORG       0
                IF        NO_OSCCAL_VALUE
                movlw     H'70'           ; Nominal value.
                ENDIF
; Capture the timer calibration value.
                movwf     OSCCAL
                bcf       STATUS, PA0     ; Most code is in this page
; ==========================================================================
; The following sequence is from the book.  It moves the
; prescaler from tmr0 to the watchdog without accidental resets.
                clrwdt
                clrf      TMR0
                movlw     OptionBits | 7
                option
                clrwdt
                movlw     OptionBits
                option
                clrwdt
                clrf      GPIO
                movlw     TrisBits
                tris      GPIO                 ; All outputs are low
; Note that we can get here with the brake on if we came because
; the battery got low.  If we got here from power up, the brake is
; off.  In all cases, the motor is off.  Don't leave with a low battery
Rearm:          clrwdt
                btfss     GPIO, BattOkBit
                goto      Rearm
; Now, hunt for a whole servo pulse before looking for arm pulses
RaLoop1:        btfss     GPIO, BattOkBit
                goto      Rearm
                btfss     GPIO, ServoBit
                goto      RaLoop1
RaLoop2:        btfss     GPIO, BattOkBit
                goto      Rearm
                btfsc     GPIO, ServoBit
                goto      RaLoop2
                clrf      ServoCount
                clrwdt
                movlw     ArmPulsesReqd
                movwf     ArmPulseCount
; Now, measure its length and decode it
RaLoop3:        btfss     GPIO, BattOkBit
                goto      Rearm
                btfss     GPIO, ServoBit
                goto      RaLoop3
RaLoop4:        incf      ServoCount, F
                btfss     GPIO, BattOkBit
                goto      Rearm
                NO_OP     1                    ; Loop must be 7 cycles
                btfsc     GPIO, ServoBit
                goto      RaLoop4
                clrwdt
                movf      ServoCount, W
                call      ServoLookup
                bcf       STATUS, PA0          ; Restore page 0
                clrf      ServoCount
                andlw     1 << BrakeEnableBit  ; Is this a legal arm pulse?
                skpnz
                goto      RaLoop1              ; No - start over
                decfsz    ArmPulseCount,F      ; Do we have enough arm
pulses?
                goto      RaLoop3              ; Not yet.
                clrf      PwmWidth             ; Hold motor off
                clrf      Flags                ; Last pulse = lo, batt is OK
; Fall into the main PWM loop.  The motor is off and will stay
; off until the next servo pulse.
; ===========================================================
; The main PWM loop
MainPwmLoop:    DoServoCount                   ; 4th Precycle
                NO_OP     1
; Exclusive of the next instruction, the loop is 24 clocks
                call      DoPwmPulse
                DoServoCount                   ; 1st Precycle
                btfsc     GPIO, ServoBit
                goto      ServoIsHigh
                btfsc     Flags, PriorServoBit
                goto      EndOfPulse
                NO_OP     1
                DoServoCount                   ; 2nd Precycle
MainPwmEntry:   DoRunBit                       ; 10th cycle after return
                DoServoCount                   ; 3rd Precycle
                movwf     PwmCount             ; From DoRunBit
                btfsc     Flags, BattLow       ; Sneak this in here
                goto      BattLoShutdown
                goto      MainPwmLoop
ServoIsHigh:    bsf       Flags, PriorServoBit
                nop
                DoServoCount                   ; 2nd Precycle, different
path
                DoRunBit
                DoServoCount                   ; 3rd Precycle, different
path
                movwf     PwmCount             ; From DoRunBIt
                btfsc     Flags, BattLow       ; Sneak this in here
                goto      BattLoShutdown       ; If batt was ever low, quit
now
                goto      MainPwmLoop
;
============================================================================
; The basic cycle we have to keep going is
;   DoPwmPulse
;   9*nop
;   DoRunBit and store result
;   9*nop
;   DoPwmPulse   etc
;
; All useful work is done by replacing the nop strings with useful
instructions
EndOfPulse:     bcf       Flags, PriorServoBit
                clrwdt
                DoRunBit
                movwf     PwmCount
; The brake bit does not flip during a PWM cycle, so we can just copy it to
the
; LED.
                btfss     GPIO, StopBit
                bcf       GPIO, RedLedBit
                btfsc     GPIO, StopBit
                bsf       GPIO, RedLedBit
                NO_OP     5
                call      DoPwmPulse
                movf      ServoCount, W
                call      ServoLookup           ; 7 clocks
                movwf     Command
                DoRunBit
                movwf     PwmCount
                clrf      ServoCount
                bcf       STATUS, PA0
                NO_OP     7
                call      DoPwmPulse
; If the run bit is still on at the end of a DoPwmPulse call, the controller
; is at full scale, so turn on the green LED; otherwise, turn it off.
                btfss     GPIO, RunBit
                bcf       GPIO, GreenLedBit
                btfsc     GPIO, RunBit
                bsf       GPIO, GreenLedBit
                NO_OP     2
                btfsc     Command, InvalidPulseBit
                goto      MainPwmEntry
                NO_OP     1
                DoRunBit                        ; Note that the old command
is in effect
                movwf     PwmCount              ; We must be careful not to
turn on
                movf      Command,W             ; brakes too soom
                andlw     H'3F'                 ; Get rid of the brake bit
                movwf     PwmWidth              ; width will be 0 if brake
is on
                btfss     Command, BrakeEnableBit
                goto      RunningCommand
                bcf       GPIO, RunBit          ; Stop the motor (ignore
prior command)
                NO_OP     3                     ;
                call      DoPwmPulse            ; Wait one PWM pulse time
                bsf       GPIO, StopBit         ; Turn on the brakes
                NO_OP     6
                goto      MainPwmEntry
RunningCommand: bcf       GPIO, StopBit         ; Turn off the brake (It may
be off)
                NO_OP     2
                call      DoPwmPulse            ; Wait one PWM time
                NO_OP     7
                goto      MainPwmEntry          ; Next command turns on
motor
; Low battery - shutdown and wait for arming.
BattLoShutdown: bcf       GPIO, RunBit          ; Stop and rearm
; WARNING - DON'T DIDDLE THE GPIO REGISTER until the RunBit settles.
; You may end up leaving it set!
                call      DoPwmPulse            ; For delay only
                bsf       GPIO, StopBit
                nop                             ; to settle
                bcf       GPIO, GreenLedBit
                nop                             ; to settle
                bsf       GPIO, RedLedBit
                goto      Rearm
; ==========================================================================
; Servo pulse to command converter.  Returns with command in W.
; PA0 is set on return.  Target PC = (PA0 << 9) | (0 << 8) | W.  See
; speed400.inc for the table at 0x200 which is being referenced
ServoLookup:    bsf       STATUS, PA0
                movwf     PCL
; ==========================================================================
; The main PWM pulse routine.  On entry, the motor may be on or off.
; If the motor is off, it will never be turned on.  However, it will be
; turned OFF when the PWM_Count register reaches zero.
DoPwmPulse:
PWM_LOOP_COUNT  SET       PWM_Period - PWM_Start
                WHILE     PWM_LOOP_COUNT
                btfss     GPIO, BattOkBit
                bsf       Flags, BattLow
                DoServoCount              ; 2 instructions
                decf      PwmCount,F
                skpnz
                bcf       GPIO, RunBit
PWM_LOOP_COUNT  SET       PWM_LOOP_COUNT - 1
                ENDW
                retlw     0
; ==========================================================================
; Servo command lookup table.  The index is 0-255, which is the lower 8 bits
; of the servo pulse width in 7 microsecond steps.  The output is:
;   PWM_width | ((invalid width)? 0x80 : 0) | ((Brake width range)? 0x40 :
0)
; The PWM width is in a range of 0 to 63, where 0 inhibits turning on the
; motor.
                ORG       H'200'          ; Low part of second page (PA0==1)
                INCLUDE   "speed400.inc"  ;
                END
----------------------------------------------------------------------------
-----------------------------------
SPEED400.INC
     LIST
; Servo pulse to command translation table
; Speed400.inc   Jun 28 1998
; ################ Copyright 1998 Michael J. Norton ######################
; ######## May be copied as desired and modified as needed ###############
; ######### so long as this copyright notice is preserved ################
            NOLIST
            retlw       H'002A'
            retlw       H'002A'
            retlw       H'002A'
            retlw       H'002B'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'003F'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0080'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0040'
            retlw       H'0000'
            retlw       H'0000'
            retlw       H'0000'
            retlw       H'0003'
            retlw       H'0005'
            retlw       H'0006'
            retlw       H'0007'
            retlw       H'0009'
            retlw       H'000A'
            retlw       H'000A'
            retlw       H'000B'
            retlw       H'000C'
            retlw       H'000D'
            retlw       H'000E'
            retlw       H'000E'
            retlw       H'000F'
            retlw       H'0010'
            retlw       H'0010'
            retlw       H'0011'
            retlw       H'0012'
            retlw       H'0012'
            retlw       H'0013'
            retlw       H'0013'
            retlw       H'0014'
            retlw       H'0015'
            retlw       H'0015'
            retlw       H'0016'
            retlw       H'0016'
            retlw       H'0017'
            retlw       H'0017'
            retlw       H'0018'
            retlw       H'0018'
            retlw       H'0019'
            retlw       H'0019'
            retlw       H'0019'
            retlw       H'001A'
            retlw       H'001A'
            retlw       H'001B'
            retlw       H'001B'
            retlw       H'001C'
            retlw       H'001C'
            retlw       H'001C'
            retlw       H'001D'
            retlw       H'001D'
            retlw       H'001E'
            retlw       H'001E'
            retlw       H'001E'
            retlw       H'001F'
            retlw       H'001F'
            retlw       H'0020'
            retlw       H'0020'
            retlw       H'0020'
            retlw       H'0021'
            retlw       H'0021'
            retlw       H'0021'
            retlw       H'0022'
            retlw       H'0022'
            retlw       H'0022'
            retlw       H'0023'
            retlw       H'0023'
            retlw       H'0023'
            retlw       H'0024'
            retlw       H'0024'
            retlw       H'0024'
            retlw       H'0025'
            retlw       H'0025'
            retlw       H'0025'
            retlw       H'0026'
            retlw       H'0026'
            retlw       H'0026'
            retlw       H'0027'
            retlw       H'0027'
            retlw       H'0027'
            retlw       H'0028'
            retlw       H'0028'
            retlw       H'0028'
            retlw       H'0028'
            retlw       H'0029'
            retlw       H'0029'
            retlw       H'0029'
            retlw       H'002A'
      LIST
----------------------------------------------------------------------------
-----------------------------------

Il problema è che il contenuto del file .inc è mappato su indirizzi
utilizzati dal programma .asm
Infatti il programma occupa fino all'indirizzo 028AH mentre il file .INC
contiene una tabella che parte da 0200H, ergo sono in sovrapposizione di
memoria.
Inoltre la parte di programma che risiede oltre l'indirizzo 01FFH si trova
in Page1 e quindi richiederebbe una tecnica di chiamata che non mi sembra ci
sia.
Ne consegue che così com'è il programma non possa funzionare.
In teoria potresti spostare la tabella da 200H a 300H, in tabella ci sono
256 bytes e quindi terminerebbe alla fine esatta della memoria del pic. In
pratica resterebbe un buco da 028BH a 0299H.
Per indirizzarla nella nuova posizione dovresti aggiungere la seguente
istruzione:
ServoLookup:    bsf       STATUS, PA0
  addlw H'100'  ; <-----nuova istruzione
                movwf     PCL
Per spostare la tabella dovresti cambiare nel file .asm la riga:
   ORG       H'200'          ; Low part of second page (PA0==1)
in:
   ORG       H'300'          ; Low part of second page (PA0==1)
In fase di compilazione converrebbe commentare il NOLIST dal file .inc per
vedi nel .lst le posizioni di memoria utilizzate dalla tabella.
Dico "in teoria" perchè resterebbe il problema del codice oltre l'indirizzo
200H e quindi in page1. Nel programma non ci sono i necessari "bcf/bsf
STATUS, PA0" per le chiamate che sarebberero da inserire ma c'è poca memoria
e potrebbe essere un nightmare.
Good lack,
Leonardo
".·'·.ArnO.·'·." <nospam@please> ha scritto nel messaggio
news:IO2l8.31298$1S3.9...@twister1.libero.it...
