PWM

Using a DAC may seem the obvious way to generate an analog output voltage. But there is another way, using nothing more than a digital I/O line configured as an output. This technique is known as Pulse Width Modulation, or PWM.

Consider the average, garden-variety square wave shown in Figure 12-25.

A ubiquitous square wave

Figure 12-25. A ubiquitous square wave

The width of the high is equal to the width of the low, so this wave is said to have a 50% duty cycle. In other words, it is high for exactly half the cycle. Now, if the amplitude of this square wave is 5V, for example, the average voltage over the cycle is 2.5V. It is as though we had a constant voltage of 2.5V.

Now consider the square wave in Figure 12-26.

10% duty cycle

Figure 12-26. 10% duty cycle

This wave has a 10% duty cycle, which means that the average voltage over the cycle is 0.5V.

A low-pass (averaging) filter on the PWM output will convert the pulses to an analog voltage, proportional to the duty cycle of the PWM signal. By varying the duty cycle, we can vary the analog voltage. Hey, presto!—we have digital-to-analog conversion without a DAC. That’s the basic idea behind PWM.

Tip

PWM can also be used to drive a LED and thereby get varying light intensities from a signal that is essentially either on or off. PWM can also be used to generate audio. Early desktop computers, such as the Apple ][, used PWM to drive a speaker. Steve Wozniak, the designer of the Apple ][, used a spare chip select of the address decoder as his PWM signal. By changing how frequently a particular address was accessed, he was able to change the frequency and duty cycle of his PWM signal and was therefore able to generate simple audio with varying volume and pitch. Sound out of an address decoder!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.125.139