Pulse Width Modulation

1 min read Last updated Fri Jun 12 2026 02:12:51 GMT+0000 (Coordinated Universal Time)

PWM encodes a value in a digital square wave by varying the fraction of time the signal is HIGH. Frequency stays fixed. Duty cycle varies.

  • Cycle time (TT)
    Total duration of 1 period.
  • On-time (tont_{on})
    Portion of each cycle the signal is HIGH.
Duty Cycle=tonT\text{Duty Cycle} = \frac{t_{on}}{T}

The time-averaged voltage:

Vˉ=Vsupply×Duty Cycle\bar{V} = V_{supply} \times \text{Duty Cycle}

An MCU timer increments a counter at a fixed clock rate. A compare register holds the duty value. The output goes HIGH at counter reset and LOW at compare match.

An nn-bit timer provides 2n2^n duty cycle steps.

Applications:

  • Motor speed control
    Average voltage controls rotational speed.
  • LED brightness
    Perceived brightness tracks duty cycle.
  • Servo position
    Pulse width (1–2 ms within a 20 ms period) encodes angle.
  • Buzzer tone
    PWM frequency sets audible pitch.

Simulated Analog Output

A low-pass RC filter on a PWM signal removes the switching component, leaving a DC level equal to Vˉ\bar{V}.

Filter cutoff must be far below the PWM frequency. Higher PWM frequency reduces ripple for the same filter. Output accuracy is limited by PWM resolution and filter tolerances.

Was this helpful?