problem with a servo

papillon2012

New Member
hello !

First : excuse my english, but i'm french (nobody's perfect :p)

Here's my problem : i want to use a servo in my project. So I bought a 9g miniature servo. My project is based on a 18M2.

i tried the code in the manual :

Code:
init: servo 4,75 ‘  start servo on 4
main: servopos 4,75 ‘  move servo to one end
pause 2000 ‘  wait 2 seconds
servopos 4,150 ‘ move servo to centre
pause 2000 ‘  wait 2 seconds
servopos 4,225 ‘  move servo to other end
pause 2000 ‘  wait 2 seconds
goto main ‘  loop back to start
but my servo doesn't act as i expected : i thougt it would stay in position '150' during 2s and then go to position '225' and keep this position during 2s and so on...

here's the way my servo acts : it goes to '150' and immediately go back to 75, then it waits 2s and it goes to 225, it goes back immediately to 75 and so on...

Is the behavior of my servo normal ? and how can i do to obtain what i want to : i want my servo to keep the position i need, during the time i decided...

Thanks

Fred
 

inglewoodpete

Senior Member
The fact that the servo keeps on returning to 75 suggests that the PICAXE is robooting, probably due to the electrival noise created within the servo motor.

Try wiring a 100uF electrolytic capacitor across the +ve and 0v wires of the servo, right at the connector plug.

Also, connect a 100nF (0.1uF) as close as you can to the +5v and 0v legs of the PICAXE.

Peter

Edit: You could also add a LED and 330ohm resistor on another pin of the PICAXE. Then add the command "PulsOut <pin>, 5000" at the very beginning of your program. The LED will only flash when the PICAXE boots (reboots): that will tell you if I am on the right trail.
 
Last edited:

hippy

Ex-Staff (retired)
The servo should not move to 75 between 150 and 225 but it will move to 75 after 225, because of the first 'servopos' after the 'main:'.

You can run the code through the Programming Editor Simulator to check you don't have an inadvertant 'servopos 4,75' between 150 and 225.
 

papillon2012

New Member
thanks hippy : no prob with the code, because i used "copy-cpaste" from pdf manual to programming editor

but i've just noticed that my servo never goes to 225... it just goes from 75 to 150...

so here's my second thanks to inglewoodpete : i think my picaxe reboots because of electrical noise.

Inglewood : i try to do what you tell me and i give you news as soon as possible.

Thanks

Fred
 

papillon2012

New Member
:D problem solved !

thanks guys. A 100uF capa and everything's ok.

I'm sorry, it's not the first time i use a picaxe, but it's the first time i use a servo.

Thanks again.

Fred.
 

SolidWorksMagi

Senior Member
hello !

First : excuse my english, but i'm french (nobody's perfect :p)

Here's my problem : i want to use a servo in my project. So I bought a 9g miniature servo. My project is based on a 18M2.

i tried the code in the manual :

Code:
init: servo 4,75 &#8216;  start servo on 4
main: servopos 4,75 &#8216;  move servo to one end
pause 2000 &#8216;  wait 2 seconds
servopos 4,150 &#8216; move servo to centre
pause 2000 &#8216;  wait 2 seconds
servopos 4,225 &#8216;  move servo to other end
pause 2000 &#8216;  wait 2 seconds
goto main &#8216;  loop back to start
but my servo doesn't act as i expected : i thougt it would stay in position '150' during 2s and then go to position '225' and keep this position during 2s and so on...

here's the way my servo acts : it goes to '150' and immediately go back to 75, then it waits 2s and it goes to 225, it goes back immediately to 75 and so on...

Is the behavior of my servo normal ? and how can i do to obtain what i want to : i want my servo to keep the position i need, during the time i decided...

Thanks

Fred


Hi,

I don't get it??? The online manual (http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/servo/) says the code isn't for 08 nor 18 chips ???

I've tried the code with my 18M2 and it doesn't function.

Is there a simple example of 18M2 code to turn a servo from .5ms to 1.5ms to 2.5ms ... Left, Center, Right?

From one good example I can configure for all my projects.

Another question is in the manual shows the format as SERVO pin,pulse ... the code above it says pin 4? On an 18M2 pin 4 is C.5 ... this is a little confusing.
 

westaust55

Moderator
As per the PICAXE manuals and online versions, the SERVO function for M2 and X2 parts only works with PortB.

So you could use B.5 but not C.5.

A reference to pin4 from older code was by default for PortB which was on most PICAXE chips pre assigned as outputs only.
Typically the older code will still work on the newer parts and pin 4 is taken by default to be B.4.

On the 18M2, both C.4 and C.5 are inputs only and can never send a signal out to external devices.
 
Top