Pulse Width Modulation

Pulse Width Modulation (PWM) is a way for a digital device to output a pseudo-analog signal.

For example, a 5v microcontroller can either output a 0v (low), or a 5v (high) signal. But if you need to output something in between, PWM is the way to do this. A true analog signal may be generated by passing the PWM output through a filter capacitor, the size of which is dependent upon the switching frequency. This will lessen the effect of the characteristic PWM spikes and smooth out the overall signal.

The microcontroller can pulse (very quickly) between 5v and 0v so that the average is somewhere between 0 and 5v. Changing the Duty Cycle, or ratio of "on" time to "off" time, is how the average output can be varied. For example, a 50% duty cycle (a square wave) in this instance would yield 2.5v, a 20% duty cycle would yield 1v, and so on.

A PWM signal could also be achieved by using a 555 Timer for smaller projects.

The effectiveness of a PWM system is closely tied to its switching frequency. If used to control brightness of an LED, the system needs to switch only fast enough to negate the visible "flicker" effect of pulsing the LED on and off. Usually a few hundred Hertz (pulses/second) is more than sufficient to fool the human eye. For audio systems it is necessary to switch at much higher frequencies, as the human ear can pick up frequencies on the order of 20kHz (20,000 pulses/sec). If the PWM cycle is slower than 20kHz, the distortion will be audible. Technically an audio system should use a PWM frequency of at least 40kHz to satisfy the Nyquist criterion.

Conversely, ovens and other climate control systems designed around a simple relay-driven heating element may give acceptable performance with a very low switching frequency.

PWM is used widely in Industrial Automation and Motion Control systems. Through the use of transistor circuits, a low-power 5V microcontroller output may be used to control the speed and torque of very high power systems.