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.

Bottom lineA free-running counter peripheral that keeps time independently of the CPU's instruction execution.

Breaking it down

What a hardware timer providesA free-running counter, incrementing on its ownA configurable rate (via a prescaler)An action on reaching a target: interrupt, PWM edge, or both
What a hardware timer provides

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

A simulated timer tick counterC: edit and run

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

Running two simulated timers side by sideC: edit and run

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?