How does a servo work (PWM or PPM)?

I'm trying to get to the bottom of how a servo works.

First of.. I wish to identify the different components of a standard servos. This is how I see it (please correct me if I'm wrong?):

  1. A DC motor
  2. Some gears
  3. A potmeter
  4. A motor controler (also reffered to as a speed controller?)

The motor controller receives a signal (in our case from the Arduino) which tells the servo to move to a specific position. It then reads the current position from the potmeter and determines how much and in which direction the DC motor should be moved and sends an appropiate signal to the DC motor.

Is this correct? Am I missing something? And what kind of signal is sent from the motor controller to the DC motor?

Second..There seems to be a GREAT deal of confusion about whether the signal received by the servo (or rather the motor controller) is PPM or PWM. The following states that it is controlled by PPM signals:

www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232572239

Since the author of this comment (Mem) is the guy who wrote the latest Arduino servo library I'm naturally accepting him as an authority on the matter. However I started a topic on another forum because I'm trying to figure out different ways of sensing servo feedback. Here it is:

letsmakerobots.com/node/10960

Within that thread several seemingly knowledgable people assured me that a servo is indeed controlled by PWM. Here is a quote and a diagram posted in that thread:

PWM, with a fixed frequency of ~20ms. A period of 1.5ms tells the servo circuitry "center". Period of 0.5ms or 2.5ms sends the servo fully CW or CCW.

bansky.net/blog_stuff/images/servo_pulse_width.png

Here is a link to that particular comment:

letsmakerobots.com/node/10960#comment-32515

So.. now I really don't know WHAT to believe?! :-/ Hope some of you smart fellas on this forum can help me clear this up once and for all...

Aniss1001

PS: If anyone has comments regarding the other topic (sensing servo feedback) they're more than welcome to post it here :slight_smile:

I would call it "pulse width modulation", and I think mem's description in the message you reference describes a form of pulse width modulation. The position of the servo is determined by the width of the "on" pulse. If it were a tru PPM scheme, the on pulse would always be the same length, but they would be different times between pulses. (I've read that the actual decoded radio signal is PPM. I dunno.)

However, the "on" time of the pulse is severely limited compared to the PWM that the arduino hardware will normally generate. If you consider the servo position to range from 0 to 100%, the pulse widths involved range from 0.5ms/20ms (2.5%) and 2.5/20 (12.5%) of the total pulse period. (note that the pretty picture of servo pulses you mention is "not to scale." The full right position (2.5ms) is actually only 1/10th of the total period width...) All off (0%) and all on (100%) are not valid inputs. (analogWrite will generate pulses between 0 and 100% for values of 0 to 255)

