Understanding PWM

PWM stands for Pulse Width Modulation and it basically means precisely that. You have a pulse, and if you can change the width of the pulse without changing the frequency, then you have modulated its width. Lets first take a look at what a pulse is, because for motion control purposes, it is very important to understand this very simple concept.

PWM Basics

A pulse is an electric signal whose presence is not indefinitely long. A pulse has a beginning an and end and the time from beginning to end can be measured. In essence everything is a pulse since everything has a beginning and an end, but lets assume that these pulses have a finite length in time which is considerably lower than other measurements. Per example, when you turn your computer on and then OFF in a matter of three hours, the pulse of energy that the computer consumed is 3 hours long. The pulses we will concern ourselves with are considerably shorter than this. In fact, they are way shorter than a second.

That being said, a pulse has a finite length in time and that is what we called its TIME ON. How long was the electrical signal present. Once the electric signal is removed and until the signal is applied again, is called the TIME OFF. If the electric signal changes to ON and OFF with continuous and equal intervals of TIME ON and TIME OFF, we say the pulse is periodic and its period is equal to the amount of time the electric signal was present (TIME ON) plus the amount of time the electric signal was not present (TIME OFF).

NOTE: Most of the time when we deal with PWM, we want the PERIOD to remain constant.

Another electrical measurement you may have heard about is the frequency. Frequency is how many times, on a per second basis, something happens. In other words, how many times did the pulse went ON and OFF on any given second. Taking the inverse of the PERIOD gives us the frequency. Frequency is vital understand as the system receiving the PWM signal will most likely be tolerant of a particular frequency. Slower or faster frequencies may not work or simply have undesired results as we shall see later.

We are now ready to fully understand what PWM is. A pulse is generated on a continuous basis, but we change the amount of time the electric signal was ON. Notice that if the PERIOD remains constant any change in TIME ON must also result in a change of TIME OFF. This is very important as well, as it gives us the measurement of Duty Cycle (DC%), which is the percentage of how much time was the electric signal versus how long it was OFF. The rule of thumb is that as the amount of TIME ON increases so does the DC%.

RC PWM 

Most people are familiar with the way in which professional remote control toys (such as cars, airplanes, helicopters, boats and now robots) are controlled through a signal referred to as PWM. I like to call this RC PWM as it is very different to the PWM signal used to control DC Motor speed. It is very important that we understand the difference as most remote control robot projects will in fact use both forms of PWM. We often use a radio transmitter which sends an RC PWM signal to an RC Receiver. The receiver decomposes the received signal into a series of RC PWM signals, one per channel. If your RC system is 5 channels, you will get 5 PWM outputs. Each one of these RC PWM signals controls the position of one RC Servo.

Transmitter Receiver

 

Here is why I like to make the distinction between RC PWM and other forms of PWM. The RC PWM signal is only meaningful to RC based systems and it basically contains position information. The width of the pulse only offers position information. We can of course utilize this information to control whatever we want (intensity of lights, DC motor speed, rate of rotation of a stepper motor, etc.) I have done a lot of stuff with the RC PWM signal, but bottom line is that this signal can only be used to send information. We will see later, that when controlling a DC motor, it is amount of energy what we need, and not information. But let see what kind of information we are talking about.

Servo RC PWM

RC Servos has been designed to accept the RC PWM signal which is nothing more than a periodic pulse with a width of anything between 1.0 ms and 2.0 ms. Some systems with more resolution will have allow for pulses in the range of 0.5 ms to 2.5 ms. However, 1 ms to 2 ms is pretty much standard. The idea behind this position protocol is that 1.5 ms commands the servo to go to the center position. A 1.0 ms pulse commands the motor to attempt to reach its leftmost position and 2.0 ms to its rightmost position. Any pulse measuring in between 1.0 ms and 2.0 ms is decoded as a position in between leftmost and rightmost. Since the remote control is analog, practically any position can be attained.

It is very easy to generate an RC PWM signal using a micro controller or any other digital contraption. When this is done, the positions available are dependent on the timer resolution. Per example, it is possible that a pulse can only have 256 steps between 1 ms and 2 ms pulse width. Even then, 256 positions are more than enough for any fair control application. The motor itself is not as precise as to be adversely affected by this lack of infinite resolution.

DC Motor Speed Control PWM

The user may feel that the RC PWM signal may be an awesome resource to control the speed of a DC motor. And this is of course true, except that the RC PWM signal itself is pretty much useless as a direct means of controlling the DC motor speed. What needs to be done is to have an intermediate circuit to decode the position information (RC Pulse width) and generate a speed magnitude signal. In other words, if the input pulse is 1 ms, move the DC motor on reverse at maximum speed, if 1.5 ms wide stop the DC motor and if 2.0 ms, move the DC motor forward at maximum speed. Any other pulse width is then decoded to partial speed on the corresponding direction.

But how do we control speed on a DC motor? There are many ways as I have depicted before on this blog, but my favorite is with an H Bridge. As it may confuse the reader, an H Bridge utilizes PWM, as well, in order to control DC motor speed!!! However, the PWM we use to control the speed is totally different than the RC PWM signal we had been discussing previously.

Like I explained previously, the RC Servo signal encodes position on the pulse width. Notice the important aspect of the RC PWM is the TIME ON and how long this is. Any TIME ON with widths between 1.0 ms and 2.0 ms are useful. TIME OFF and Duty Cycle are of no concern. This is not true about DC Speed Control.

As it turns out, on an H Bridge, the Duty Cycle will be directly proportional to the resulting voltage applied into the load. And on a DC Motor, voltage applied is directly proportional to motor speed.

The best way to see this is to realize that with an H Bridge, TIME ON actually means the motor is ON, whereas TIME OFF actually means the motor is OFF. So imagine you are applying 12V to  your H Bridge, but the H Bridge is ON only half of the time. In other words, the motor is ON for 1 ms and then OFF for another 1 ms. To the eyes of the motor, this is pretty much identical to having 6V instead.

On the figure below I am trying to portray how speed varies by changing PWM Duty Cycle. The H Bridge is chopping the amount of time the motor is receiving energy. By varying Duty Cycle, we have an infinite amount of voltages to apply to the motor, which then results in an infinite DC motor speeds ranging from stopped to running at full speed.

Speed vs PWM DC%

 

I demonstrate this concept on my DC Motor Basics Part I blog. Feel free to check the video and notice how the motor speed instantaneously changes as the PWM DC% is modified. For that experiment I used my AE-MDL-DC1 and an MSP430 micro controller to supply a synthesized 32 KHz 8 bit PWM signal.

14 comments for “Understanding PWM

Leave a Reply to Yacob Hassidim Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.