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

Servo Shake

Jeff KJeff K Posts: 2
edited 2009-06-05 03:17 in BASIC Stamp
I'm working through the "What's a Microcontroller" book, and I just wrapped up the potentiometer chapter.· One of the last programs controls a servo position by turning the pot.· Code is:

DO
· HIGH 7
· PAUSE 100
· RCTIME 7, 1, time
· DEBUG HOME, DEC5 time
· time = time */ 233
· time = time + 500
· PULSOUT 14, time
LOOP

My scale is .911 based on earlier tests.

It works fine, but the horn shakes (moves a very very short distance clockwise and counterclockwise repeatedly) at most midpoints along the pot.· Occasionally I can find a place where it sits still.·

I think it's because the time to discharge the capacitor on 7 isn't constant even when the pot is steady.· Or maybe the pot isn't so great and it lets a slight variation in current through?· Could that be right?· The debug line shows a constant number, but I thought it might be a rounding thing...

Thanks!

·

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-04 05:07
    I think your pause statement is too long.

    Rich H
  • SRLMSRLM Posts: 5,045
    edited 2009-06-04 05:43
    You might also want to add logic that doesn't move the servo at all if the measured value is within 10 units of the current servo value. It doesn't have to be 10, but you can play with that number and see what works.
  • FranklinFranklin Posts: 4,747
    edited 2009-06-04 23:14
    I think SRLM is on the right track. Put a debug statement in your code and see how much time changes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Jeff KJeff K Posts: 2
    edited 2009-06-05 01:53
    Thanks - I ended up putting in the tolerance and changing the pause time:

    lastTime = 0

    DO
    HIGH 7
    PAUSE 50
    RCTIME 7, 1, time
    DEBUG HOME, DEC5 time
    time = time */ 233
    time = time + 500
    DEBUG CR, DEC5 time
    IF ABS(time - lastTime) > 12 THEN
    PULSOUT 14, time
    ENDIF
    lastTime = time

    LOOP

    Did the trick!
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 03:17
    I would go lower with the pause. Servos expect a signal 50 times a second or once every 20 milliseconds. With a 50 mS pause the servo is getting updated less than 20 times a second - the rest of the code takes some time too so the total time between PULSOUTs will be more than 50 mS. It doesn't have to be exact, servos are very tolerant. I would use a pause of 20 just because it is a nice round number. If you want to get exactly 50 hz you'll need to figure out how much time the rest of the code takes to execute and subtract that from the pause.

    Rich H
Sign In or Register to comment.