Hi,
You seem to have gone back to much lower values for CREEP and MAXPWMVALUE so the Creep might not keep driving properly. IIRC you were using a creep of 299 and a DEADZONE of 6 is far too large! But to go back to one of my previous comments:
Cheers, Alan.
You seem to have gone back to much lower values for CREEP and MAXPWMVALUE so the Creep might not keep driving properly. IIRC you were using a creep of 299 and a DEADZONE of 6 is far too large! But to go back to one of my previous comments:
It might not be possible to change the Fonts, but it is possible to add Colour by using the "Copy for Forum" link. But I rarely use it because all the color codes can very rapidly take you to the forum's 10,000 character limit. However, it does help to draw attention to comments (which the PE will ignore). There are quite a lot of lines that have either been "commented out" (i.e. do nothing) or are unnecessary. I've commented out the unnecessary lines from an earlier post (I can't keep up with all of your posts at the moment). I've also added/changed two lines to lower the PWM frequency, but it seems the 28X2 probably cannot go low enough to really "jog" the motor out of "stiction" (static friction).That's one reason we include "comments" in the code, but unfortunately can only mark them with a ' or ; character (it's not possible to use fancy fonts inside the code window)... :
Rich (BB 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
goto main