now I'm no programmer and I might be laying myself bare for everyone to laugh at, but this is how I'd likely approach it...
(disclaimer...there maybe some syntax errors, but you get the methodology blah blah)
Code:
begin:
ADCIN 1,pot_sample
if pot_sample = 127 then
fwd_pwm = 0 & rev_pwm = 0
hpwm 1,fwd_pwm,20000
hpwm 2,rev_pwm,20000
goto begin
endif
if pot_sample >127 then
rev_pwm = 0
fwd_pwm =255-pot_sample x 2
hpwm 2,rev_pwm,20000
hpwm 1,fwd_pwm,20000
goto begin
endif
if pot_sample<127 then
fwd_pwm = 0
rev_pwm =127-pot_sample x 2
hpwm 1,fwd_pwm,20000
hpwm 2,rev_pwm,20000
goto begin
endif
pause 20
goto begin
I'm sure to those who really are programmers, then the above is inelegant, but I'm a kludger & therefore go with what I can grasp...not elegancy!
the above assumes 8 bit AtoD which obviously gives 256 levels & therefore a level of 127 becomes your zero point & your duty cycle changes in steps of 2 up to 256 for each direction. But like I say....what do I know?!!!
Bookmarks