Pages: [1] 2   Go Down
Author Topic: How does a servo work (PWM or PPM)?  (Read 19145 times)
0 Members and 1 Guest are viewing this topic.
Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

http://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:

http://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:

Quote
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.



Here is a link to that particular comment:

http://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 smiley
« Last Edit: September 16, 2009, 11:09:46 pm by Aniss » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6364
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
« Last Edit: September 16, 2009, 11:45:49 pm by westfw » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6364
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)

Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi..And thanks for the reply smiley

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):

Quote
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:

Quote
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...
Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah..it would seem we were writing simultaniously. I was just very slow smiley
« Last Edit: September 17, 2009, 01:12:18 am by Aniss » Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
« Last Edit: September 17, 2009, 01:29:13 am by Aniss » Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 confuse people 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.
« Last Edit: September 17, 2009, 04:17:53 am by mem » Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
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 smiley


Aniss
Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 208
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Quote
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?
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16466
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.  smiley-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.  smiley-wink

Lefty
« Last Edit: September 18, 2009, 12:14:28 am by retrolefty » Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 18, 2009, 12:52:11 am by mem » Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.
« Last Edit: September 18, 2009, 12:53:48 am by mem » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6364
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Quote
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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
« Last Edit: September 18, 2009, 02:38:55 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16466
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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  8-)

Lefty
Logged

Pages: [1] 2   Go Up
Jump to: