Shop OBEX P1 Docs P2 Docs Learn Events
Servos and Propeller — Parallax Forums

Servos and Propeller

HoffaHoffa Posts: 46
edited 2007-03-02 15:19 in Propeller 1
Hi

I have a parallax servo. Earlier I have used basic stamp to control that servo using:

pulsout servo, NUMBER (750 for neutral)
pause 20

How can I do the same thing in Propeller?

Comments

  • inserviinservi Posts: 113
    edited 2007-02-27 10:31
    Hello,

    Simply use the objects available in the Propeller Object Exchange as "Servo-4" or "Servo32_Demo V1.2"

    Is there samples for easy understand.

    Best regards,
    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • Bryan K.Bryan K. Posts: 47
    edited 2007-03-01 19:56
    i have successfully driven the parallax servos by generating the pulse in its own cog, changing the time high pulse to change the speed of the servo. This can be done directly from the pin (with a resistor from the prop to the signal pin on the servo). Here is the code I used in generating the signal. However, the program deals with the pulse width in clock pulses, rather than a straight PWM signal.

    ''****************************
    ''* Basic servo postitioning *
    ''****************************

    ''This code uses the main cog, or a new cog to toggle a pin to produce the 1.5ms pulse to run a positioning servo or a continuous rotation servo motor
    ''compiled and buile by Bryan K.

    ''Servo pinout to Prop:
    '' black = ground
    '' red = 5 volts
    '' white = signal coupled to a 1 k resistor to prop pin

    ''7_500 is the theoretical center
    ''9_000 is full direction 1
    ''5_000 is full reverse direction
    ''these values are different for each servo.

    CON
    _clkmode = xtal1
    _xinfreq = 5_000_000
    servopin = 15

    VAR

    long pulse 'change this value to change the pulse duration

    PUB Servo
    pulse := 7_500

    dira[noparse][[/noparse]servopin]~~
    outa[noparse][[/noparse]servopin]:=0
    Repeat
    !outa[noparse][[/noparse]servopin]
    waitcnt(pulse + cnt) ' High time
    !outa[noparse][[/noparse]servopin]
    waitcnt(120_000 + cnt) ' Low time
  • Stan671Stan671 Posts: 103
    edited 2007-03-01 22:22
    Bryan, I am working on similar stuff using Servo_4 from the Object Exchange as a basis to run pulse streams to operate 4 continous rotation servos at the same time.· I looked over your program and have some questions.

    1. You have
    _clkmode = xtal1

    Why not use

    _clkmode· = xtal1 + pll16x

    and run your Propeller at 80 MHz?· Of course, you would need to increase your timing values 16 times.

    2. Using your method, you have a fixed pulse low time of 24 ms always.· Therefore, the total width of high and low times will vary with the high time.· Wouldn't it be better to subtract the high time from the maximum low time so that the pulses are at a fixed frequency?· Also, I though 20 ms between pulses was·recommended for servos.· How about:

    ' timing values based on 5 MHz clock and no multiplier as in original example
     
    dira[noparse][[/noparse] servopin ]~~
    outa[noparse][[/noparse] servopin ] := 0
    pulse := 7_500
     
    Repeat  !outa[noparse][[/noparse] servopin ] 
      waitcnt( pulse + cnt ) ' High time
      !outa[noparse][[/noparse] servopin ] 
      waitcnt( [color=red]100_000 - pulse[/color] + cnt) ' Low time
    




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski
  • rokickirokicki Posts: 1,000
    edited 2007-03-01 22:33
    You'll get more accuracy if you don't keep reading cnt over and over again.

    For instance:

    var long speed ; ' shared variable with the speed to set; in cycles
    pub drive(pin) | ontime, cyctime, hictr, loctr
       dira[noparse][[/noparse] pin ] := 1
       cyctime := clkfreq / 50 ; ' update rate is 50 Hz
       loctr := cnt
       repeat
          ' do arithmetic during low time
          loctr := loctr + cyctime
          hictr := loctr - speed
          waitcnt(hictr)
          outa[noparse][[/noparse] pin ] := 1
          waitcnt(loctr)
          outa[noparse][[/noparse] pin ] := 0
    
    



    This should be accurate to the clock cycle time (12.5ns at 80MHz).
  • edited 2007-03-01 22:35
    Hi Hoffa... I am using the Servo32.Spin to control 18 servos on a Hexapod.... the Servo32 object is super simple to use, and the servo behavior is really smooth... you can configure the minimum and maximum pulse width, and even the frecuency the pulses are sent.... reallly neat...

    here is the details of my project..

    http://forums.parallax.com/forums/default.aspx?f=25&m=161756

    I hope this helps...
  • Stan671Stan671 Posts: 103
    edited 2007-03-01 23:42
    rokicki said...
    You'll get more accuracy if you don't keep reading cnt over and over again.
    Yes.· That is the way Servo_4 does it.· By·pre-calculating absolute positions to compare against cnt (with the waitcnt function), this removes the time loses·running the code·of the program.· I have observed the pulse train on the oscilliscope and it is rock steady.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski
  • Bryan K.Bryan K. Posts: 47
    edited 2007-03-02 15:19
    Stan671, Thanks for the info, I have tried operating at 80 MHz, but the counts all have to be adjusted. I like the simplified code. How were you able to interface using the servo-4 object?
Sign In or Register to comment.