SGD | USD

Pulse Width Modulation (PWM): What Is It? How Can I Use It?

Before pulse width modulation (PWM) was developed, the only way to adjust voltage or current for dimming purposes was to use rheostats or potentiometers. Also, controlling larger components such as motors, valves, pumps, hydraulics, and other mechanical components is easier with PWM.

Normally, a DC Voltage stays constant at some value above or below zero. Pulse width modulation turns a digital signal into an analog signal by changing the timing of how long it stays on and off. The term “duty cycle” is used to describe the percentage or ratio of how long it stays on compared to when it turns off. Usually, devices that can produce a PWM output have a very high refresh rate to make sure the average power “looks” constant to a load. I tested the Arduino, for example, with a digital analyzer that read about 500 Hz for a refresh rate. Here is an example of what PWM signals look like; I used LTSpice to simulate the signal and captured a picture of the waveform.

PWM signal generated via LTSpice, a circuit simulation program made by Analog Devices.

I used different voltage levels and put an offset for each signal to show the differences between duty cycles. As you can see, a higher duty cycle means that the signal stays on more than it turns off while the opposite is true for a low duty cycle.

What does this type of signal accomplish exactly? A device capable of PWM will maintain whatever duty cycle a user defines and in some cases a user may program changes in pulse width at any time. Mathematically speaking, the devices capable of PWM change the output so that an “average” voltage is present. A signal set at 50% duty cycle will roughly reduce the average voltage presented to a load by 50%. However, this is not a practical in most cases since devices aren’t 100% accurate. A better measurement to consider would be a root mean square (RMS) measurement. Many multi-meters and other measurement equipment can take RMS measurements. For example, in a simulation on LTSpice, a 5 VDC signal at 50% duty cycle at a 60 Hz refresh rate has an RMS voltage of 3.57 V. I also put a load that typically would draw 1 A with no PWM pulse in the same simulation, it read about 714 mA RMS at 50% duty cycle.

Digital signals tend to stay around 5 V or 3.3 V depending on the application, but it is possible to “duplicate” the effect on larger voltages using MOSFETs. Since these transistors are often used as voltage-controlled switches, they will turn on and off at the same rate as the PWM signal depending on the gate to source voltage. This reaction allows high voltages to look just like the PWM signal and follow the same behavior. PWM is especially helpful in emulating a “dimming” effect on several components. LEDs don’t react very well to potentiometers, especially higher current and voltage LEDs. However, PWM devices in tandem with MOSFETs keep the voltage at a high enough level to keep the LEDs on longer producing a larger dimming range. PWM is also used for controlling speed on motors using the same concept.

If you want to experiment with PWM for the first time, I’d recommend the Arduino platform. The two models I’ve used are: 1050-1024-ND and 1050-1018-ND. The MEGA has more pins capable of PWM output. The Arduino uses an “analogWrite(pin, val)” function to accomplish this, the pin variable is the I/O capable of PWM (has a ~ next to the pin) while the value can be a value from 0 to 255. Zero would be a 0% duty cycle while 255 would be 100% duty cycle.

About this author

Image of Kaleb Kohlhase

Kaleb Kohlhase, Electronics Technician – Digi-Key Applications Engineering Department: Kaleb has worked at Digi-Key since early 2018. His interests include digital logic, programming, circuit simulation, PCB design, 3D modeling, audio circuitry, and more. Kaleb graduated from Minnesota State University in 2017 with a BS in Engineering. His strengths include understanding technical documentation such as circuit diagrams and datasheets, writing technical documentation on researched information, troubleshooting various systems, finalizing concepts by making physical prototypes, and programming in various computer languages. In his free time Kaleb enjoys spending time with his wife watching Netflix, playing video games, biking, swimming, and learning about electronics.

More posts by Kaleb Kohlhase