Skip to content

Lab 2: PIT and timer IRQs ​

Generated folder: labs/timer/

Lab 2 introduces periodic hardware events. You configure a timer-like device and react to interrupts instead of asking an OS clock for time. The program now waits for a device to report 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 simple, but it supports keyboard idle timeouts, mouse polling windows, animation, audio scheduling, serial retries, and final project loops.

Plan ​

Read why PC timers exist, then the i8254 controller and timer divisor arithmetic. Compare polling and interrupts, then turn the exercise into a reusable timer library. Complete the tasks, validate with the checks, and compare with modern timers.

TIP

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

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