Programming Parallax continuous rotation servos??
Peter Rand
Posts: 20
I'm having trouble programmimg these continuous rotation servos. Can anybody help me with something like - "rotate clockwise for a period, stop for a period, rotate ccwise, stop - etc. I want to animate a piece of kinetic art in a more or less random way.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
ServoPin CON 2
ServoPos VAR WORD
MAIN:
· ServoPos = 500·· ' 500 * 2 uSec is rotate full one way
· FOR I = 1 to 100· ' 100 * 20 mSec == 2 seconds
··· GOSUB RotateServo
· NEXT
· ServoPos = 750· ' 'Stop'·value is 1.5 mSec, or 2 uS * 750
· GOSUB RotateServo
· PAUSE 1500· ' 1.5 seconds
· ServoPos = 1000· ' 1000 * 2 uSec is rotate full the other way
· FOR I = 1 to 100· ' 100 * 20 mSec == 2 seconds
··· GOSUB RotateServo
· NEXT
· ServoPos = 750· ' Send 'stop' again
· GOSUB RotateServo
· Pause 500· ' Wait 1/2 second this time...
· GOTO MAIN
RotateServo:
· PULSOUT ServoPin, ServoPos
· PAUSE 20
· RETURN
Post Edited (allanlane5) : 12/10/2007 6:55:32 PM GMT
ServoPin CON 2
ServoPos VAR WORD
I VAR WORD 'had to add this'
MAIN:
ServoPos = 755 ' 500 * 2 uSec is rotate full one way
FOR I = 1 TO 100 ' 100 * 20 mSec == 2 seconds
GOSUB RotateServo
NEXT
ServoPos = 750 ' 'Stop' value is 1.5 mSec, or 2 uS * 750
GOSUB RotateServo
PAUSE 1500 ' 1.5 seconds
ServoPos = 1000 ' 1000 * 2 uSec is rotate full the other way
FOR I = 1 TO 100 ' 100 * 20 mSec == 2 seconds
GOSUB RotateServo
NEXT
ServoPos = 750 ' Send 'stop' again
GOSUB RotateServo
PAUSE 500 ' Wait 1/2 second this time...
GOTO MAIN
RotateServo:
PULSOUT 14, ServoPos
PAUSE 20
RETURN
Or in this simpler program
counter VAR WORD
DEBUG "ccwuse 10",CR
FOR counter = 1 TO 10
PULSOUT 14, 800
PAUSE 200
NEXT
PAUSE 10000
DEBUG "cwise 2", CR
FOR counter = 1 TO 10
PULSOUT 14, 700
PAUSE 200
NEXT
PAUSE 10000
DEBUG"ctr", CR
FOR counter = 1 TO 10
PULSOUT 14, 750
PAUSE 200
NEXT
DEBUG "fin", CR
END
Then, the above programs assume you're using a BS2 'plain'. If you don't HAVE a BS2 'plain', then the "PULSOUT" numbers must be adjusted for the 'flavor' of BS2 you DO have. Otherwise, you won't get the right pulse widths for the servo.
THEN, a servo pulls about 100 mA to 500 mA. You can't do this with a 9-volt battery -- they 'brown out' and your BS2 resets. You MUST use 4 AA batteries or a wall-wart power supply or equivalent if you're going to drive a servo.
I'm using a BS2e and have determined the appropriate pulswidths as above. So thay are OK and do as I expect.
Ah - Do you mean DURING the running of the program the battery browns out - because the battery is OK as tested and runs the beginning of the program again and again? On the oher hand a 9 V battery runs two discontinuous servos perfectly well??
The only thing that appears not to work is getting out of and past the first FOR- NEXT loop.
Many thanks
Post Edited (Peter Rand) : 12/11/2007 2:46:08 PM GMT
So yes, a perfectly good 9-volt 'transistor' style battery WILL 'brown out' when the Servo starts up.