Skip to main content

Chapter 8 Timers and Interrupts

The programs we have written so far stop and wait whenever they need to mark off time. delay_ms(1000) produces an accurate one-second delay, but for that entire second the CPU can do nothing else, not read a sensor, not update a display, not notice a button. This chapter introduces the two mechanisms that end the waiting. A hardware timer is a circuit that counts on its own, in parallel with whatever the CPU is doing. An interrupt is the hardware’s way of tapping the CPU on the shoulder when something (a timer reaching its period, a button changing state) needs attention, without the CPU ever having to ask. Together they are how embedded software becomes responsive and efficient at the same time.