📄 drivera.asm
字号:
; incf fakeidx, f ; Advance past the 0
; endif
btfss rstatus, ST_STOP ; Stop now?
goto t1intend ; Done if not
; Want to stop in high speed run case
; Assume that since we are in the hsrun states, curindex is not 0
decf rcuridx, f ; Head back down
movfw rcuridx ;
call rgetaccel ; Load "down 1" index
movlw 24 ; Next is t1decel1of8
movwf t1state ;
goto t1intend ;
t1decel1of8
movfw rcuridx ; Pick up index
skpnz ; Wrap it if now 0
goto t1wrap ;
movfw t1stepcmd ; 1st step of 8
rstep ;
incf t1state, f ; Advance to next state
goto t1intend ;
t1decelxof8
movfw t1stepcmd ; nth step
rstep ;
incf t1state, f ;
goto t1intend ;
t1decel8of8
movfw t1stepcmd ; 8th step
rstep ;
movlw 24 ; Step 1 is next
movwf t1state ;
movfw rinc ; Account for a full step
addwd rapos ;
toggle_led ; We were here
decfsz rac_cnt, f ; More steps at this speed?
goto t1intend ; Go on if not
; Decelerating, check next step
decf rcuridx, f ;
movfw rcuridx ;
call rgetaccel ; Reload CCPRx, rac_cnt
goto t1intend ; wrap it up
t1intend ; Set up CCPR1 for next interrupt, if not already done
movfw rspdlow ; Advance to next time to stop
addwf CCPR1L, f ;
skpnc ;
incf CCPR1H, f ;
movfw rspdhigh ;
addwf CCPR1H, f ;
bcf PIR1, 2 ; Clear CCP1IF just in case
int1 ; Process rest of interrupts
btfss PIR2, 0 ; Check for timer 1 compare (CCP2IF) match next
goto int2 ;
; t2 interrupt
t2int
bcf PIR2, 0 ; Clear CCP2IF
movlw high t2jmptbl ;
movwf PCLATH ;
movfw t2state ; Pick up jump vector
addwf PCL, f ; Go
t2jmptbl
goto t2stepxof8 ; 0 Step 2
goto t2stepxof8 ; 1 Step 3
goto t2stepxof8 ; 2 Step 4
goto t2stepxof8 ; 3 Step 5
goto t2stepxof8 ; 4 Step 6
goto t2stepxof8 ; 5 Step 7
goto t2step8of8 ; 6 Step 8
goto t2step1of8 ; 7 Step 1
goto t2accelxof8 ; 8 Step 2
goto t2accelxof8 ; 9 Step 3
goto t2accelxof8 ; 10 Step 4
goto t2accelxof8 ; 11 Step 5
goto t2accelxof8 ; 12 Step 6
goto t2accelxof8 ; 13 Step 7
goto t2accel8of8 ; 14 Step 8
goto t2accel1of8 ; 15 Step 1
goto t2hsxof8 ; 16 Step 1
goto t2hsxof8 ; 17 Step 2
goto t2hsxof8 ; 18 Step 3
goto t2hsxof8 ; 19 Step 4
goto t2hsxof8 ; 20 Step 5
goto t2hsxof8 ; 21 Step 6
goto t2hsxof8 ; 22 Step 7
goto t2hs8of8 ; 23 Step 8
goto t2decel1of8 ; 24 Step 1
goto t2decelxof8 ; 25 Step 2
goto t2decelxof8 ; 26 Step 3
goto t2decelxof8 ; 27 Step 4
goto t2decelxof8 ; 28 Step 5
goto t2decelxof8 ; 29 Step 6
goto t2decelxof8 ; 30 Step 7
goto t2decel8of8 ; 31 Step 8
t2stepxof8
movfw t2stepcmd ;
dstep ; Step RA Axis
incf t2state, f ;
goto t2intend ;
t2step8of8
movfw t2stepcmd ; 8th step
dstep ;
incf t2state, f ; Set to step 1
movfw dinc ; increment
addwd dpos ; Advance dpos - 8 microsteps done
toggle_led ; Flip LED - full step done
goto t2intend ;
t2step1of8
btfss dstatus, ST_STOP ; Do they want to stop?
goto t2step1of8a ; Skip over if not
t2wrap ; Code to shut off timer 1
clrf dstatus ; OK, let's stop...
bsf dstatus, ST_STOPPED ;
banksel PIE2 ;
bcf PIE2, 0 ; Turn off CCP2IE
banksel 0 ;
movlw B'00000000' ; CCP1X:CCP1Y=0 CCP1M3:CCP1M0=0
movwf CCP2CON ; Shut off compare on match
goto int2 ; Process rest of interrupts
t2step1of8a movfw t2stepcmd ;
dstep ; 1st of 8 microsteps
movlw 0 ; State 0 next
movwf t2state ;
goto t2intend ;
t2accelxof8
movfw t2stepcmd ; Step it
dstep ;
incf t2state, f ; Advance nicely along...
goto t2intend ;
t2accel8of8
movfw t2stepcmd ; 8th step
dstep ;
incf t2state, f ; Set to step 1
movfw dinc ; Account for a full step
addwd dpos ;
toggle_led ; We were here
btfsc dstatus, ST_STOP ; Stop before we got there?
goto t2accel8of8b ;
decfsz dac_cnt, f ; More steps at this speed?
goto t2intend ; Go on if not
; Accelerating, check next step
movfw dcuridx ;
subwf dhiacidx, w ; At top speed?
skpnz ;
goto t2accel8of8a ; change state if yes
incf dcuridx, f ; Point at next one
movfw dcuridx ;
call dgetaccel ; Reload CCPRx, dac_cnt
goto t2intend ; wrap it up
t2accel8of8a movlw 16 ; State t2hs1of8 next
movwf t2state ;
goto t2intend ; Wrap it up
t2accel8of8b ; Wants to stop before we hit full speed
movfw dcuridx ; Where are we?
skpnz ;
goto t2intend ; Pick it up in t2accel1of8 if done
decf dcuridx, f ; Head back down if not
movfw dcuridx ;
call dgetaccel ; Load "down 1" index
movlw 24 ; decel state - t2decel1of8
movwf t2state ;
goto t2intend ;
t2accel1of8
btfss dstatus, ST_STOP ; Do they want to stop?
goto t2accel1of8a ; Skip over if not
movfw dcuridx ; Probably 0 if we are here (see t2accel8of8b)
skpnz ; Wrap it up if yes
goto t2wrap ; Will see it in t2accel8of8 then decel if not
t2accel1of8a movfw t2stepcmd ;
dstep ; 1st of 8 microsteps
movlw 8 ; State 8 - t2accelxof8 next
movwf t2state ;
goto t2intend ;
t2hsxof8
movfw t2stepcmd ; Step it
dstep ;
incf t2state, f ; Next state
goto t2intend ;
t2hs8of8
movfw t2stepcmd ; 8th step
dstep ;
movlw 16 ; Set to t2hsxof8
movwf t2state ;
movfw dinc ; Account for a full step
addwd dpos ;
toggle_led ; We were here
ifdef SIM
incf fakeidx, f ; Advance past the 0
endif
btfss dstatus, ST_STOP ; Stop now?
goto t2intend ; Done if not
; Want to stop in high speed run case
; Assume that since we are in the hsrun states, curindex is not 0
decf dcuridx, f ; Head back down
movfw dcuridx ;
call dgetaccel ; Load "down 1" index
movlw 24 ; Next is t2decel1of8
movwf t2state ;
goto t2intend ;
t2decel1of8
movfw dcuridx ; Pick up index
skpnz ; Wrap it if now 0
goto t2wrap ;
movfw t2stepcmd ; 1st step of 8
dstep ;
incf t2state, f ; Advance to next state
goto t2intend ;
t2decelxof8
movfw t2stepcmd ; nth step
dstep ;
incf t2state, f ;
goto t2intend ;
t2decel8of8
movfw t2stepcmd ; 8th step
dstep ;
movlw 24 ; Step 1 is next
movwf t2state ;
movfw dinc ; Account for a full step
addwd dpos ;
toggle_led ; We were here
decfsz dac_cnt, f ; More steps at this speed?
goto t2intend ; Go on if not
; Decelerating, check next step
decf dcuridx, f ;
movfw dcuridx ;
call dgetaccel ; Reload CCPRx, dac_cnt
goto t2intend ; wrap it up
t2intend ; Set up CCPR2 for next interrupt, if not already done
movfw dspdlow ; Advance to next time to stop
addwf CCPR2L, f ;
skpnc ;
incf CCPR2H, f ;
movfw dspdhigh ;
addwf CCPR2H, f ;
bcf PIR2, 0 ; Clear CCP2IF just in case
int2 ; Check for timer 0
btfss INTCON, 2 ; Did timer 0 fire?
goto int3 ; Skip if not
bcf INTCON, 2 ; Clear flag if it did
incf t0ticks, f ; Advance timer
int3 ;
int4 ; Wrap up interrupt processing
; post processing - match up with prolog
bcf STATUS,RP0 ; ensure file register bank set to 0
movfw pclath_temp ; restore PCLATH
movwf PCLATH ;
movfw temp1_temp ; restore temp1
movwf temp1 ;
movfw temp_temp ; restore temp
movwf temp ;
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f ;
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;
; gettraj
; w = index into table
; returns the value from the table
; Org up to a reasonable boundary
org ($+0x100) & 0x3F00
gettraj
movwf temp ; Stash the index
movlw high traj ;
movwf PCLATH ;
movfw temp ;
addwf PCL, f ; assumes same page, etc
;
; Trajectory table for microstepping
; Numbers in the comments column give the number of microstep, half and
; full step. The top nibble goes to the 1st controller, the bottom to
; the second. Of the 4 bits in a nibble, the MSB is the phase, the bottom
; 3 are the digital code.
;
traj dt H'CC' ; 0 0 0
dt H'BD' ; 1
dt H'AE' ; 2
dt H'9F' ; 3
dt H'0F' ; 4 1
dt H'1F' ; 5
dt H'2E' ; 6
dt H'3D' ; 7
dt H'4C' ; 8 2 1
dt H'5B' ; 9
dt H'6A' ; 10
dt H'79' ; 11
dt H'70' ; 12 3
dt H'71' ; 13
dt H'62' ; 14
dt H'53' ; 15
dt H'44' ; 16 4 2
dt H'35' ; 17
dt H'26' ; 18
dt H'17' ; 19
dt H'87' ; 20 5
dt H'97' ; 21
dt H'A6' ; 22
dt H'B5' ; 23
dt H'C4' ; 24 6 3
dt H'D3' ; 25
dt H'E2' ; 26
dt H'F1' ; 27
dt H'F8' ; 28 7
dt H'F9' ; 29
dt H'EA' ; 30
dt H'DB' ; 31
;
; GetAccel
; Gets the accel. at index w
; Loads rac_cnt, rspdlow, rspdhigh
; Got a version for ra and one for dec
;
rgetaccel
clrf temp1 ; Use temp, temp1 for index
movwf temp ; Multiply w by 3 to index into tbl
clrc ; Clear carry
rlf temp, f ; Shift index left
rlf temp1, f ;
addwf temp, f ; w*3 now in temp, temp1
addcf temp1, f ;
call getacc1 ; Get count
movwf rac_cnt ;
movlw 1 ;
addwf temp, f ;
addcf temp1, f ;
call getacc1 ; Get msb
movwf rspdhigh ;
movlw 1
addwf temp, f ;
addcf temp1, f ;
call getacc1 ; Get lsb
movwf rspdlow ;
return
dgetaccel
clrf temp1 ; Use temp, temp1 for index
movwf temp ; Multiply w by 3 to index into tbl
clrc ; Clear carry
rlf temp, f ; Shift index left
rlf temp1, f ;
addwf temp, f ; w*3 now in temp, temp1
addcf temp1, f ;
call getacc1 ; Get count
movwf dac_cnt ;
movlw 1 ;
addwf temp, f ;
addcf temp1, f ;
call getacc1 ; Get msb
movwf dspdhigh ;
movlw 1
addwf temp, f ;
addcf temp1, f ;
call getacc1 ; Get lsb
movwf dspdlow ;
return
getacc1
movlw high accel ; set PCLATH for accel
movwf PCLATH ;
movfw temp1 ; Add in top of index
addwf PCLATH, f ;
movfw temp ; Now do bottom
addlw low accel ;
addcf PCLATH, f ; prop. carry
movwf PCL ; and go
;
; Acceleration table
; Each entry has a number of 16 bit microsecond counts
; Accel. at the rate of 1250 full steps/second/second
; These are microstep counts.
;
accel
dt 1 , H'13', H'88'
dt 1 , H'08', H'17'
dt 1 , H'06', H'35'
dt 1 , H'05', H'3C'
dt 1 , H'04', H'9D' ; 100 fs/sec = 8x
dt 1 , H'04', H'2B'
dt 1 , H'03', H'D6'
dt 1 , H'03', H'92'
dt 1 , H'03', H'5A'
dt 1 , H'03', H'2C'
dt 1 , H'03', H'04'
dt 1 , H'02', H'E2'
dt 1 , H'02', H'C3'
dt 1 , H'02', H'A9'
dt 1 , H'02', H'91'
dt 1 , H'02', H'7B'
dt 1 , H'02', H'68'
dt 1 , H'02', H'56'
dt 1 , H'02', H'46'
dt 1 , H'02', H'36'
dt 1 , H'02', H'28'
dt 1 , H'02', H'1B'
dt 1 , H'02', H'0F'
dt 1 , H'02', H'04'
dt 1 , H'01', H'F9'
dt 1 , H'01', H'EF'
dt 1 , H'01', H'E6'
dt 1 , H'01', H'DD'
dt 1 , H'01', H'D5'
dt 1 , H'01', H'CD'
dt 1 , H'01', H'C5'
dt 1 , H'01', H'BE'
dt 1 , H'01', H'B7'
dt 1 , H'01', H'B0'
dt 1 , H'01', H'AA'
dt 1 , H'01', H'A4'
dt 1 , H'01', H'9E'
dt 1 , H'01', H'99'
dt 1 , H'01', H'93'
dt 1 , H'01', H'8E'
dt 1 , H'01', H'89'
dt 1 , H'01', H'84'
dt 1 , H'01', H'80'
dt 1 , H'01', H'7B'
dt 1 , H'01', H'77'
dt 1 , H'01', H'73'
dt 1 , H'01', H'6F'
dt 1 , H'01', H'6B'
dt 1 , H'01', H'67'
dt 1 , H'01', H'64'
dt 1 , H'01', H'60'
dt 1 , H'01', H'5D'
dt 1 , H'01', H'59'
dt 1 , H'01', H'56'
dt 1 , H'01', H'53'
dt 1 , H'01', H'50'
dt 1 , H'01', H'4D'
dt 1 , H'01', H'4A'
dt 1 , H'01', H'47'
dt 1 , H'01', H'44'
dt 1 , H'01', H'42'
dt 1 , H'01', H'3F'
dt 1 , H'01', H'3C'
dt 1 , H'01', H'3A'
dt 1 , H'01', H'38' ; 400 fs/sec = 32x
org 0x800
ifdef SIM
fakeinput
movfw fakeidx ; Pick up the index
call getfake ;
andlw 0xff ; Zero?
skpz ;
incf fakeidx, f ; Always return 0 if it is
mreturn ;
getfake
movwf temp
movlw high faketbl
movwf PCLATH
movfw temp
addlw low faketbl ; Index into table
movwf PCL ; assumes same page, etc
faketbl dt "GB\r"
dt 0
dt "Q\r"
dt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
endif
;
; Speed tbl
; Call with index in temp
; Returns char at that index in w
;
getspeed
movlw high speedtbl ;
movwf PCLATH ;
movfw temp ;
addlw low speedtbl ; Index into table
movwf PCL ; assumes same page, etc
speedtbl
dt 'T', SL_SLOW_MASK, TRACKH, TRACKL
dt 'G', SL_GUIDE_MASK, 0, 0
dt 'L', SL_SLOW_MASK, LUNARH, LUNARL
dt 'S', SL_SLOW_MASK, SOLARH, SOLARL
dt 'M', SL_MED_MASK, MEDIDX, 0
dt 'F', SL_FAST_MASK, HIGHIDX, 0
dt 0
;
; Powers of 10 table
; Used in dtoa to convert digital to ascii
; Gets byte at temp, increments temp
;
getpot
movlw high pottbl ;
movwf PCLATH ;
movfw temp ;
incf temp, f ; Point to next one
addlw low pottbl ;
movwf PCL ;
pottbl
dt 59, 154, 202, 0 ; 1000000000
dt 5, 245, 225, 0 ; 100000000
dt 0, 152, 150, 128 ; 10000000
dt 0, 15, 66, 64 ; 1000000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -