Pulse Width Modulation

Driving LEDs or Audio Circiuts from a digital source

3208

Pulse Width Modulation

A Pulse Width Modulator (PWM) circuit creates a continuous sequence of pulses, with each pulse staring at a regular interval, and then remaining asserted for a programmable length of time. Each new pulse starts at a regular interval, but the length (or width) of the pulse in each interval can be changed. In any given “pulse window”, the ratio of signal high time to signal low time (or “duty cycle”) determines the information carried by the signal. This digital signal is passed through a simple low-pass filter that integrates the digital waveform to produce an analog voltage proportional to the average pulse width over some interval (the interval is determined by the RC time constant and the pulse frequency).

Figure 1. PWM Signal and Integration
Figure 1. PWM Signal and Integration

PWM signals are useful in many settings: a simple low-pass passive filter (one R and one C) can be used to create an analog voltage; they can directly drive an LED, and the perceived brightness of the LED will be proportional to the pulse high time; they can switch a DC motor’s current on and off to set motor speed; and there are many other uses as well. Digital devices like FPGAs or microprocessors typically use PWM signals to create variable voltage signals that control motor speed, set LED brightness, or define reference voltages for other analog circuits. As shown in the figure below, the PWM output voltage is directly related to duty cycle. For example, a 50% duty cycle PWM signal will generate an output voltage that is 50% of the Vdd input voltage.

Figure 2. PWM Signal Applications
Figure 2. PWM Signal Applications

PWM circuits are often used as simple, inexpensive DACs (Digital to Analog Converters) to create low-to-medium frequency analog voltage signals from a single digital signal. The switching digital waveform can be filtered/integrated with a low-pass filter to remove the higher frequency waveform components that originate from the pulse frequency “carrier” signal. Note the “information” in the PWM pulse train is carried by the pulse widths, and not the pulse frequency (the pulse frequency is just a carrier to communicate the pulse widths, and it is intended to be filtered out). In the case of driving an LED, the higher-frequency information is filtered out by the human eye, and not by an electronic circuit (note the human eye “bioware” can only respond to stimuli up to about 50Hz).

When creating an analog voltage output from a PWM signal, the pulse frequency should be at least 10 times higher than the output filter 3dB frequency (and preferably 100 times higher) to minimize switching noise in the output waveform. As examples, to create an analog voltage that could drive a speaker with up to 10KHz of bandwidth, a pulse frequency of at least 100KHz is required, and 500KHz would be even better. To create a bias voltage on an analog amplifier, a 1KHz pulse frequency could be used together with a 10Hz low-pass filter.

Figure 3. PWM Bandwidth
Figure 3. PWM Bandwidth

LEDs can be used as simple “on/off” devices to indicate the presence of high or low voltage, or they can be driven to different brightness levels. There are two ways to change LED brightness: the current through the LED (or the voltage across the LED circuit) can be changed using an electronic voltage-control circuit; or the LED can be turned off and on at a frequency higher than the human eye can perceive – in this case, the perceived brightness will be proportional to the ratio of “on” versus “off” time. Switching an LED on and off is far simpler and less expensive than an electronic circuit, so that method is most often used.

The human eye can’t respond fast enough see changes that occur above about 60Hz, so an LED driven by a PWM signal with a window frequency above 60Hz will be perceived at a brightness level directly proportional to the PWM duty cycle.

Other than the output frequency, another key PWM specification must be addressed – how many different output signal levels are required? For example, does an LED need just three brightness levels (on, off, and 50%), or more? Does an output voltage need to be driven to one of 16 different levels, or one of 256 different levels? Does an output audio signal need to represent near silence to a whisper, or near silence to a jet engine? All of these examples ask the same question – how many different pulse lengths are required in any given pulse window? Or equivalently, how many different duty cycles must be supported?

The ratio between the largest and smallest values that the information carried by a signal can represent is called the dynamic range of the signal, typically expressed in decibels (dB). As examples, a PWM signal using a 4-bit data word could define 16 different pulse lengths, so the ratio of the largest to smallest output amplitude would be 16/1, or 16. Since log10(16) = 1.2, a 4-bit quantity can represent a signal with a dynamic range of 24 dB (20 x log10(16)). A 5-bit quantity has a dynamic range of 30 dB ((20 x log10(32)), a 6-bit quantity 36dB, and so on – every additional bit represents a doubling of the number of pulse widths, and equivalently, 6 more dB of dynamic range.

So, how much dynamic range does the output of a PWM signal need? That depends on the application. A older telephone might have 48dB of audio dynamic range, equivalent to encoding the signal with 8 bits. Cell phones (and DVD players) typically offer around 96dB, equivalent to encoding the signal with a 16 bits. The human eye may be able to perceive a 36dB change in the brightness level of an LED, equivalent to 5 bits.

A simple block diagram for a PWM circuit is shown. The main counter can be driven from the main system clock, resulting in larger comparators, larger ranges of frequencies and duty cycles, and increased precision. An optimal clock, equal to the pulse frequency multiplied by the number of supported duty cycles could also be used.

Figure 4. PWM Circuit Block Diagram
Figure 4. PWM Circuit Block Diagram

Pulse Density Modulation (PDM)

A Pulse Density Modulator (PDM) circuit is a variation on the PWM circuit, and it works in a similar fashion. Like a PWM circuit, a PDM circuit drives a digital pulse train on a single digital pin, and a low-pass filter integrates the digital signal to produce an analog signal. But in a PDM circuit, the pulse widths are constant, and the period between the pulses change.

A PDM has the advantage of switching more frequently than a PWM circuit. That means the PDM carrier frequency is higher than the PWM carrier frequency, and more information can transported per unit of time. The resulting waveform can have higher bandwidth and/or better characteristics, and a more effective low-pass filter can be constructed. Consider, for example, a PWM with an 8-bit sample (and so 256 different pulse widths). To achieve an analog voltage that is 50% of Vdd, the PWM would have one pulse that terminates at 128 clock cycles, but the PDM would alternate between high and low on every clock. In trade-off, the PDM signal requires more overhead to produce.

Figure 5. PDM signals
Figure 5. PDM signals