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

Servo mystery

bluejaybluejay Posts: 131
edited 2013-01-07 17:10 in BASIC Stamp
Could someone explain why the servo does not stay in the last position? The servo goes to the zero position first, then goes to the 180 degrees position. The problem is that after reaching the

180 deg position after a slight delay the servo the travels to the 175 deg position and stays there. I want the servo to stay in the 180 deg position and NOT go to the 1175 deg location.

Will someone solve this mystery? I appreciate a response. Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-06 20:26
    Your program is written to move the servo to the 0 degree position for about 3 seconds, then to move the servo to the 180 degree position for about 3 seconds, then your program stops. What also stops is the continual train of servo control pulses every 20ms or so. After a short time without these pulses, the servo will shut itself off. The power to the motor will be turned off and the motor will not hold its position. Other than the gear friction, there's little to hold the servo from moving in response to pressure from whatever is mechanically connected to it.

    To keep the servo at a certain position, you have to continue to supply control pulses to it. For your simple program, you can just turn the last FOR / NEXT loop into a DO / LOOP loop like this
    DO     '180 degrees until the power is turned off
        PULSOUT 14, 1248
        PAUSE 20
    LOOP
    
    If your program will have to do something else that can't be done in the 18ms or so left in the 20ms servo control pulse cycle, you'll have to add some kind of external servo controller to handle this like the Propeller Servo Controller or the ServoPAL (temporarily unavailable).
  • ercoerco Posts: 20,256
    edited 2013-01-06 21:00
    The CLUE version of solving this "Servo Mystery":

    Dr. Green, in the Stamp Forum, with a DO loop. :)
  • bluejaybluejay Posts: 131
    edited 2013-01-06 21:12
    Thanks Mike for the solution. The correct DO/LOOP, coding is as follows:

    counter VAR Byte

    For counter = 1 to 150 '0 deg for about 3 sec
    PULSOUT 14, 250
    PAUSE 20
    NEXT

    DO
    For counter = 1 to 150 '180 deg for about 3 sec
    PULSOUT 14, 1248
    PAUSE 20
    NEXT
    LOOP
  • ercoerco Posts: 20,256
    edited 2013-01-06 21:39
    Per Mike's post, you don't even need that for/next loop inside the do loop:

    DO
    PULSOUT 14, 1248
    PAUSE 20
    LOOP
  • bluejaybluejay Posts: 131
    edited 2013-01-07 16:21
    That's true Erco. Now the problem is that everytime I run the coding the servo moves somewhat prior to following the commands.
  • ercoerco Posts: 20,256
    edited 2013-01-07 17:10
    It's fairly normal that analog servos glitch when you first turn the power on or even restart the program. Same is true of R/C cars & planes. Digital servos might be better at this.

    What sometimes helps reduce glitching is:

    1) before you power down, have your program drive the servos to where you want them to be on powerup, and
    2) turn on power (3.3 or 5V) to your controller (thus sending control pulses to the servo) before seperately switching on power to your servos (typ 6V).
Sign In or Register to comment.