PDA

View Full Version : Continous Rotation Servo - How to...?



Mike C
05-25-2005, 12:57 PM
Hello,

I'm a bit confused about how these servos work. This is my code:

' {$STAMP BS2}
' {$PBASIC 2.5}

servo PIN 0
sensor PIN 1
charge_time VAR Word
main:

HIGH sensor
PAUSE 1
RCTIME sensor,1, charge_time
DEBUG DEC charge_time, CR
IF charge_time > 200 THEN
PULSOUT servo, 900
PAUSE 20
ENDIF
GOTO main

----------------------------------------------------

The servo would spin for a while then stop, I'm not sure why. Is it because the position has been achieved and it won't budge anymore? (since i felt that it is harder to manually spin the servo bc the servo seems to be holding it in place).

I'm connecting the servo using a voltage regulator 7805. I was also curious if I could connect a 2nd servo using the same voltage regulator or do I need to apply a 2nd one?

I was hoping that the servo would either be ON or OFF, so I'm a bit confused as to how it works.
Much appreciated for all the help (and patience) people have given me in this forum.

Jon Williams
05-25-2005, 07:29 PM
You may want to try a different strategy -- the servo will stop when you send it a pulse·of 1500 uS.· Perhaps this will work:

' {$STAMP BS2}
' {$PBASIC 2.5}

Servo········· PIN··· 0
Sensor········ PIN··· 1

charge_time··· VAR··· Word

Setup:
· LOW Servo

Main:
· DO
··· HIGH Sensor
··· PAUSE 1
··· RCTIME Sensor, 1, charge_time
··· IF (charge_time > 200) THEN
····· PULSOUT Servo, 900
··· ELSE
····· PULSOUT Servo, 750
··· ENDIF
··· PAUSE 20
· LOOP

Two things I added: 1) The Servo pin is initialized low since the servo wants a high-going pulse (PULSOUT simply inverts a pin for the specified period, then inverts it back, and 2) I added the PULSOUT to stop the servo when the charge_time variable is less than 200.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Mike C
05-26-2005, 03:14 AM
Hi Jon, thanks for your reply.

I've implemented your code, but the servo would spin for a bit then stop, and also if the charge_time value goes back to < 200 and I turn the charge_time value back up to > 200, the servo would not move at all. I was hoping that everytime the charge_time is > 200 the servo would spin continously until the charge_time is < 200, then be able to re-initiate the process again.
Thanks again.

Jon Williams
05-26-2005, 04:24 AM
I'm not sure why the program isn't working as you expect. You may want to toss in a couple DEBUG statements to see what the values are and why the servo is stopping when you don't expect it to. How's your power supply? Could that be an issue? Also, do you have a common ground between the Stamp and the servo?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Mike C
05-26-2005, 04:43 AM
Hi Jon,

I have tested with a debug and verified that the charge_time is fine.
I am not sure about power supply, but I'm using a Homework Board and I have a voltage regulator reducing the voltage down to 5 volts from Vin.

Jon Williams
05-26-2005, 05:44 AM
Do not power the servo from the Homework board -- it's regulator is just not strong enough to handle servo currents. You'll need a separate five (or six -- no problem for the servo) supply to handle the servo load.

EDIT: Do not use the Vdd pin on th HWB -- the Vin connection is fine (servos can tolerate 9V).· Just be aware that if you do use Vin and more than one servo, you could go through your 9V battery pretty quickly.· Sorry for any confusion.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 5/27/2005 12:10:41 PM GMT

Mike C
05-26-2005, 05:53 AM
Hmm....so get like a 4pack AA battery holder and wire that up to the homework board to power the servo?
Would it be necessary to run the power from the battery thru the 7805 to down it from 6 volts to 5 volts?
Thanks again Jon.


P.S. If I am using two servos would I then need 10 volts of power to run them simultaneously?

Post Edited (Mike C) : 5/25/2005 11:15:05 PM GMT

Jon Williams
05-26-2005, 06:45 AM
If you get a 4-pack, you might as well go with C or D cells so you have lots of life in your batteries (you only need six volts for both servos as they are connected in parallel). The Black (ground) connection of the battery pack needs to be connected to the Vss connector on the Homework board (this also goes to the servos). The red (positive) connection goes to the positive (center) lead of the servos -- it does not need to connect to the HWB in any way. The output pins from the HWB go to the servo signal lead (usually white).

With ample power now for your servos, your program should run fine.

Edit: I whipped up a quick diagram that should make things more clear.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 5/26/2005 12:16:24 AM GMT

Mike C
05-26-2005, 09:34 AM
Hi Jon,

Thanks for the diagram, I will post results after I get my hands on some batteries. :)

Mike C
05-27-2005, 11:40 AM
I got a 4 pack AA battery holder and wired it one servo for testing sakes...then grounded it with the servo.
At first I had trouble, the servo was just ticking in rotation and not spinning smoothly, then I realized that the sensor wasn't connected to the pin cuz there was no output on the debug screen. Hooked it up and everything works!

I'd like to thank Jon for your help and effort. I've trully found this forum to be more supportive than they needed to and people are willing to take the extra step to explain or show how things work.

THANKS!!! :)