Gramps
Senior Member
The objective here was to get the motor to stop when b1 and b3 are equal. However the motor does not stop as desired.
Obviously, I'm missing something. Hint please!
Gramps
Obviously, I'm missing something. Hint please!
Gramps
Code:
'Test circuit for MD20A with feedback pot
'Adapting Erco's code
' C.5 goes to center wiper on desired pos. pot
' C.7 goes to center wiper on feedback pot
'C.4 connects to direction pin on MD20A
'C.2 connects to PWM pin on MD20A
'pwmduty is 0 to 1023
#picaxe 28x2
#no_data
init: pwmout C.2, 221, 177 ' 9000Hz at 20% @ 8MHz start pwm peroid is
'0-255 and duty cycles is 0-1023
main:
readadc 17, B1 ' read desired pos. pot, C.5 store ADC value 0-255 in B1
'sertxd (#b1," ",#w2,13,10)
debug
readadc 19, B6 ' read feedback pot, C.7 store ADC value 0-255 in B6
;sertxd (#b6," ",#w3,13,10)
debug
if b1<128 then reeverse
foreward: high c.4: b2=b1-128: goto speed
reeverse: low c.4: b2=128-b1
speed: w2=8*b2
pwmduty C.2,w2 ; set pwm duty
'sertxd (#b1," ",#w2,13,10)
debug
if b1=b3 then pwmout C.2, 199,0 '0% duty cycle turn off motor
endif
goto main ; loop back to start