Shop OBEX P1 Docs P2 Docs Learn Events
Newbie servo control question — Parallax Forums

Newbie servo control question

Daniel Lloyd-WoodDaniel Lloyd-Wood Posts: 14
edited 2009-02-15 13:24 in Propeller 1
Hello,

I've got a PE USB kit. I've been through all the labs in the PE Fundamentals Book and am now stepping out on my own and starting to play around. I am currently trying to control a servo with the Propeller. The code I'm using is pinched for the Fundamentals book and is as follows:


CON
_clkmode = xtal1 + pll16x        ' System clock → 80 MHz
_xinfreq = 5_000_000

PUB TestPwm | tc, tHa, t
ctra[noparse][[/noparse]30..26] := %00100           ' Configure Counter A to NCO
ctra[noparse][[/noparse]8..0] := 24
frqa := 1
dira[noparse][[/noparse]24]~~

tC := 1_600_000                    ' Set up cycle time for 20ms
tHa := 120_000                     ' Set up high time for 1.5ms
t := cnt                                 ' Mark counter time

repeat                                  ' Repeat PWM signal
  phsa := -tHa                       ' Set up the pulse
  t += tC                               ' Calculate next cycle repeat
  waitcnt(t)                            ' Wait for next cycle





The servo I am using is the Hitec HS-65MG:

-90o - 600 usec
-45o - 1050 usec
0o - 1500 usec
45o - 1950 usec
90o - 2400 usec

The code runs fine. The problem is even though the pulse is sent continuously once the repeat loop is entered the sero only moves slightly towrards centre then stops. I have to repeat the program again to get the servo to move a bit further. I have to keep doing this until the servo reaches centre and then it stays in the centre as it should. Is it the servo causing this or something I've missed in the code?

Thanks,

Dan

Comments

  • virtuPICvirtuPIC Posts: 193
    edited 2009-02-13 11:39
    Newbie servor anser... What about signal voltage? Propeller gives thre point something volts for logical high. This is okay for CMOS and TTL inputs according to SN74xx datasheets. However, I don't know what's used in the servo anw would suspect that they need more.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • Daniel Lloyd-WoodDaniel Lloyd-Wood Posts: 14
    edited 2009-02-13 12:34
    Thanks for the fast response!

    I found these details about the servo:
    http://www.servocity.com/html/hs-65mg_mighty_feather.html said...

    Control System: +Pulse Width Control 1500usec Neutral
    Required Pulse: 3-5 Volt Peak to Peak Square Wave
    Operating Voltage: 4.8-6.0 Volts
    Operating Temperature Range: -20 to +60 Degree C
    Operating Speed (4.8V): 0.14sec/60° at no load
    Operating Speed (6.0V): 0.11sec/60° at no load
    Stall Torque (4.8V): 25 oz/in. (1.8kg.cm)
    Stall Torque (6.0V): 31 oz/in. (2.2kg.cm)
    Operating Angle: 45 Deg. one side pulse traveling 400usec
    360 Modifiable: No
    Direction: Clockwise/Pulse Traveling 1500 to 1900usec
    Current Drain (4.8V): 5.3mA/idle and 400mA no load operating
    Current Drain (6.0V): 6.6mA/idle and 500mA no load operating
    Dead Band Width: 4usec
    Motor Type: 3-Pole Neodynium Magnet
    Potentiometer Drive: Indirect Drive
    Bearing Type: Top Ball Bearing
    Gear Type: Karbonite Gears
    Connector Wire Length: 6" (150mm)
    Dimensions: 0.92" x 0.45"x 0.94" (23.6 x 11.6 x 24mm)
    Weight: .39oz. (11.2g)

    Required Pulse: 3-5 Volt Peak to Peak Square Wave - Do you think this means it requires a 3V low, 5V high signal or anywhere between 3V-5V is counted as high and the low is 0V?
  • virtuPICvirtuPIC Posts: 193
    edited 2009-02-13 14:33
    Somebody said...
    Required Pulse: 3-5 Volt Peak to Peak Square Wave - Do you think this means it requires a 3V low, 5V high signal or anywhere between 3V-5V is counted as high and the low is 0V?

    '3-5 V Peak to Peak Square Wave' means that the difference between high level and low level should be 3 V to 5 V. As a MOS circuit the prop should be able to deliver 3 V peak to peak output when powered with 3.3 V if there is no load at the output. The transistor in the prop driving the pin, the connectino to the servo, as well as the input of the servo have certain resistances which form a voltage divider. If you can get an oscilloscope watch the signal. Or just give it a try and build a simple level converter from a few discrete parts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • ratronicratronic Posts: 1,451
    edited 2009-02-13 17:18
    How are you powering your servo and prop chip?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Fix it, if it ain't broke·
    D Rat


    Dave Ratcliff· N6YEE
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-02-13 17:32
    If you are able to just run the program multiple times to get the servo to the desired location, couldn't you just put the whole (or at least the output part of the) program in a loop?
    I don't think that is a answer you are looking for, but it may work.

    I'm not too familiar with CTRs, I usually end up programming 20 lines of code that CTR could do in 3, but then at least I understand exactly what is happening. So I'm sure someone else can give a little more insightful input.

    The fact that the servo is moving at all would make me think that the pulse's voltage is high enough. And an oscilloscope would help the process out a bit to make sure that the output frequencies are good.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-02-13 19:28
    How are you powering the servo and prop? Are the grounds tied together? If they're both supplied from the same source, do you have a decent sized capacitor on the servo power line to buffer the power spike when the motor starts? You could be resetting the propeller if not. Is the power supply for the servo 5v?

    I'm not familiar with the operation of the timers, so I can't comment on that part.

    Jason
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2009-02-14 01:09
    Daniel Lloyd-Wood,

    I tried your code, and it is supplying the correct pulse. (See attached image)

    As far as the 3V to 5V, I believe it has been answered, but it simply means that the Servo will accept a signal as a logic level "1" or HIGH from 3V to 5V.
    This does not mean that the servo itself should be powered from a 3V to 5V supply. According to your data, it will need at least 4.8V.

    The Propeller provides a 3.3V output under the load conditions that would be demanded of it from a servo.

    As others have asked, what does your power supply to the Servo(s) look like and are you sharing the Ground connection (VSS) between the Propeller and your Servo?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    2304 x 1728 - 628K
  • Daniel Lloyd-WoodDaniel Lloyd-Wood Posts: 14
    edited 2009-02-15 13:24
    Hello all,

    Thanks for all the suggestions. I've tried a few things out and it looks like the power drain caused by the·servo operating was the culprit. This·was reseting the Prop. I've set up a separate power supply for the servo and everything·is working fine now.

    Thanks again,

    Dan·
Sign In or Register to comment.