Skip to content

Lab 2: PIT And Timer IRQs

Generated folder: labs/timer/

Lab 2 introduces periodic hardware events. Instead of asking a high-level OS clock for time, you configure a timer-like device and react to interrupts. This is the first point where the course starts to feel reactive: the program does not simply run a calculation and exit, it waits for a device to say that something happened.

Device Model

PartRole
Timer 0periodic interrupt source
Control wordselects timer, access mode, operating mode, BCD/binary
Divisorconverts base clock frequency into requested rate
IRQ lineevent path from device to program
Interrupt handlerrecords that a tick happened

The timer is deliberately simple, but it creates the foundation for almost everything that follows. Keyboard idle timeouts, mouse polling windows, graphics animation, audio scheduling, serial retries, and final project game loops all need a way to measure progress through time.

Plan

Begin with why PC timers exist, then study the i8254 controller and the arithmetic behind timer divisors. After that, compare polling and interrupts, because this choice will return in the keyboard and mouse labs. The last part of the lab is about turning the exercise into a reusable timer library, completing the implementation tasks, and comparing the model with modern timers.

TIP

Timer code is infrastructure. Keep it small now so your final project can use it without copying lab-specific logic.

Course/docs licensed CC BY 4.0. Code licensed MIT.