PDA

View Full Version : Servo help



haunteddansion
02-02-2007, 12:10 PM
I am using the Prop-1 and trying to make 2 servos spin to half way then wait for 15 seconds and then spin back to 0 again. How would this look

Mike Green
02-02-2007, 12:21 PM
What have you done so far? What do you understand about the Stamp 1? Do you understand how servos work?

Typically, a servo expects a pulse approximately every 20ms with a width between 1ms and 2ms with 1ms representing one end of the range of movement and 2ms representing the other end. With 2 servos, you could put out 2 separate pulses of differing widths if you want, as long as the pulses occur at least every 20ms. With the BS1, you would use a PULSOUT statement for each servo with the period (in 10us units) either 1ms or 1.5ms (for the two positions). You may have to adjust these pulse widths to get the movement you want, but this is a good starting point. After sending the two pulses, you'd need a PAUSE of maybe 16-18ms, then repeat. A wait of about 15 seconds would be 50*15=750 cycles approximately (you can adjust that as needed).

If you haven't looked at it yet, you should get a download copy of "What's a Microcontroller?" from Parallax's website.

haunteddansion
02-02-2007, 12:35 PM
I have used servos and the stamp before. But makeing a servo move spin to half way then wait and then spin back to 0 again is something I have really never gotten a straight answer on. I am a visual learner, what would a code look like, to help me get started. Thanks for the help

AIman
02-02-2007, 12:44 PM
This is a basic outline of code for you to follow. You will need to adjust the values for your servo, on mine this is a max side to side turn (180).


COUNTER VAR Word

DO
FOR COUNTER = 1 TO 150 STEP 10
PULSOUT 12, 1100
PAUSE 20
NEXT

FOR COUNTER = 1 TO 150 STEP 10
PULSOUT 12, 250
PAUSE 20
NEXT

LOOP

Mike Green
02-02-2007, 01:06 PM
For 2 servos, you'd just add a second PULSOUT to each loop and shorten the PAUSE slightly to compensate. Again, for 15 seconds approximately, you'd want the first loop to execute about 750 times (roughly). The second loop should execute until you're ready to start over again like:


COUNTER VAR Word

FOR COUNTER = 1 TO 750 ' this should take about 15 seconds
PULSOUT 12, 150 ' 150 * 10us = 1.5ms (adjust as needed)
PULSOUT 13, 150 ' the same (or different) value
PAUSE 18
NEXT
DO ' *** repeat forever ***
PULSOUT 12, 100 ' 100 * 10us = 1.0ms (adjust as needed)
PULSOUT 13, 100 ' the same (or different) value
PAUSE 18
LOOP

haunteddansion
02-03-2007, 02:09 AM
I cant get the program to work with the " COUNTER VAR word command in the beginning, isnt that supposed to be B1 or some syntax, how should I change this to make the program work? Thanks soo much

Mike Green
02-03-2007, 02:18 AM
Sorry, I used a BS2 format statement. For the BS1 (and Prop-1) use "SYMBOL COUNTER = W5".