Shop OBEX P1 Docs P2 Docs Learn Events
basic servo control question — Parallax Forums

basic servo control question

ziggyramaziggyrama Posts: 1
edited 2007-10-04 02:13 in BASIC Stamp
Hi, I am sure this has been addressed before, but I haven’t had any luck finding an answer. I am trying to control a single servo and move it slowly from a stationary center position to a 90 degree position and hold it using a BS2 and an unmodified servo. I am using a standard FOR NEXT LOOP to move it, but cannot figure out how to leave the loop and keep the servo at 1250 once it reaches the final point. The servo simply pans back and forth between the two positions. I've tried using an IF statement to leave the loop, but it doesn't seem to work. Any help would be appreciated.

Thanks

for x = 750 to 1250 STEP 25
PULSEOUT 1,x
PAUSE 20
NEXT

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 19:21
    ServoPos VAR WORD
    X VAR WORD

    FOR x = 750 to 1250 step 25
    ServoPos = x
    GOSUB RefreshServo
    NEXT

    RefreshForever: ' Infinite loop, holding servo position...
    GOSUB RefreshServo
    GOTO RefreshForever

    END

    RefreshServo:
    PULSOUT 1, ServoPos
    Pause 20
    RETURN
  • LilDiLilDi Posts: 229
    edited 2007-10-04 02:13
    With a BS2, each PULSOUT unit is 2 micro seconds. A servo pulse width is from 1.0 milliseconds to 2.0 milliseconds.
    Doing the math, that means the code for moving the servo should be

    FOR x=500 to 1000 step 25

    Center position is PULSOUT 1,750
Sign In or Register to comment.