Unit content
Hardware timers and counters
A hardware timer is a peripheral counter driven by a clock. Instead of spending processor instructions counting time, software configures the counter and lets hardware advance it independently.
A prescaler can divide the input clock before it reaches the counter. If a timer receives clock frequency $f$ through prescaler $P$, one count represents approximately
$$T_{count}=\frac{P}{f}.$$
Timers commonly generate events when the count overflows or matches a programmed compare value. They can also capture the current count when an external edge arrives, allowing pulse widths or periods to be measured.
An event may set a status flag, trigger an interrupt, toggle an output or initiate another hardware action depending on the device.
Hardware timers provide a time base that continues independently of ordinary instruction timing, making them suitable for periodic work, precise delays, waveform generation, scheduling support and timestamping external events.