Shop OBEX P1 Docs P2 Docs Learn Events
BSIISX - Connecting Servo''s Correctly — Parallax Forums

BSIISX - Connecting Servo''s Correctly

ArchiverArchiver Posts: 46,084
edited 2000-10-20 05:38 in General Discussion
Original message from: "Ray McArthur" <rjmca@u...>
>
>Nick:
>The red wire goes to +5 volts.
>Black goes to gnd.
>White goes to your Stamp pin.
>
>I advise a 1K resistor in series to the stamp pin, it doesn't effect
the
>servo and provides protection to the Stamp.
>
>Here is BS1 code that I have used to cycle servos back and forth. I
am not
>familiar with the SX, so you will have to convert the code. Pay
special
>attention to the PULSOUT...the SX probably uses different units of
time.
>This program generates 1 to 2 millisecs with a BS1, (Pulsout
100=10us*100=1
>millisec). Also, check on the Pause statement, I don't know if it's
the
>same for the SX. For the BS1, Pause 15 is a 15 millisec delay. Also
make
>sure your power supply can support the current drain of a servo.
Many
>problems show up on this list because the power supply bogs down when
the
>servo moves, resulting in a Stamp reset.
>
>Hope this helps,
>Ray McArthur
>
>'PROGRAM "SRVOTST1.BAS" 10/4/00
>'TO TEST RC SERVOS
>DIRS=%11111111
>LOW 0
>AGAIN:
>FOR B2=100 TO 200 STEP 2
> PULSOUT 0,B2
> PAUSE 15
>NEXT B2
>FOR B2=200 TO 100 STEP -2
> PULSOUT 0,B2
> PAUSE 15
> NEXT B2
>'DEBUG "AGAIN"
>PAUSE 1000
>GOTO AGAIN

Just a note of caution, I was told that driving a servo one way and
then another at high speed will wear out the servo quite fast. I drive
my servo's using an acceleration variable instead of just a simple
position statement. By controlling acceleration you can softly
accelerate and decelerate the servo from start to stop thus prolonging
the servo life. Although it makes the coding more compicated.

The acceleration rate thus looks like this: 0,1,2,3,4,5,6,7,8,9,
instead of 0 to top speed.

Here is the program for 'organic' servo motion, it is by no means
elegant at this stage:



'THIS CODE MOVES A SERVO LEFT TO RIGHT
'WITH AN ORGANIC MOTION

a var word
mo var word ' servo position
x var byte ' accelleration rate

servo:

x=0
mo= 600
for a = 1 to 10 '******HOLD INITIAL POSITION FOR A WHILE
pulsout 0, mo
pause 15
next


'************begin

'rev up
for a = 1 to 20
pulsout 0, mo
pause 15
mo=mo+x '
x=x+1 '0,1,2,3,4,5,6,7,8,9
next


'slow down
for a = 1 to 20
pulsout 0, mo
pause 15
mo=mo+x '
x=x-1 '9,8,7,6,5,4,3,2,1,0
next




for a = 1 to 10 '******HOLD FINAL POSITION FOR A WHILE
pulsout 0, mo
pause 15
next



'rev up in opposite direction

for a = 1 to 20
pulsout 0, mo
pause 15
mo=mo-x ' negative value of below
x=x+1 '0,1,2,3,4,5,6,7,8,9
next


'slow down in opposite direction

for a = 1 to 20
pulsout 0, mo
pause 15
mo=mo-x ' negative value of below
x=x-1 '9,8,7,6,5,4,3,2,1,0
next


'*************

goto servo 'repeat





Jason





__________________________________________________________________
Get your free Australian email account at http://www.start.com.au
Sign In or Register to comment.