I have a very simple program which moves a standard RC servo slowly from one resting position to another at the throw of a switch; switch closed = full right; switch open = full left. Each time the servo is moved the program is supposed to save its position (1 = right; 2 = left) into the EEPROM so that, when power is switched on again after having been switched off, the servo will go slowly to whichever position the switch is in at that moment -- even if the switch has been changed while the power was off. The program works fine so long as power is there, but when power is switched off and then switched on again, whether or not the switch is in the correct position for the present servo position, the servo jerks through about 10 degrees of rotation, and doesn't move to a correct position until the switch is thrown one way or the other.
c.1 and c.4 switch leds to indicate the position of the servo, and a relay, neither of which impact on the operation of the servo itself. I switch the servo OFF after each movement to eliminate buzzing while it's stationary, and to save power, so it shouldn't even be responsive when I power up the circuit.
Following is the program; can anyone enlighten me as to why the servo gives such a twitch when the circuit is powered up, please? Maybe it's nothing to do with the memory, but a "spike" or something affecting the servo? If so, how can I eliminate that?
c.1 and c.4 switch leds to indicate the position of the servo, and a relay, neither of which impact on the operation of the servo itself. I switch the servo OFF after each movement to eliminate buzzing while it's stationary, and to save power, so it shouldn't even be responsive when I power up the circuit.
Following is the program; can anyone enlighten me as to why the servo gives such a twitch when the circuit is powered up, please? Maybe it's nothing to do with the memory, but a "spike" or something affecting the servo? If so, how can I eliminate that?
Code:
symbol servo_position = b5
symbol min_pulse = b6
symbol max_pulse = b7
symbol servo_slow = b8
symbol route_set = b9
let max_pulse = 175 ;change this value to alter right limit
let min_pulse = 125 ;change this value to alter left limit
let servo_slow = 20 ;increase this value to slow servo
SYMBOL EEPROM_Save = 1 ;defines EEPROM location 1 to hold current selected route
read EEPROM_Save,route_set
main:
if pin3 = 1 and route_set<>1 then
let servo_position=min_pulse
goto rightA
elseif pin3 = 0 and route_set<>2 then
let servo_position=max_pulse
goto leftA
else
goto main
endif
rightA:
high c.1
high c.4
servo c.2,servo_position
inc servo_position
pause servo_slow
do
servopos c.2,servo_position
inc servo_position
pause servo_slow
loop while servo_position<max_pulse
let servo_position=max_pulse
let route_set=1
write EEPROM_Save,route_set
pause 10
servo c.2,OFF
low c.1
goto main
leftA:
high c.1
high c.4
servo c.2,servo_position
dec servo_position
pause servo_slow
do
servopos c.2,servo_position
dec servo_position
pause servo_slow
loop while servo_position>min_pulse
let servo_position=min_pulse
let route_set=2
write EEPROM_Save,route_set
pause 10
servo c.2,OFF
low c.4
goto main