Home / Learn Embedded C / Busy-Wait Delay vs Timer Delay

Busy-Wait Delay vs Timer Delay

Comparing the two common ways to make embedded code "wait", and when each is appropriate.

Quick summaryComparing the two common ways to make embedded code "wait", and when each is appropriate.

How to think about this

Busy-wait vs timer delayBusy-wait delayBlocks the CPU entirelySimple to write, fine forquick demosTimer delayCPU free to do other work orsleepNeeded once more than onething must happen at once
Busy-wait vs timer delay

In plain terms

A busy-wait delay blocks the CPU in a counting loop doing nothing useful until time passes; a timer-based delay lets a hardware timer track the time while the CPU is free to do other work (or sleep) in the meantime.

Why we use it

Simple scripts and quick demos often use busy-wait for simplicity; real production firmware almost always prefers timer-based delays (or full event-driven designs) once more than one thing needs to happen "at the same time".

Under the hood

A busy-wait delay's accuracy depends on the compiler, optimization level and clock speed unless carefully calibrated; a hardware timer's accuracy depends only on the clock source feeding it, which is far more predictable.

Real-world use

  • Delay implementation choice
  • Responsiveness-critical code
  • Power-sensitive designs

Try it

Comparing the two mental models, in print formC: edit and run

This course's DELAY_MS/DELAY_US calls are meant to represent the timer-delay model, even in examples that read like simple blocking calls.

Try it: a busy-wait loop that actually blocks other work from happening

Showing how a busy-wait delay starves a second taskC: edit and run

Nothing else in the program can run while the CPU is stuck counting inside the busy-wait loop.

Quick quiz

1. Why do production embedded systems usually prefer timer-based delays over busy-wait loops?