Shop OBEX P1 Docs P2 Docs Learn Events
Continuous Rotation Servo — Parallax Forums

Continuous Rotation Servo

jessicajessica Posts: 8
edited 2009-10-04 07:58 in Propeller 1
Hello everybody

I'm new to this forum, my name is jessica. I live in France and I'm interested in robotics.

I'm studying servo right now with the parallax usb oscilloscope and I have a question about this spin code
found on #900-00008-CRservo pdf:

ServoRotation.spin
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
  [b][u]t += tC[/u][/b]                                ' 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
  [b][u]t += (tC + 200)[/u][/b]                        ' 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
  [u][b]t += (tC - 200)[/b][/u]                        ' Calculate next cycle repeat
  waitcnt(t)                             ' Wait for next cycle (20 ms)


I don't understand why we have to add and subtract 200 (see bold underlined code) ?

I can't see any difference with the scope (even zooming) if I use the three times:

t += tC 


Can someone explain this to me ?
Thanks for your help and understanding.
jessica

Comments

  • simonlsimonl Posts: 866
    edited 2009-10-01 21:51
    Hi Jessica, and welcome.

    I'm not totally sure, but it looks like the code is first turning the servo clockwise increasing speed (+200), then counter-clockwise, decreasing speed.

    I could be wrong tho'!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2009-10-01 22:18
    Hi Jessica!
    Welcome to the forum smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Where am I? Where am I going? Why am I in a handbasket?"
  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-10-01 22:52
    I can not figure out why they did it. 200 ticks is only 2.5 usec and all other times are msec. To control servos (standard or continuous) I use servo23v7 from the object exchange. PWM_32_v2 will also support servos and do other PWM functions at the same time.

    John Abshier
  • mparkmpark Posts: 1,305
    edited 2009-10-01 23:10
    Maybe they meant 200 * tInc, which would be 0.2ms. It looks like they want to compensate for the 0.2ms difference between CW/center/CCW pulse lengths so that the loop period remains constant, but the code is wrong.
  • KyeKye Posts: 2,200
    edited 2009-10-02 00:02
    Use the dual servo controller driver posted up in the obex. Its much easier to use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • jessicajessica Posts: 8
    edited 2009-10-04 07:58
    Thanks for your help!
    I picked up the servo32v7 object and it works fine with CR servo.

    But I have problems using standard servo ...
    I'll try to search in the forum
Sign In or Register to comment.