I don't know what the libraries do. There are several possibilities:

  1. set the period to ~20ms, and map the user-provided values to pulses of 0.5 to 2.5ms. With an 8 bit counter, each count worth of pulse width is about 0.08s, so that's about 25 steps of resolution for the 2ms range of interest. That's not TOO bad. It would work better on the 16-bit counter, if there's a 16bit PWM mode.

  2. Fire the timer with the max period set to ~2.5ms (about 0.01s per count) and the count set to between 50 and 250 (200 steps; plenty) Arrange for this firing to be repeated at appropriate intervals via pushing the responsibility to the user (refresh() function, as I've seen in some servo libraries), or using interrupts tied to some other timer (even the same timer.)

So here are some "scale" pictures. First, a single servo signal:

The large gaps allow multiple servo signals to be multiplexed on a single communications link (eg the radio signal of a radio control set.) You only have to send one actual pulse at any one time, and you have enough room to send about 10 servo signals. I'm pretty sure that this is how the libraries that support very large numbers of servos on Arduino (or similar micro) work. For each timer the chip has, you can easily control up to 10 servos. Since the ATmega168 (and 328) have three (or even 6, depending on how you count), you can control more servos than there are pins. (5 channels are drawn here.)

Hi..And thanks for the reply :slight_smile:

I believe I do understand what PWM (pulse width modulation) and PPM (pulse position modulation) means and how they respectively work.

In short...

PWM: ..has a fixed frequency (for servos: ~20 ms) and variable on-pulse (for servos: 0.5-2.5 ms). The information is contained in the width of the on-pulse.

PPM: ..has a fixed length on-pulse that arrives at different times, referenced to a fixed frequency. How far ahead or behind the fixed time is what is important.

And you're right..the diagrams posted by Mem does indeed seem like PWM. So it confuses me that he says (directly following the diagrams):

This is called Pulse Position Modulation and is not the same as PWM as used in the Arduino analogWrite. PWM (Pulse Width Modulation) varies the ratio of on time to off time to vary the overall signal level and are not suitable for driving a hobby servo.

...And that he starts off with:

You should not use the arduino analogWrite PWM function to drive a hobby servo. They do not use PWM and could damage a servo or speed controller. Its confusing because many references do incorrectly use the term PWM in articles about servos. But hobby servos and speed controllers expect different pulse timings from that provided by analogWrite.

The latter could mean that the Arduino analogWrite PWM works of a different frequency than the PWM used by servos...but I dunno...

Ah..it would seem we were writing simultaniously. I was just very slow :slight_smile:

And thanks again for the info, westfw

The thing about the timers was all news to me. And it may actually prove to be very useful knowledge...

Although it usually doesn't make a lot of difference what something is called, I have been campaigning for years on this forum to avoid calling the servo pulses PWM because analogWrite is the way Arduino produces PWM and driving a servo using Arduino analogWrite can destroy servos.

PWM involves the modulation of a signals duty cycle. In controlling a servo, the duty cycle does not control the position of a servo. Servo position is controlled through modulating the on time of the pulse. Indeed it is possible to control a servo over its full range of movement by changing the on time but keeping the duty cycle constant. If servo control works perfectly well without changing the duty cycle then PWM modulation would not be the most appropriate term for the modulation used.

The terminology is confusing because servo control pulses do involve changing (modulating) the pulse width. And a subset of PWM can be used to emulate the modulation needed to control a servo. But its no more correct to say that this makes the servo signal PWM than it would be to say that an AC (Alternating Current) signal is PWM because PWM is capable of alternating (switching on and off) current. Indeed it is possible to emulate AC using PWM (along with a few passive components) but of course that doesn't mean one should say that AC is PWM modulation.

Choosing the correct terminology for servo signals is complicated by the fact that many smart people (like westfw) do use the term PWM when talking about servos. But the term PWM for servo modulation can [u]confuse people[/u] into thinking that analogWrite is suitable for driving servos, so what should it be called?

It makes sense to use the same termonology used by the people designing and manufacturing RC electronics. And the major manufactures of RC equipment describe this modulation as PPM:
http://www.futaba-rc.com/faq/product-faq.html#q1
http://www.hitecrcd.com/product/comparison_chart/26/Optic_Radio_Chart.pdf
http://www.spektrumrc.com/DSM/Technology/glossary.aspx

Avoiding references to PWM controlling servos should help reduce confusion with the output from analogWrite, so I will continue to evangelize the use of PPM to refer to servo signals.

Thanks a lot for the explanation. I was in fact hoping to get a comment from you.

Your explanation is a bit tecnical so I'll need a bit time to digest it. So just one comment:

You said:

Although it usually doesn't make a lot of difference what something is called..

I must strongly disagree. Establishing a meaningful and COMMON nomenclature is allways a must for being able to communicate properly. Otherwise we end up where: you say tomato - I hear potato :slight_smile:

Aniss

So for now let's consider the PPM/PWM matter closed.

However I'd still very much appreciate some input on the other part:

First of.. I wish to identify the different components of a standard servos. This is how I see it (please correct me if I'm wrong?):

  1. A DC motor
  2. Some gears
  3. A potmeter
  4. A motor controler (also reffered to as a speed controller?)

The motor controller receives a signal (in our case from the Arduino) which tells the servo to move to a specific position. It then reads the current position from the potmeter and determines how much and in which direction the DC motor should be moved and sends an appropiate signal to the DC motor.

Is this correct? Am I missing something? And what kind of signal is sent from the motor controller to the DC motor?

Avoiding references to PWM controlling servos should help reduce confusion with the output from analogWrite, so I will continue to evangelize the use of PPM to refer to servo signals.

And after that battle is won (if ever), maybe we can take on my next biggest complaint with Arduino vocabulary. Why in the world did someone chose the word analogWrite for the function that outputs a PWM output signal? Why was it not properly called pwmWrite?

Yes I know if one, using external components, low pass filters a PWM output signal, one can extract a analog voltage, but I'm sure the confusion and misunderstanding for newcomers to the Arduino world, often just learning hardware and software fundamentals, makes for additional road bumps in their learning curve.

No, Joe, it doesn't really output an analog voltage, but it kind of can, if you do some stuff and don't think too hard about it. :wink:

I recommend that for version 18 they announce that they have decided to eliminate the analogWrite command, but also announce that they will then replace it with a new and improved pwmWrite command. :wink:

Lefty

Hi Lefty,

I think there is a good case for keeping the name analogWrite even though pwmWrite would be more technically correct.

Arduino is primarily aimed at non technical users – people that want to do things with Arduino but are not engineers and are much more interested in the ends than the means.

For tasks like varying the intensity of an LED or moving the pointer of an analog meter, a function named analogWrite is more expressive than the more technically correct term.

I must strongly disagree. Establishing a meaningful and COMMON nomenclature is always a must for being able to communicate properly

Aniss, my point was that it is usually the case that understanding something is much more important than knowing its correct name.

However I'd still very much appreciate some input on the other part:

I would amend your summary on servos as follows:
4) A motor controller (typically an H-bridge)
5) a servo feedback circuit that reads the output position from the pot and drives the motor controller to correct deviation from the commanded position.

