danielwi11iams
New Member
Hi, I'm new to this chip programming. I start using it today and found some code for a servo slow, which will slow down the movement of the servo.
But when I go and run the simulation of the program it comes up with:
loop:
Error: loop without a Do
the code is has follows:
'Radio control servo slowdown using PICAXE-08M
'Kevin Goom, 17 October 2005
'
'PICAXE-08M connections are:
' Leg 1 +5V
' Leg 2 (Serial in) Tie to Ground through 10K resistor
' Leg 3 (In4/Out4) Wiper of 10K potentiometer connected to +5V
' and ground
' Leg 4 (In3) Pulse input from radio receiver
' Leg 5 (In2/Out2) Pulse output to servo
' Leg 6 (In1/Out1) Mode indicator output
'1/2 second flash = no valid signal
'Steady on = pass-through (no servo slowdown)
'Flicker = servo slowdown mode
' Leg 7 (Out0/Serial Out) NC
' Leg 8 Ground
symbol Delay=b8 'Name the delay factor
symbol PWin=w0 'Name the input pulse length
symbol PWout=b2 'Name the output pulse length
symbol PWinPrev=b3 'Name the length of the prior input pulse length
symbol PWinErr=b6 'Name the difference between input and output pulse lengths
symbol skip=b4 'Name the counter for skipping "Delay" times
restart:
Skip=0
high 1
servo 2,135 'Center the servo initially
' and on input pulse loss
Pause 500 'Wait 1/2 second initially
toggle 1
readadc 4,Delay 'Read the voltage from the delay potentiometer
pulsin 3,1,PWin 'Measure the input pulse width initially
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
high 1
low 2 'Stop the sevo command if valid input detected
PWinPrev=PWin 'Initially set the prior pulse width to current pulse width
if Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
Delay=Delay/21 'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
PWout=PWin 'Set output pulse to input pulse initially
loop:
toggle 1
PWinPrev=PWin 'Reset the prior pulse width
pulsin 3,1,PWin 'Measure the input pulse
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
PwinErr=PWin-PWOut
if PWinErr<2 or PWinErr>254 then StayPut 'Add 2 units of hysteresis
if PWout<PWin then MoveUp
if PWout>PWin then MoveDown
Loop
MoveDown: 'Routine to decrease the
output pulse width
if skip>=Delay then Skip1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
goto Skip2
Skip1:
Skip=0
PWout=PWout-1
Skip2:
pulsout 2,PWout 'Send the output pulse to the servo
goto loop 'Return to re-measure the input pulse
MoveUp: 'Routine to increase the output pulse width
if skip>=Delay then Skip3 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
goto Skip4
Skip3:
Skip=0
PWout=PWout+1
Skip4:
pulsout 2,PWout 'Send the output pulse to the servo
goto loop 'Return to re-measure the input pulse
StayPut: 'Routine to send the same output pulse
pulsout 2,PWout
goto loop 'Return to re-measure the input pulse
StraightThru:
pulsin 3,1,PWin
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
PwinErr=PWin-PWinPrev
if PWinErr<2 or PWinErr>254 then Stay 'Add 2 units of hysteresis
pulsout 2,PWin
PWinPrev=PWin
goto StraightThru: 'Return to re-measure the input pulse
Stay:
pulsout 2,PWinPrev 'Set output pulse to input pulse
goto StraightThru: 'Return to re-measure the input pulse
I can only get it to simulate until the loop line. is it the right code for this software (PICAXE Programming) or is there something missing that i need to fill in.
Once I understand the code I want to use it to read the signal coming from a RX receiver, used in model aircarfts to control up to five servos.
Three servo for wheel on a model and the ofter two servos for the doors on the model for the undercarriage.
Whiles I'm here I will give you an idea of what I'm trying to do.
I want the two servos for the door to open up the doors, once they have opened I what the wheels to come down using the slow code. then in reverse I want the wheels to go up then the doors to close.
But all of this needs to work off one channel from the RX receiver. so if a forward signal is sent from the transmitter the door need to open with a pause on the wheel until the doors have fully opened then the wheels to come down. But when a reverse signal is sent from the transmitter I want the wheels to go up, with a pause on the doors until the wheel have fully gone up.
any help would be appreciated.
Danny
But when I go and run the simulation of the program it comes up with:
loop:
Error: loop without a Do
the code is has follows:
'Radio control servo slowdown using PICAXE-08M
'Kevin Goom, 17 October 2005
'
'PICAXE-08M connections are:
' Leg 1 +5V
' Leg 2 (Serial in) Tie to Ground through 10K resistor
' Leg 3 (In4/Out4) Wiper of 10K potentiometer connected to +5V
' and ground
' Leg 4 (In3) Pulse input from radio receiver
' Leg 5 (In2/Out2) Pulse output to servo
' Leg 6 (In1/Out1) Mode indicator output
'1/2 second flash = no valid signal
'Steady on = pass-through (no servo slowdown)
'Flicker = servo slowdown mode
' Leg 7 (Out0/Serial Out) NC
' Leg 8 Ground
symbol Delay=b8 'Name the delay factor
symbol PWin=w0 'Name the input pulse length
symbol PWout=b2 'Name the output pulse length
symbol PWinPrev=b3 'Name the length of the prior input pulse length
symbol PWinErr=b6 'Name the difference between input and output pulse lengths
symbol skip=b4 'Name the counter for skipping "Delay" times
restart:
Skip=0
high 1
servo 2,135 'Center the servo initially
' and on input pulse loss
Pause 500 'Wait 1/2 second initially
toggle 1
readadc 4,Delay 'Read the voltage from the delay potentiometer
pulsin 3,1,PWin 'Measure the input pulse width initially
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
high 1
low 2 'Stop the sevo command if valid input detected
PWinPrev=PWin 'Initially set the prior pulse width to current pulse width
if Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
Delay=Delay/21 'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
PWout=PWin 'Set output pulse to input pulse initially
loop:
toggle 1
PWinPrev=PWin 'Reset the prior pulse width
pulsin 3,1,PWin 'Measure the input pulse
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
PwinErr=PWin-PWOut
if PWinErr<2 or PWinErr>254 then StayPut 'Add 2 units of hysteresis
if PWout<PWin then MoveUp
if PWout>PWin then MoveDown
Loop
MoveDown: 'Routine to decrease the
output pulse width
if skip>=Delay then Skip1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
goto Skip2
Skip1:
Skip=0
PWout=PWout-1
Skip2:
pulsout 2,PWout 'Send the output pulse to the servo
goto loop 'Return to re-measure the input pulse
MoveUp: 'Routine to increase the output pulse width
if skip>=Delay then Skip3 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
goto Skip4
Skip3:
Skip=0
PWout=PWout+1
Skip4:
pulsout 2,PWout 'Send the output pulse to the servo
goto loop 'Return to re-measure the input pulse
StayPut: 'Routine to send the same output pulse
pulsout 2,PWout
goto loop 'Return to re-measure the input pulse
StraightThru:
pulsin 3,1,PWin
if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
PwinErr=PWin-PWinPrev
if PWinErr<2 or PWinErr>254 then Stay 'Add 2 units of hysteresis
pulsout 2,PWin
PWinPrev=PWin
goto StraightThru: 'Return to re-measure the input pulse
Stay:
pulsout 2,PWinPrev 'Set output pulse to input pulse
goto StraightThru: 'Return to re-measure the input pulse
I can only get it to simulate until the loop line. is it the right code for this software (PICAXE Programming) or is there something missing that i need to fill in.
Once I understand the code I want to use it to read the signal coming from a RX receiver, used in model aircarfts to control up to five servos.
Three servo for wheel on a model and the ofter two servos for the doors on the model for the undercarriage.
Whiles I'm here I will give you an idea of what I'm trying to do.
I want the two servos for the door to open up the doors, once they have opened I what the wheels to come down using the slow code. then in reverse I want the wheels to go up then the doors to close.
But all of this needs to work off one channel from the RX receiver. so if a forward signal is sent from the transmitter the door need to open with a pause on the wheel until the doors have fully opened then the wheels to come down. But when a reverse signal is sent from the transmitter I want the wheels to go up, with a pause on the doors until the wheel have fully gone up.
any help would be appreciated.
Danny