Shop OBEX P1 Docs P2 Docs Learn Events
Explanation on Servo_32_v7? — Parallax Forums

Explanation on Servo_32_v7?

Circuitbuilder9Circuitbuilder9 Posts: 85
edited 2013-01-19 20:55 in Propeller 1
Hi, all.

I was looking at the assembly code of Servo_32_v7, and i am confused on how the servos can all operate at one time. Any answers? I am really lost on this one.
I want to use this object, but i want to understand how one cog can operate the 32 servos simultaneously, since i want to do a robotics project soon.

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2012-05-06 18:42
    I'm pretty sure that there is an explanation of the theory of operation within the SPIN file.

    It is a solid object. I use it all the time.
  • SRLMSRLM Posts: 5,045
    edited 2012-05-06 19:20
    If it's the same as the PWM_32_v4 object, then it basically calculates the remaining amount of time for each pulse and decides, for each channel, whether it's a 1 or 0. All 32 are then OR'd into a single variable, which is finally sent to OUTA.
  • W9GFOW9GFO Posts: 4,010
    edited 2012-05-06 20:19
    In order to avoid a large current spike, the outputs are driven in staggered blocks of eight.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-06 21:19
    I've read through Servo_32_v7 a bunch of times trying to understand it. I think it works the way SRLM describes (not that I understand it myself) or it's some sort to black magic. I've seen some of Beau's other projects, and it's clear he dabbles in the black arts.

    In case you haven't seen 32 servos being driven at once by a Prop, you ought to check out my 32 servo demo.
  • Circuitbuilder9Circuitbuilder9 Posts: 85
    edited 2012-05-07 11:08
    I understand the concept of the work, but i still don't get how you could, for example, control 32 servos conditionally; doesn't the zone periods cause the servos to have a slight pause before being active under the condition? I am confused mainly about that.

    What causes the servos to act simultaneously (by pin) if they start at time periods after other servos?

    In the object, it is explained that up to 8 servos are operated among 4 different time zones in a 20ms period. The zones confuse me, on how the servos can operate all at once.

    As you can see, i am frustrated about this scenario of simultaneous control.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-07 11:25
    What you have to remember is that a servo just needs to see a control pulse once about every 20ms. Servo_32_v7 issues all of its control pulses within a 20ms cycle, so all of the servos are "happy". As mentioned, the 20ms cycle is divided up into 4 zones to prevent current spikes in case large numbers of servos are told to change position. At most 8 of them will start moving (and drawing current spikes) at once. Functionally, all of the servos would be told to start moving at the same time, but there will be a few milliseconds delay between each group of up to 8.

    Also remember that, because the output register controls all 32 I/O pins, any combination of any number of I/O pins can be changed at the same time with one operation (within a nanosecond or so).
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-05-07 13:33
    Hello Circuitbuilder9,

    Welcome to the forums!!

    As it has been mentioned there are 4 zones of 8 controllable servos within each zone. Each Zone is staggered by a delay 5ms before the next zone is allowed to start. By the time that each zone has had a succession, the total time each zone 'sees' is 5ms, with a repetition rate every 20ms. Within each zone, all 8 servos that are enabled will have their corresponding signal pin go high, and then each servo signal pin will go low in turn depending on if the desired pulse width was reached. After 2ms all of the servo pins should have gone LOW. The remaining 3ms within the Zone are used for processing overhead... updating new values, etc. After a total of 5ms, the next zone is started where all 8 of the servos in that zone that are enabled will have their corresponding pin go high, and thus the process repeats to the next available zone.
  • Circuitbuilder9Circuitbuilder9 Posts: 85
    edited 2012-05-07 16:06
    @Beau : thank you for the explanation, but one question still dawns:

    In the frame of one of the 4 zones, do all the servos have to move the same direction and speed? How can you control the 8 servos differently, as they may have to do different tasks, and not act in the same accord?

    Lastly, Do the zones affect the timing of all the servos, since there is a 5ms zone, and 8 servos in each zone have to go after the first zone?
  • pedwardpedward Posts: 1,642
    edited 2012-05-07 16:25
    IIRC, hobby servos express their angular position as a pulsewidth of 1ms-2ms, with 1.5ms being the center point.

    Beau is saying that since the min pulsewidth is 1ms, he turns on all servos outputs, then based on a scheduler algorithm, he turns off the corresponding outputs at the right time.

    The simplest way to implement this is to have an array of 32 servo commanded values.

    1. Turn on all outputs in the array segment you are working
    2. Scan the segment of the array you are working to find the shortest pulsewidth
    3. Sleep until the pulsewidth expires
    4. Shut off output
    5. Go to 2

    Since there are only 32 pins on the Prop, Beau's code works for that. However, if you had a serial I/O expander, this method of scheduling could probably due a lot more servos, but only to a given resolution in SPIN, you would need PASM to get high enough resolution to serve a lot of servos *AND* have proper angular precision.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-07 18:18
    In the frame of one of the 4 zones, do all the servos have to move the same direction and speed? How can you control the 8 servos differently, as they may have to do different tasks, and not act in the same accord?

    The servos can be controlled individually. As I linked to earlier, I demonstrated driving 32 servos with each servo moving independently from each other.

    There are also several hexapods (including my popsicle stick bot) that have had all 18 servos controlled using this same servo driver.

    As pedward mentioned, with IO expanders, a Propeller could drive even more servos. In this thread Beau shows how to drive 144 servos.
  • jtbrownleejtbrownlee Posts: 9
    edited 2012-12-30 10:32
    If you were controlling 8 servos individually all in one zone(using Servo32 driver), and all the values hit the same number at the same time, wouldn't the actual output length increase 1us for every servo after the first?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-30 10:44
    jtbrownlee wrote: »
    If you were controlling 8 servos individually all in one zone(using Servo32 driver), and all the values hit the same number at the same time, wouldn't the actual output length increase 1us for every servo after the first?

    Short answer, no.
    The servo pulses aren't started or ended one at a time. If all the servos in a zone had the same pulse length, then they'd all be turned on and off together.

    The variable "ServoByte" is adjusted one servo at a time but the line:
    mov     outa,                   ServoByte               '(4 - clocks) Send ServoByte to Zone Port
    

    Is the code that turns on or off the I/O pins. So all eight pins are turned on or off at the same time (assuming identical servo pulses).
  • jtbrownleejtbrownlee Posts: 9
    edited 2012-12-31 13:50
    Ok, I see. Thanks. I have been working on a similar object to the servo32 driver while learning assembly. I am new to posting things to forums. Wondering if I have a useful Idea, should I start a new thread or ask questions here?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-31 14:05
    jtbrownlee wrote: »
    Ok, I see. Thanks. I have been working on a similar object to the servo32 driver while learning assembly. I am new to posting things to forums. Wondering if I have a useful Idea, should I start a new thread or ask questions here?

    Since your idea probably isn't about the original poster's question, I think a new thread is in order.

    BTW, welcome to the forum. I'll be watching for your servo thread.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-01-19 19:08
    Not to try and hijack this thread, I just have a quick question. Are the 32 servos controlled using 2 ea. Servo controllers or has Parallax released a 32 channel controller I am not finding?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-01-19 20:55
    NWCCTV wrote: »
    Not to try and hijack this thread, I just have a quick question. Are the 32 servos controlled using 2 ea. Servo controllers or has Parallax released a 32 channel controller I am not finding?

    Just about any Propeller board that lets you access all 32 I/O pins can be used to drive 32 servos.

    Here's an example of a QuickStart board driving 32 servos.
Sign In or Register to comment.