Mem and I may have to agree to disagree on the PPM vs PWM debate. I'm pretty sure the PPM references he supplies are talking about the radio side of things, which is not quite the same as the servo side.
I see the servo signal and "duty cycle modulation" as two different sub-cases of PWM, with PPM definitely involving a fixed-width pulse.

  1. A DC motor
  2. Some gears
  3. A potmeter
  4. A motor controler (also reffered to as a speed controller?)

The motor controller receives a signal (in our case from the Arduino) which tells the servo to move to a specific position. It then reads the current position from the potmeter and determines how much and in which direction the DC motor should be moved and sends an appropiate signal to the DC motor.

That sounds pretty close to me. A "speed controller" in the usual sense is a different beast. While some servos may vary the speed of the motor based on the amount of "error" from the desired position, most just generate a (nearly digital) "direction" signal (sign bit of the error, sort of.) that makes the power transistors in the H bridge have an easier job. (hmm. The newer "digital" servos may do a better job here, perhaps even generating PWM to the motor terminals to vary speed. But using transistors in linear analog mode to control motor speed is HARD.)

There was an old linear IC that used to be used in the guts of many servos, and the datasheet had a really good explanation of how the error signal was generated and used to control a motor. But I don't remember the part number, can't find it even in my historical databooks, and web searches are hopeless polluted by explanations of how to generate/use the PWM/PPM signal we've been talking about.

I'm pretty sure the PPM references he supplies are talking about the radio side of things, which is not quite the same as the servo side

They're exactly the same - in the Old Days an R/C receiver's decoder was simply a TTL counter, with the serial pulse stream from the RF connected to the counter's input and an RC circuit attached to the reset pin.
The servo PPM control pulses from the transmitter were sent sequentially in a frame with a long inter-frame gap; the gap was long enough for the RC circuit to trigger the counter's reset and so resync the link.
The output pins of the counter were connected directly to the servo control pins.

There was an old linear IC that used to be used in the guts of many servos, and the datasheet had a really good explanation of how the error signal was generated and used to control a motor. But I don't remember the part number, can't find it even in my historical databooks, and web searches are hopeless polluted by explanations of how to generate/use the PWM/PPM signal we've been talking about.

I think your talking about the Signetics NE544 chip.

Here is a article that has some of the data sheet info for the NE544 embedded.

http://www.seattlerobotics.org/encoder/200009/Servos.html

Put me down for calling it PPM :sunglasses:

Lefty

Hi Mem,

Point understood!

However I've been programming for many years (for fun and professionally) but frankly 6-8 weeks ago I barely knew what a circuit, microcontroller or a servo was. And it's been a very slow and painful process learning about these things. Not least because people use different terms for the same concept OR the same term for different concepts.

In that sense I very much agree with lefty that "analogWrite" should be called "pwmWrite". Simply because that's more correct but MAINLY because the term "analog" is allready reserved for an entirely different concept. The current mixup made it a lot harder (for me atleast) to understand the whole ordeal.

Besides even if 2 persons both understand a given concept it's still difficult to talk about it if they don't share a common nomenclature. If working as a programmer/systems developer has taught me anything it's that nomenclature is important, if not a must, for meaningful communication..

Hope you see my point too :slight_smile:

Thanks again for your input

Aniss

And just one more noob question...

The "servo feedback circuit" (that Mem mentioned) is that the same as/another term for/related to a PID loop/controller?

PS: Regarding PPM vs. PWM: I think I'll just reffer to it as SERVO SIGNALS from now on.. as a guy on the other forum suggested :smiley:

Hope you see my point too

I do see your point about using correct termonology, and if Arduino was primarily aimed at programmers/system developers then I would wholeheartedly agree.

But arduino is a platform intended for artists, designers and hobbyists. And although it is also highly attractive to trained software engineers like you and me, we should to be tolerant to the bending of some technical terms in the interests of making the technology more accessible to non-technical people.

I also take the point about potential confusion over the differences between analog inputs and analog outputs. But whatever you call the output function, the differences between changing the intensity of an LED and reading the intensity of a light source still needs to be adequately explained – things don't get any clearer to the non-technical person by renaming the function pwmWrite.

I can see many reasons why the analogWrite should not be changed to pwmWrite:

  1. (as mentioned in an earlier post) analogWrite is more expressive of the affect when driving things like LEDs. PWM has little or no meaning to non-technical people.

  2. It would increase the likelihood for confusion over its suitability for driving servos (particularly if people persist in referring to servo control signals as PWM).

  3. Even if there was a better name for analogWrite, so much material refers to that name (25,000 hits on google) that changing it would create considerable consternation.

On further thought, I think the main problem with PWM vs PPM is with the "M"; properly speaking, the servo control signal is not "modulated", it is merely "encoded." Especially as used by microcontrollers.

westfw, if you want the most technically correct term and I want the term that causes the least confusion among Arduino users, can we at least agree not to use PWM in relation to servo encoding signals on the grounds that the encoding is not based on modulating the proportion of on time to off time and has nothing to do with the PWM output from analogWrite and the current Arduino servo library does not use hardware PWM to produce the servo pulses.