Skip to main content

Microcontrollers

Section 9.5 Pulse-Width Modulation (PWM)

Pulse-width modulation (PWM) is used to generate digital signals with varying average voltage levels. Instead of outputting an analog value, which is not possible without a digital to analog converter (DAC), a digital pulse with varying frequency and duty cycle is generated.

Subsection 9.5.1 Duty Cycle

The duty cycle (\(D\)) of a square wave is the fraction of time that a signal is HIGH (\(T_{HIGH}\)) compared to the total period of the wave (\(T\)). The duty cycle can be calculated as defined in (9.5.1).
\begin{equation} D = \frac{T_{HIGH}}{T}\tag{9.5.1} \end{equation}
Duty cycle is typically expressed as a percentage. A square wave that is LOW all the time has a duty cycle of 0%, and a square wave that is HIGH all the time has a duty cycle of 100%. Equal HIGH and LOW intervals would result in a duty cycle of 50%.

Subsection 9.5.2 Average Voltage

Modifying the duty cycle of a square wave changes the signalโ€™s average voltage (\(\overline{V}\)). This average voltage can be calculated as defined in (9.5.2), where \(V_{MAX}\) is the maximum signal voltage (usually VCC), and \(V_{MIN}\) is the minimum signal voltage (usually 0ย V).
\begin{equation} \overline{V} = D \times V_{MAX} + (1 - D) \times V_{MIN}\tag{9.5.2} \end{equation}
Figureย 9.5.1 shows five PWM waveforms, all with a period of 20ย ms (frequency of 50ย Hz). Each of the waveforms in Figureย 9.5.1 is described below.
There are 5 graphs of different waveforms plotted with respect to time. Waveform A is OFF all the time. Waveform B is ON for 5 ms and OFF for 15 ms, which repeats 5 times. Waveform C is ON for 10 ms and OFF for 10 ms, which repeats 5 times. Waveform D is ON for 15 ms and OFF for 5 ms, which repeats 5 times. Waveform E is ON all the time.
Figure 9.5.1. Pulse-width modulation waveforms with various duty cycles. The average voltage is indicated with a dashed line.

Subsection 9.5.3 Frequency

The frequency of a PWM wave is equal to the number of complete cycles that occur per unit of time. It is independent of the waveform duty cycle. Figureย 9.5.2 shows waveforms, all with 25% duty cycles, with different frequencies. The frequency of each waveform shown in Figureย 9.5.2 is described below.
There are 4 graphs of different waveforms plotted with respect to time. Waveform A is ON for 1.25 ms and OFF for 3.75 ms, which repeats 20 times. Waveform B is ON for 2.5 ms and OFF for 7.5 ms, which repeats 10 times. Waveform C is ON for 5 ms and OFF for 15 ms, which repeats 5 times. Waveform D is ON for 12.5 ms and OFF for 37.5 ms, which repeats 2 times.
Figure 9.5.2. Pulse-width modulation waveforms with various frequencies. All have a duty cycle of 25%.