Skip to content
UPEEC

Timers and PWM

Hardware timers count clock cycles to measure time, create delays, and generate PWM signals.

Easy
Comments 0

A timer counts clock ticks (after a prescaler). Modes: overflow interrupts, compare match (generate events at exact times) and input capture (timestamp an edge to measure frequency or pulse width).

Pulse-width modulation switches a pin rapidly; the duty cycle DD sets the average:

Vavg=D⋅VCCfPWM=fclkprescaler×(TOP+1)V_{avg} = D \cdot V_{CC} \qquad f_{PWM} = \frac{f_{clk}}{\text{prescaler} \times (\text{TOP} + 1)}

PWM controls LED brightness, motor speed and servo position (servos expect a 1–2 ms pulse every 20 ms).

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.