How to make BS2 control min 2 servo at almost the same time?

Hi all,

I have a problem with my project. I need to run at least 2 servo motors at almost the same time using BS2. Here is my simple BS2 code:

[code]’ {$STAMP BS2p}
’ {$PBASIC 2.5}

PULSE VAR Word
PULSE2 VAR Word

Init:
PULSE2 = 1670

MAIN:
FOR PULSE = 2100 TO 1250 STEP 5
PULSOUT 0, PULSE
PULSOUT 1, PULSE2
PULSE2 = PULSE2 + 5
PAUSE 20
NEXT
[/code]

the specification of the 1st servo is pulse 2100 at -90deg and pulse 1250 at 90deg, and the 2nd servo is pulse 2350 at -90deg and pulse 1670 at 90deg.
The code above will make 1st servo run slowly from -90deg to 90deg, however the 2nd servo will run from 90deg to more then -90deg.

I need the 2nd servo to run to -90deg. The servo I use is GWS S-125 Standard 360Deg. Can anyone help me with this?

Thx before…

I have never used a Basic Stamp, but couldn’t you do something like this?

' {$STAMP BS2p}
' {$PBASIC 2.5}

PULSE VAR Word
PULSE2 VAR Word

Init:
PULSE2 = 1670

MAIN:

PULSOUT 0, PULSE
PAUSE 10
PULSOUT 1, PULSE2
PAUSE 10
GOTO MAIN

I have not played with a basic stamp very much, but I do have a few questions.

For example the for loop you go to 2100 to 1250 step 5. Should the step be -5? But assuming this works., you have one servo going from 2100 to 1250 which a difference of 850. The second servo goes from 2350 to 1670 which is a difference of 680.

So if your code goes through the for loop 170 times, then you probably need to adjust how much you change pulse2. My guess is a value of 4 (680/170).

Good Luck
Kurt

Thx kurt for your kind reply…

yes i can do the way you told me, but it will make the pin 0 the pulse to drive the 1st motor 1st, and after the 1st motor finish its rotation, the 2nd motor will move… they won’t run at almost the same time…

BS2 can automatically increment or decrement the counter depending on the initial and final counter… if the initial counter is higher, then it will decrement the counter and vice versa…

yeah, I have tried to change the step so they have the same change in step, but the output was not as expected… there are some delay for the 1st motor to follow the second motor movement…