Shop OBEX P1 Docs P2 Docs Learn Events
Controlling A Servo — Parallax Forums

Controlling A Servo

StampyStampy Posts: 26
edited 2014-09-04 11:28 in BASIC Stamp
So, Im trying to learn how to run a servo using the PWM. I am using a BS2, and have tried a regular servo that a Continues servo but get either servo to run for a period or change
direction, note I am using the Sample Parallax code...

The code:
' RotateParallaxCrServo.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
servoPin PIN 12 ' change I/O pin for servo signal here

FOR counter = 1 TO 100 ' Rotate counterclockwise for ~3 seconds
PULSOUT servoPin, 850
PAUSE 20
NEXT
FOR counter = 1 TO 100 ' Hold still for ~3 seconds
PULSOUT servoPin, 750
PAUSE 20
NEXT
FOR counter = 1 TO 100 ' Rotate clockwise for ~3 seconds
PULSOUT servoPin, 650
PAUSE 20
NEXT
END

This is the sample Parallax code. When I use a continues rotate servo, it spins only one direction never stopping. When I use a regular servo it barely moves. Note the BS2 is plugged into a Board of ED platform, Please, any ideas whats going on???

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2014-09-01 19:04
    What you're seeing is not wrong. A continuous motion servo stops when the pulse is 1.5ms long (PULSOUT ...,750). It should rotate in one direction for pulses between 1.5 and 2.0ms (750 to 1000) and rotate in the other direction for pulses between 1.0ms and 1.5ms (500 to 750). If the servo is not calibrated, the stop setting may be off (something other than 750).

    A standard servo moves through a range of 180 degrees typically over a pulse width of 1.0ms to 2.0ms (500 to 1000). Midpoint is at 1.5ms (750). There's not a lot of position difference between 850 and 750 or between 750 and 650. Try PULSOUT values more toward the ends of the range like 550 and 950.
  • StampyStampy Posts: 26
    edited 2014-09-02 05:39
    Hi Mike, Thank you. I had actually also tried using values like 500 and 1000 for the Pulsout and had the same results. So I am now confused, especially with the test program coming from the learn.parallax forum. I also tried using a different IO pin, no better. Possible something wron with the stamp itself causing the issue?
  • PublisonPublison Posts: 12,366
    edited 2014-09-02 05:53
    Have you tried to center the continuous rotation servo using the instructions in this document?

    Is it a Parallax CR Servo?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-09-02 06:40
    Stampy wrote: »
    Possible something wron with the stamp itself causing the issue?

    It's more likely your power supply can't provide enough current. I'm going to bet you're using a 9V battery? If so, don't!

    Servo draw a lot of current when they first start to move and this causes the voltage to drop which resets the microcontroller. This is a very very common problem.

    You either need a better battery pack or a good wall transformer which can supply at least 1 amp of current.

    Sometimes a big capacitor across the servo power lines will keep a microcontroller from resetting when using weak batteries/power supply. You might want to try adding a capacitor across the power lines of your servo.
  • GenetixGenetix Posts: 1,754
    edited 2014-09-02 10:10
    Stampy, servos need a lot a current to operate and a new 9V battery will drain quickly. While you can run a servo for a short time on a 9V battery, you should use 4 AA Alkaline or 5 AA rechargeable batteries since they will last longer. Just be sure the jumper between the Servo Ports is set to VIN.
    As Duane mentioned weak batteries can cause all kinds of servos issues and Continuous Rotation servos must first be centered.

    Chapter 4 of What's a Microcontroller is on Standard servos
    http://www.parallax.com/sites/default/files/downloads/28123-Whats-a-Micro-v3.0.pdf

    Chapter 2 of Robotics with the Boe-Bot is on Continuous Rotation servos
    http://www.parallax.com/sites/default/files/downloads/28125-Robotics-With-The-Boe-Bot-v3.0.pdf
  • StampyStampy Posts: 26
    edited 2014-09-02 13:43
    Hi Guys and thanks again for the info. I am in fact using a wall pack for power (9VDC @ 1A) to power the BOE and the servo and not the 9V battery. Now the large cap across the servo power is
    a thought. Any other value to suggest if other that the 3300uf to use? I am still thinking of trying another BS2 or SX which ​also have.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-09-02 14:44
    Stampy wrote: »
    Any other value to suggest if other that the 3300uf to use?

    That's what I'd use.

    If you add a line to your code to send a debug message when the program starts (or blink a LED) you can see if the BS2 is resetting or not (I bet it is). Wall warts can have trouble keeping up with the demands of a servo. There's a good chance the cap will help.
  • StampyStampy Posts: 26
    edited 2014-09-02 17:48
    Success! at least for now, Turns out the input voltage had to be more. I used a 12V7A gel cell battery to power the BOE and servo, and that program that I've been trying to use did in fact work. I was
    able to verify with both a regular servo and the continues one. S I have very happy to have get this far. Thank you all.
  • GenetixGenetix Posts: 1,754
    edited 2014-09-02 21:39
    Stampy, if you look at the documentation you will see that it says not to apply more than 6V to a servo. While you can use a higher voltage it will shorten the servo's life. Batteries are recommended unless you are absolutely sure you have a 6V regulated power supply.

    http://www.parallax.com/sites/default/files/downloads/900-00005-Standard-Servo-Product-Documentation-v2.2.pdf
    http://www.parallax.com/sites/default/files/downloads/900-00008-Continuous-Rotation-Servo-Documentation-v2.2.pdf

    Also, what is the jumper between the servo ports set to? Vdd or Vin?
  • StampyStampy Posts: 26
    edited 2014-09-03 05:49
    Yep, am very aware of the voltage levels to a servo (I fly RC model airplanes as another hobby). While the 12V was used to power the BOE, it was going thru the regulator, and the servo was getting a 5V also from
    this regulator. All this was to see if maybe I had a bad stamp issue. The next robot, I plan on providing separate power to the stamp and servos ( I have an old bot design from several years ago that I want to recreate, and make it into a much larger design eventually.
  • GenetixGenetix Posts: 1,754
    edited 2014-09-03 15:43
    Stampy, since you already have a Board of Education why not just build a Boe-Bot with this kit.
    http://www.parallax.com/product/28124
  • StampyStampy Posts: 26
    edited 2014-09-03 19:33
    Yeah, I've been thinking about building my own version of the BOE bot actually. Eventually I want to redo a robot I started along time ago, and will be looking to utilizes a lot of VEX material for it.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-09-03 22:37
    I think I have some brand new Vex gears and such to get rid of. Let me know if you are interested and I can send some pics.
  • StampyStampy Posts: 26
    edited 2014-09-04 11:28
    Yeah? Cool, What parts do you have?
Sign In or Register to comment.