Shop OBEX P1 Docs P2 Docs Learn Events
Spin continuous servo control — Parallax Forums

Spin continuous servo control

AngeloQAngeloQ Posts: 10
edited 2009-08-17 18:44 in Propeller 1
I'm trying to get two continuous servos working with the sample SPIN code provided on the Parallax site. I'm new to the Propeller and SPIN, but I reviewed the manual and the counter app note, as well as whatever I could find online, but I can't seem to find the problem.

This is what the sample code looks like for one servo, and it works fine:


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

PUB CenterServo | tInc, tc, tCtr, tCw, tCcw, t

ctra[noparse][[/noparse]30..26] := %00100                   ' Configure Counter A to NCO
ctra[noparse][[/noparse]8..0] := 0

frqa := 1
dira[noparse][[/noparse]0]~~


tInc := clkfreq/1_000_000                ' 1 µs increment  
tC   := tInc * 21_500                    ' Low pulse
tCtr := tInc * 1500                      ' Center pulse = 1.5 ms
tCw  := tInc * 1300                      ' Clockwise fast = 1.3 ms
tCcw := tInc * 1700                      ' Counter-Clockwise fast = 1.7 ms
t    := cnt                              ' Mark counter time

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCw                           ' Set up clockwise fast pulse
  t += tC                                ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCtr                          ' Set up the center pulse
  t += (tC + 200)                        ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCcw                          ' Set up counter-clockwise fast pulse
  t += (tC - 200)                        ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)




I added a second servo and I would like to control it from the same cog, so I tried the following:

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

PUB CenterServo | tInc, tc, tCtr, tCw, tCcw, t

ctra[noparse][[/noparse]30..26] := %00100                   ' Configure Counter A to NCO
ctra[noparse][[/noparse]8..0] := 0
frqa := 1
dira[noparse][[/noparse]0]~~

ctrb[noparse][[/noparse]30..26] := %00100                   ' Configure Counter B to NCO
ctrb[noparse][[/noparse]8..0] := 1
frqb := 1
dira[noparse][[/noparse] 1 ]~~                                     ' spaces added for the sake of the forum posting (otherwise it comes out "dira~~")


tInc := clkfreq/1_000_000                ' 1 µs increment  
tC   := tInc * 21_500                    ' Low pulse
tCtr := tInc * 1500                      ' Center pulse = 1.5 ms
tCw  := tInc * 1300                      ' Clockwise fast = 1.3 ms
tCcw := tInc * 1700                      ' Counter-Clockwise fast = 1.7 ms
t    := cnt                              ' Mark counter time

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCw                           ' Set up clockwise fast pulse (motor A)
  phsb := -tCw                           ' Set up clockwise fast pulse (motor B)
  t += tC                                ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCtr                          ' Set up the center pulse (motor A)
  phsb := -tCtr                          ' Set up the center pulse (motor B)
  t += (tC + 200)                        ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)

repeat 100                               ' Repeat PWM signal 100x
  phsa := -tCcw                          ' Set up counter-clockwise fast pulse (motor A)
  phsb := -tCcw                          ' Set up counter-clockwise fast pulse (motor B)
  t += (tC - 200)                        ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)





When the code starts, both motors start turning at the same speed and in the same direction, but then it stops (after around 2s) and doesn't do anything else. It's as if it never gets into the second repeat loop. I thought maybe the extra power draw was causing problems so I looked for transients on a scope but didn't see anything.

I assume this is a code problem, or a lack of understanding on my part.

Any thoughts?

Thanks,
Angelo

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-14 16:08
    I haven't used that method of controlling servos. It is just too easy to use the Servo32v6 object.

    Rich H
  • AngeloQAngeloQ Posts: 10
    edited 2009-08-14 16:50
    Rich,
    Great thanks! That looks good - I will give it a try.

    (I would still love to know what's wrong with what I have, even if I don't use it for servo control - but to clear up my understanding of these counters.)

    Thanks again
  • mparkmpark Posts: 1,305
    edited 2009-08-14 20:44
    AngeloQ said...
    ...
    When the code starts, both motors start turning at the same speed and in the same direction, but then it stops (after around 2s) and doesn't do anything else. It's as if it never gets into the second repeat loop.
    After about 2s, aren't the motors supposed to stop?

    You have a scope; does the prop just stop sending control pulses after 2s?
  • AngeloQAngeloQ Posts: 10
    edited 2009-08-17 06:48
    Yes, sorry it is supposed to stop after 2s, but then after another 2s pause, it is supposed to start again in the opposite direction, which it doesn't do.

    If I use only one motor (even on the second counter) it's OK. I modified it to stagger the shut-off of the two servos and then it would continue.

    So I looked more carefully with the scope and saw a ~15ms dip in the 3.3V supply to the Propeller when both motors stop together. It only dips to about 2.9V, but that's enough to reset the micro. I changed to a different 3.3V regulator and that problem seems to have gone away.

    I looked around from some sample schematics and notes on power management for servos in general, but I haven't seen any special considerations made. Usually it's just a normal 3.3V regulator and a 10uF cap. This is what I started with, and eventually ended up with 100uF which still didn't help. Eventually the new regulator fixed it, but I'm concerned that the design might still be susceptible to occasional resets.

    Any suggestions or tips on designing boards where servos are used?
    Thanks
  • he1957he1957 Posts: 58
    edited 2009-08-17 07:55
    May be a marginal regulator or the filter caps are not large enough to provide voltage carry for the current surge when the (s) motors reverse. Are you powering the servos off the same power rail as the Propeller? What, if any additional switching is in use?

    May be more reliable to use an independent power rail with a higher current rating for them.


    Cheers,

    HarryE.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-08-17 08:22
    If you are using a 4 or 5 cell battery pack (not LiPos) you can (should) power the servos directly, unregulated. Five or six volts is what you want to run the servos at. The signal line will work fine at 3.3 volts. If you need to regulate the servos power I would allow 1 amp or more per servo. If I remember right the Parallax servos draw up to 600 milliamps, larger servos can draw 4 amps or more.

    Rich H
  • AngeloQAngeloQ Posts: 10
    edited 2009-08-17 17:30
    Thanks for your help.

    The Propeller and servos are running off different rails, in the sense they had their own regulators, but both regulators are fed from the same power source. There are no other devices switching.

    The app note for the continuous rotation servo (#900-00008) shows 140+/-50mA under no load, but there is no indication of max stall current.

    This board is designed to fit on the BoeBot, and is normally taking power from the 4 AA batteries. I have two servos fed power through a 7805. I can run the servos directly from the batteries, but I'm worried someone (maybe even me [noparse]:)[/noparse] will plug in a high voltage power supply to the jack. I'm not sure how tolerant those servos are to high voltages on the supply line.
  • photomankcphotomankc Posts: 943
    edited 2009-08-17 18:31
    You're using a 7805? With 4 fresh AA Alk you'd only be at 6V and that's below the dropout on it anyway (1.5 to 2V) so it's no longer regulating it's just dropping your output voltage in proportion to the input and making heat. Even with an low dropout you'd still need input about 0.5V above the output for it to really be regulating. There's gotta be a better way to protect it from over-voltage.
  • AngeloQAngeloQ Posts: 10
    edited 2009-08-17 18:44
    Good point. I didn't realize those had such a high dropout. I'm used to using LDO regulators with <200 millivolt dropout, and honestly I didn't check the spec on the 7805 - just something I had lying around.

    Maybe I'll use a zener.

    Thanks
Sign In or Register to comment.