Shop OBEX P1 Docs P2 Docs Learn Events
Servo problems — Parallax Forums

Servo problems

aeanaean Posts: 5
edited 2007-02-09 21:46 in Robotics
I'm an EE major and I've been issued a BS2 for my industrial automation class, been playing with it and having fun so today went to the RC store and get some servos (JR Sport ST47 47 ounce). Using the pulsout I can send the servo to a position easy enough but no matter how I write the code I can't make the position change during the program.

Like say I wanted it to rotate clockwise:

a VAR Word

FOR a = 350 TO 1250 STEP 10
PULSOUT 7, a
PAUSE 20
NEXT

Should do it right? What happens when I run that is the servo rotates to the PULSOUT 350 spot and just stays there.

It does the same thing if I use a DO WHILE with a counter variable or make a series of IF statements that accepts input from DEBUGIN to send it to routines to change position. It seems like whatever PULSOUT it encounters in the program first, it just stays there.

Any ideas what the problem is?

Thanks

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2007-02-09 04:05
    "What happens when I run that is the servo rotates to the PULSOUT 350 spot and just stays there"

    Are you sure it's not the 1250 spot?

    By the looks of your program it is running correctly, however after 90 itterations or about 1.8 seconds· (1250-350)/10 = 90 * 20mS = 1.8 seconds
    it·stops·and there is nothing to tell it to continue doing anything else.

    Try something like this:· (Should "pan" the servo back-n-forth)

    a VAR Word 
    
    MainLoop: 
    
    FOR a = 350 TO 1250 STEP 10 
    PULSOUT 7, a 
    PAUSE 20 
    NEXT 
    
    FOR a = 1250 TO 350 STEP 10 
    PULSOUT 7, a 
    PAUSE 20 
    NEXT 
    
    GOTO MainLoop
    

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • aeanaean Posts: 5
    edited 2007-02-09 04:17
    When I run it does much the same, it rotates to the 350 position and stops, if I move the servo horn by hand, it spins back to 350. I swapped the order of the FOR statements and it behaves identically, rotating to the 350 spot. :/

    I'm powering the Stamp off a 9v and the servo off another 9v voltage divided down to about 5.5v, if that makes any differance
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2007-02-09 04:54
    "the servo off another 9v voltage divided down to about 5.5v, if that makes any difference" - hmmm it could, how are you doing that?

    Also, are you sharing the ground supplies between the servo and the stamp? ....using the correct pin on the BS2? (pin#12)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • aeanaean Posts: 5
    edited 2007-02-09 05:05
    Pin 12 on the stamp I have is i/o 7, I've got a 9v + to pin 24 Vin and - to pin 23, Vss. Power for the servo comes from + off the terminal and the ground from between two resistors forming the divider.

    Earlier I was trying to power the servo off pin 21 VDD, it was my understanding that when Vin was supplied with a voltage, this pin would be regulated to +5, after looking at my spec sheet it seems I was trying to power the servo with pin 22, Reset. Could this have damaged the servo or stamp?

    Thanks for the help
  • aeanaean Posts: 5
    edited 2007-02-09 06:28
    Aftering reading through the What is a Microcontroller pdf I upped to the V to my servo, it must've not been getting enough potential or current, it works just as it should now, thanks

    -Brett
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2007-02-09 06:40
    "Power for the servo comes from + off the terminal and the ground from between two resistors forming the divider"

    This is likely the culprit.· Your servos are going to require several mA of current,· and using a resistor divider is not going to be adequate
    for this particular application.· Mainly because you have a varying load depending on what you are demanding of your servos,· that alone
    will throw a resistor divider scheme out of whack.· While the regulated 5V from the Stamp "might" work, it's not something I would advise
    for long term use, especially with any kind of respectable load on your servo.· The best thing to do is use an external voltage regulator such
    as an LM7805 and make sure that the grounds are tied together.

    If I were you, I would take a look at the "What's a Microcontroller"






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-02-09 14:12
    Generally, having a separate battery supply for motor power makes things a lot less trouble. Only the ground is common.

    In this way, the BasicStamp can provide power to a transistor, MOSfet, darlington, or UNL2003 that controls the motor without suffering sags from the motor starting or being stalls. If the sags are significant, the BasicStamp will often just loop through a reboot.

    A voltage divider seems an easy way to provide an alternative power, but it is both quite wasteful of power and tricky to get right. A voltage regulator really is a much better solution than a divider as the votage will hold within a few percent over a wide range of flux.

    If you can get LM2940-5 regulators instead of the 7805, you will find that they are more forgiving of mistakes [noparse][[/noparse]shorts and reversed polarity], operate at lower battery voltages, and can actually prevent a lot of frustration. They do require a larger capacitor on the output side.
    They do come in other voltages - like the LM2940-3.3 for 3.3volts, LM2940-12 for 12.0 volts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • aeanaean Posts: 5
    edited 2007-02-09 21:46
    Thanks for the help guys, got another battery and some LM7805s from the shop, everything works as it should.
Sign In or Register to comment.