Home / Learn Embedded C / What Is a Hardware Timer?
What Is a Hardware Timer?
A free-running counter peripheral that keeps time independently of the CPU's instruction execution.
Breaking it down
What it is
A hardware timer is a peripheral that counts clock ticks on its own, in the background, independently of whatever instructions the CPU happens to be executing — letting firmware measure time or generate periodic events without busy-waiting.
Why it matters
Busy-wait delays (a loop that just counts) waste CPU time that could otherwise do useful work, and their timing is imprecise and chip-speed-dependent — a hardware timer solves both problems.
Mechanically speaking
A timer has a counter register that increments every clock tick (or every N ticks, via a prescaler), and can trigger an interrupt or action when it reaches a target value — covered across this whole group.
Shows up in
- Precise delays
- Periodic events
- PWM generation
Try it
TIMER_TICK is this course's sandbox stand-in for a hardware timer incrementing on its own.
Try it: two independent timers ticking at different rates
Real chips usually have several independent timer peripherals, each counting at its own configured rate at the same time.
Check yourself
1. What is the main advantage of a hardware timer over a busy-wait delay loop?
A busy-wait loop blocks the CPU and its timing varies with clock speed and compiler optimization; a hardware timer runs independently with precise timing.