Shop OBEX P1 Docs P2 Docs Learn Events
Programming Parallax continuous rotation servos?? — Parallax Forums

Programming Parallax continuous rotation servos??

Peter RandPeter Rand Posts: 20
edited 2007-12-11 15:35 in BASIC Stamp
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

  • FranklinFranklin Posts: 4,747
    edited 2007-12-10 18:35
    What have you gotten so far? have you read the "What is a microcontroller" document? What problems are you having? Please be more specific.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-12-10 18:47
    Something like:

    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
  • Peter RandPeter Rand Posts: 20
    edited 2007-12-11 01:05
    Thank you for he help. This is the problem I have been having. This program as you provide, and in the simpler program that follows it below, the servo only rotates according to the first FOR-NEXT loop and stays so rotating. (I can change the direction in that loop and it responds correctly) In both programs therefore it never executes beyond that first FOR-NEXT loop to get to the following ones, so doesn't reverse nor get to an END or stop either. What's going on?



    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-12-11 01:45
    Well, the Servo control signal is a pulse, repeated every 20 mSec. No repeat every 20 mSec, no movement. Your simpler program has lost the 20 mSec delay between repetitions. The pulse needs to be 1 mSec wide (for full left) to 1.5 mSec wide (for 'stop') to 2 mSec wide (for full right).

    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.
  • Peter RandPeter Rand Posts: 20
    edited 2007-12-11 03:02
    Remember this is a continuous servo so the servo's 'comparator' is not working. The movement is continuous. And once started it fits the appropriate PULSOUT I give it, both directions and stop. In any case with repeat every 20 mSec it behaves the same.

    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-12-11 15:35
    No, a 9-volt "transistor" style battery can only provide about 50 milli-amps MAX. A typical servo runs at 100 mA, and up to 500 mA if 'held' while it's trying to turn.

    So yes, a perfectly good 9-volt 'transistor' style battery WILL 'brown out' when the Servo starts up.
Sign In or Register to comment.