;
; Half-stepping stepper motor controller "with fast-foward and reverse".
; For Pollux eq platform by Kosminen Vompatti, uuki@iki.fi
;
; PIC16F84 port A bits 0-3 interface to L293D motor driver:
;
; bit 0 -> 1A
; bit 1 -> 2A
;
; bit 2 -> 3A
; bit 3 -> 4A
;
; Both enables of L293D are kept high. Motor windings are connected across
; outputs 1Y and 2Y (white and yellow wires), and outputs 3Y and 4Y (red and
; blue).
;
; Port B bits 1 and 2 are for slewing telescope forward and backward. Wire
; these through normally open switches to ground.
;
device pic16f84
config CP=off,WDT=off,PWRT=off,OSC=hs
include "pic16c84.h" ;also for f84
org 0x0c
delay1 ds 1
delay2 ds 1
org 0
; Initialize the port
movlw 0x00
movwf PORTA
; Set port A as output (we'll use only bits 0, 1, 2 and 3)
; Set port B bits 1 and 2 as inputs, with pull-ups enabled
bsf STATUS,RP0
movlw 0xe0
movwf TRISA
movlw 0x06
movwf TRISB
bcf OPTIO,RBPU
bcf STATUS,RP0
; This is the stepping sequence including half-steps:
; bin 0001 0101 0100 0110 0010 1010 1000 1001
; hex 0x01 0x05 0x04 0x06 0x02 0x0a 0x08 0x09
; If port b1 is grounded, run the sequence in reverse.
step1
movlw 0x01
call track_step
btfss PORTB,1 ; Are we slewing backwards?
goto step8 ;
step2
movlw 0x05
call track_step
btfss PORTB,1
goto step1
step3
movlw 0x04
call track_step
btfss PORTB,1
goto step2
step4
movlw 0x06
call track_step
btfss PORTB,1
goto step3
step5
movlw 0x02
call track_step
btfss PORTB,1
goto step4
step6
movlw 0x0a
call track_step
btfss PORTB,1
goto step5
step7
movlw 0x08
call track_step
btfss PORTB,1
goto step6
step8
movlw 0x09
call track_step
btfss PORTB,1
goto step7
goto step1
; Take a step and wait a while. If slewing, use a shorter delay
track_step
movwf PORTA
movlw 0x36 ; This sets the delay
call delay
btfss PORTB,1 ; Are we slewing either forward or back?
return ;
btfss PORTB,2 ;
return ;
movlw 0x36
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x36
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x36
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
btfss PORTB,1
return
btfss PORTB,2
return
movlw 0x37
call delay
return
; We repeated that 10 times, so slewing is 10x faster than tracking
; Delay routine, length set by w (0 means 256):
; w*771+6 instruction cycles (197.382 ms max, on a 4 MHz crystal)
; including call and return cycles.
delay movwf delay1
clrf delay2
delay_a incfsz delay2,F ; ; Inner loop: 256*3=768
goto delay_a ; ; instruction cycles.
decfsz delay1,F ; Outer loop w*(768+3)=w*771
goto delay_a ; instrcution cycles.
return
end
;
; Whee.
;
|