Gramps
Senior Member
We are still in Florida and I'm itching to get back to my shop.
The code below reads the value of the desired pot. I think it's basically watching for a voltage change from zero to 5 volts.
Correct?
A 1/10th scale ESC (electronic speed control) delivers a variable voltage output, zero to 6 volts to power a DC motor.
So it should be pretty simple to replace the desired pot with an ESC without even changing the code!
(Of course, it will NOT be that simple )
Gramps
The code below reads the value of the desired pot. I think it's basically watching for a voltage change from zero to 5 volts.
Correct?
A 1/10th scale ESC (electronic speed control) delivers a variable voltage output, zero to 6 volts to power a DC motor.
So it should be pretty simple to replace the desired pot with an ESC without even changing the code!
(Of course, it will NOT be that simple )
Gramps
Code:
~
'Shadow-Bot feedback control code with limits updated 11-13-20
#picaxe 28x2
#no_data
#no_table ; The next line can reduce the PWM frequency ** NEW ** (Cannot put comments in #define lines)
#define pwmfreq PWMDIV16,
; #define pwmfreq
symbol DEADZONE = 2 ; Switch motor off (Make as small as practical) ;
; symbol SLOWZONE = 12 ; Slow motor down (NB: May depend on motor speed ! )
symbol MotorSpeed = w4 ; (To replace the "300" in the present PWMOUT code)
symbol LOOPGAIN = 33 ; i.e. MAXPWMVALUE / SLOWZONE (= 399 / 12)
symbol PWMPERIOD = 199 ; Equivalent Max Duty Cycle is 799 ;
; symbol xb0 = b0 ' reserved for bit variables ;
; symbol bReverseForward=bit1 ' 0=reverse,=forward ;
; symbol bMotorState=bit0 ' 0=off,1=on ;
; symbol REVERSE_=0 ;
symbol FORWARD_=1 Symbol desired_pot_value = b1
Symbol feedback_pot_value = b3
Symbol diff = b4
Symbol desired_pot = 13 'B.5 Symbol feedback_pot = 11 'B.4
Symbol MOTOR = B.0 ' Energize PWM
Symbol Direction = B.7
Symbol MAXPWMVALUE = 399 ; ** ONLY HALF OF THE AVAILABLE DRIVE VOLTAGE ! ;
; Symbol bSlowState=bit2
Symbol old_feedback_value= b5
Symbol old_desired_value= b6
Symbol ENDSTOP_A = 60 ; desired_pot MINimum value
Symbol ENDSTOP_C = 210 ; desired_pot MAXimum value
Symbol CREEP = 160 ; PWM value to run slowly * HIGH ENOUGH TO START MOTOR TURNING !
Main:
Readadc Desired_pot, desired_pot_value
Desired_pot_value = Desired_pot_value MIN ENDSTOP_A MAX ENDSTOP_C
' sertxd (#desired_pot_value," ",#b1,13,10)
pause 100
Readadc feedback_pot, feedback_pot_value
' sertxd (#feedback_pot_value," ",#b3,13,10)
pause 100
' sertxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
If old_feedback_value<>feedback_pot_value or old_desired_value<> desired_pot_value then
old_feedback_value=feedback_pot_value
old_desired_value=desired_pot_value
sertxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
endif
if desired_pot_value > feedback_pot_value then
diff=desired_pot_value - feedback_pot_value
else
diff=feedback_pot_value - desired_pot_value
endif
if diff > DEADZONE then
MotorSpeed = diff * LOOPGAIN max MAXPWMVALUE min CREEP ; Limit range of motor speed
if desired_pot_value > feedback_pot_value then
high Direction ; Set forward direction
else
low Direction ; Set reverse direction
endif
; pwmout MOTOR , PWMPERIOD , MotorSpeed ; Slows motor within SLOWZONE
pwmout pwmfreq MOTOR , PWMPERIOD , MotorSpeed ; Slows motor within SLOWZONE ** NEW **
else
pwmout MOTOR , OFF ; STOP ;
; bMotorState=0 ; Not sure what these do (now) ;
; bSlowState = 0 ;
endif
Go to main
[code]
Last edited: