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 ()
Total duration of 1 period. - On-time ()
Portion of each cycle the signal is HIGH.
The time-averaged voltage:
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 -bit timer provides 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 .
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.