Shop OBEX P1 Docs P2 Docs Learn Events
Twitching Servo using BS1 — Parallax Forums

Twitching Servo using BS1

garyggaryg Posts: 420
edited 2012-05-05 06:40 in BASIC Stamp
Hi
I'm using a BS1 module.
I set up a circuit that will output pulses to the Parallax standard servo.
The program looks at the pot that I'm using to control the position of the servo arm.
Everything appears to be working as designed except for the fact that when the pot is in a number of
different locations, the servo will twitch like it's receiving a couple of different locations to go to.
When I include the debug statement to monitor the go to position, I always get the same number,
However, the servo will twitch back and forth about 1 degree or so, as though it's looking for a different location.
If I alter the location of the pot just very slightly, the twitching goes away and the servo appears to be at
rest at the location called for.
My question is this:
Are there any position numbers that are confusing to the Parallax Standard servo?
I'm doing a strictly research project involving moving a finger that I've fabricated into different positions from
fully extended to grabbing onto different objects.
My BS1 supply is a 9 Volt battery that is regulated down to 7.7Vdc.
My Servo is being supplied by Four AA batteries.
I've checked the voltages and they are as fully charged batteries.

The servo driving logic is:

setup
SYMBOL PotPin = 0
SYMBOL Scale = 180
SYMBOL level = B2
SYMBOL levelstorage =W2
SYMBOL Position = W3

FOR position = 1 to 1000
POT PotPin, Scale, Level
levelstorage=B2
IF [EMAIL="W2@<114"]W2<114[/EMAIL] THEN Minimum
If W2>190 THEN Maximum
GOTO Driveservo
Minimum:
levelstorage = 114
GOTO Driveservo
Maximum:
levelstorage = 190
GOTO Driveservo
Driveservo:
Pulsout 1, levelstorage
pause 5
NEXT

