Loop Command Not running

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
 

BCJKiwi

Senior Member
loop is now a reserved word - part of the do... loop structure.
So loop cannot be used as a label anymore - just change it to something else e.g. loop1 or whatever you like.
 

danielwi11iams

New Member
Thanks I just worked it out, just as I came back to write back on here. thanks again.

Would you have any help with the last part of my question.

"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."
 

BeanieBots

Moderator
Should be simple enough.
Use pulsin to detect the incomming servo signal.
Jump to first routine if pulse > X
Jump to second routine if pulse < X

The first routine does the doors open wheels down
The second routine does the wheels up doors shut
 

danielwi11iams

New Member
Sorry to sound so dumb. but this is all new to me, I'm trying to get my head around the basic stuff.

Can you give me an example of were to start. and would I be able to use it with a 08M chip.

What it the rule, if any, with component connected to the chip.

Would I be able to use the circuit layout in this file to do what i need.

http://www.rev-ed.co.uk/docs/axe024.pdf

But without the other connections, just a finished programed chip, and a small circuit board, due weight in the model.

Hope this clear for you to understand.

Thanks Danny
 

BeanieBots

Moderator
It would probably do what you want.
Bottom line, the 08M chip (the one that circuit is based around) can read in one servo channel and drive up to four servos. If that is OK for you control wise, then I'm quite sure the required code will fit in it.
Remember, just as with a normal Rx output, you can connect several servos to the same channel.
The 08M is available surface mount, so you can make it very small & light.

Where to start:-
Well, I'm not going to do it for you (somebody else might).

To read a servo channel, use "pulsin".
It will return a value about 75 and 225 for the two extremes of your 'stick'.
A value of 150 is neutral.

Test the value and jump (or gosub) to the routine that does what you want done. You already have the code for the first part. Once you've read and understood it, it should become clear what to do for the reverse of that.

Anyway, I'm sure with a little patience some kind person will write the whole thing for you.
 
Last edited:

danielwi11iams

New Member
Thanks for your help any way, I'm using the code that I found, but when I get to the line on the first part, saying " if PWin<75 or PWin>225 then restart" that is confusing me. due to it asking both values.

Reason being is that I'm trying to keep the servo slow program in the chip so that the undercarriage looks more real. but when I need to but my part of the program in I just get lost with it all.

I think with a bit of playing around I just might get it. But I hope I don't get to a stage were I just give up. due to that possiblities of thing you can do with these chips.

But if anyone would point me in the right direction, that would be appreicated.
 

hippy

Ex-Staff (retired)
when I get to the line on the first part, saying " if PWin<75 or PWin>225 then restart" that is confusing me. due to it asking both values.
This is a bit like saying you're learning to play an instrument but when you read the music score you don't have any idea what the dots mean, reading a foreign language book but don't understand any of the words, trying to solve complex equations without having understood basic math.

You've dived into a project without really understanding what you're doing and you are going to fall at many hurdles. While it's excellent having a goal one wants to reach, like cooking a perfect meal you aren't going to get it perfect first time or without practice and being familiar with what you'e doing and what the instructios mean.

The best thing I'd suggest is taking some time out from your intended project and get to learn how the PICAXE works and what the commands do. Simpler projects such as flashing a LED, reporting back to the PC what the received servo position is and so on will get you up to speed.

As to the "if PWin<75 or PWin>225 then restart" ... PWin I expect ( I didn't read the code ) is the recieved PULSIN signal and this just checks that it's in a valid range, and if not ignores it. PULSIN reads pulses with a 10uS resolution so a 750us pulse is reported as 75 a 2250us pulse as 225. This is the range a servo can be operated over so here it's just making sure that the PULSIN is valid for servo control later; if the pulse is less than 75 (750us) then restart, if the pulse is greater than 225 (2250us) then restart.
 

danielwi11iams

New Member
ya I sort of understand it but I need to spit it for my operation.

I need the <75 range to send the program somewhere else in the code
I also need the >225 range to send the program somewhere else in the code

But as you can see the code has it all in one line telling it to go somewhere else, that is need to slow the servo down, if need. but if I need it to operate the door then the wheel at a particular speed that is where i'm confused.
 

hippy

Ex-Staff (retired)
In that case simply change the label ...

if PWin<75 or PWin>225 then SomewhereElse

or, if you want to handle each under or over range separately ...

if PWin<75 then SomewhereElseUnderRange
if PWin>225 then SomewhereElseOverRange
 

danielwi11iams

New Member
But if i do that i dont keep the code to use the slow down process of the servo and all the safty code that stops the servo over turning.
 

hippy

Ex-Staff (retired)
Maybe I'm missing something but you can't have it all ways. You either have that check to stop over turning or you don't. Altering how an out of range is handled doesn't alter what happens when it's in range.

The original code is like waiting for someone to knock on the door knowing a friend you want to let in will knock two or three times; if they knock less than twice or knock more than three times they are ignored. All you're doing in making the alteration is changing how you handle what happens in the circumstances you were previously ignoring ( maybe you'll throw a bucket of water out the upstairs window instead ). How you deal with someone who knocks two or three times remains the same.
 
Top