I'm thinking that the Logic used to read the Pot will take at least 10 Miliseconds to complete and
the rest of the Logic will more than likely take about 5 Miliseconds to complete.
I've attempted to use pauses in the Driveservo subroutine from 5 to 25 with almost no change in how the
servo responds.

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2012-05-03 18:36
    I have never programed a BS1 but the BS2 requires a "RETURN" and the end of each subroutine.

    Also, I think that for each iteration through the loop you should call Driveservo only one time. Your code calls it three times, which makes for very short pauses between the pulses.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-03 19:17
    Rich, the way the code is now it only "calls" Driveservo once each loop. Each of the three possible branches use "GOTO" to get there. There's no "RETURN" since there aren't any GOSUBs.

    Gary, How does the program behave with just one servo attached. The three servos might be too much for your batteries (though unlikely)? Edit: I don't know why I thought there were three servos.

    Edit: Are the grounds from the two power supplies connected together? If not, they need to be.
  • garyggaryg Posts: 420
    edited 2012-05-03 20:06
    Duane Degn wrote: »
    Rich, the way the code is now it only "calls" Driveservo once each loop. Each of the three possible branches use "GOTO" to get there. There's no "RETURN" since there aren't any GOSUBs.

    Gary, How does the program behave with just one servo attached. The three servos might be too much for your batteries (though unlikely)? Edit: I don't know why I thought there were three servos.

    Edit: Are the grounds from the two power supplies connected together? If not, they need to be.


    Hi
    I did quite a bit of research on Grounding of power supplies about a month ago.
    It had to do with a statement about grounding on the page that I purchased the BS1 module from.
    I utilized information that I had Gleened from the thread I started concerning grounding of BS1.
    Thanks again to those who commented on my grounding dilema.
    I have the grounds connected at what I believe is a low impedence path where the servo current can go quite
    easily back to the 6Volt return and the BS1 supply ground will hopefully not be interfered with.

    Apparently, the servo twitch problem is not uncommon.

    I think I might need to get my O-Scope out of mothballs to see if I really have a signal problem.

    The only thing that I can think of that may be causing the twitching may be that I'm using a Polyester-Film
    capacitor for the Pot to read.
    The Polyester-Film capacitor was the only one that I could find locally with the value recomended in the Basic Stamp
    Reference manual BUT:
    If I get no number change for the position, then I'm telling the servo to go to the same place.
    If I'm giving the servo the same position information, there is something going on here that I absolutely do not understand.
    Is the BS1 PULSOUT command known to output a consistent pulse width?

    If I can resolve the twitching issue, I can continue with this research project.
    I think that the servo, when twitching, is using quite a bit of the available 6 volt battery current.

    Thanks
    Garyg
  • W9GFOW9GFO Posts: 4,010
    edited 2012-05-03 20:07
    Ah, I see now. Thanks.
  • W9GFOW9GFO Posts: 4,010
    edited 2012-05-03 20:11
    Could it be the pot? You could make a test program to run the servo without the pot and see if there is any difference.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-03 20:18
    garyg wrote: »
    Is the BS1 PULSOUT command known to output a consistent pulse width?

    I personally have never used a BS1. I helped someone with a robotic fish project not too long ago so I'm a little familiar with the BS1's syntax.

    I think the BS1 outputs a consistent pulse width if it's given the same value to pulse.

    Have you tried just moving the servo back and forth without the pot in the loop? If not, I'd suggest getting a simple back and forth movement programmed to test the servo.

    One thing I've found very helpful in servo projects (if you look in post #2 of my index, you'll see I've done a lot of servo projects) is that a 1000uF capacitor on the servo's power line can really help. When a servo starts to move is draws a surprising amount of power for a short period of time. This extra current draw can cause the voltage of the system to dip causing all sorts of problems.

    The majority of servo problems I've seen on the forum have been caused by power supply issues. You mentioned AA batteries. What chemistry are they. A good rechargeable battery pack have solved many servo problems.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-03 20:33
    The POT statement charges the capacitor for 10ms, then waits for the capacitor to discharge which could take over 10ms if the resistor is towards the maximum value. That's 20ms already. Add to that the time for the PULSOUT statement which could take as long as 2ms to execute plus some miscellaneous statements which could take 0.5ms to 1ms to execute. The additional PAUSE 5 might well put the timing over the edge for the servo to shutdown which would cause twitching (somewhere past 20ms). Try eliminating the PAUSE 5 for a start. You might try a smaller capacitor or smaller pot value and re-scale the POT scale factor to fit. You haven't provided a schematic, so we have no idea of the resistor or capacitor value, so no idea of the RC time constant.
  • garyggaryg Posts: 420
    edited 2012-05-04 00:06
    Thanks to all
    I need to modify my Fingerboard so that I can absolutely check my Pot voltages and monitor them to see if
    the Pot is giving me a stabil voltage.
    I'm planning on also setting up my test board to be able to include a filter capacitor of about 1000uF for the servo.

    I'll also set up my fingerboard so that I can easily change out my Pot capacitor so that I can determine
    if either my capacitor uF value is too large or if my timing may be too long between the 20ms pulses.

    Mike, If the servo shuts down because of lack of pulse, What does it normally do?

    It may take me a bit of time to do these things because sometimes life gets in the way.

    I've attached a photo of my fingerboard project as is, in case you'se would like to see what I'm up to so far.
    Fingerboard1-1331.jpg


    Thanks again, I really appreciate all of your help and comments.
    Gary
    1024 x 768 - 94K
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-04 05:52
    When a servo doesn't receive a control pulse roughly 50 times a second, the control circuit shuts down until the next pulse comes in. This means that power is turned off to the servo's motor, at least briefly. When the servo motor is powered, it will actively resist any attempt to move it. When it's turned off, the motor will turn freely, but the movement at the other end of the gear chain will be limited by friction. Try it some time. Try to move the servo output shaft without power applied, then try to move it with power and a test program producing a 1.5ms control pulse every 20ms. These brief shutdowns cause the stuttering.
  • garyggaryg Posts: 420
    edited 2012-05-05 06:40
    This morning I removed the PAUSE 5 statement and did a test of the servo motion.
    The 1 degree twitching is gone. The servo moves smoothly now.
    The suggestion of speeding up the approximate 20ms program loop speed appears to have worked well.
    Thanks

    While testing my motion with the PAUSE 5 statement removed, the servo was still buzzing slightly, like it could
    not get to it's final destination. Instead of turning the pot in attempting to eliminate the buzz, I pushed my mechanical
    linkage slightly in the intended direction and the buzz stopped. I think I need to look at freeing up my linkages
    so that it will take less power to get to my final destination.

    Thanks to everyone for your comments and suggestions.
    I can now continue developing the project.
Sign In or Register to comment.