Tutorials
Schedule an RP2040 Timer Alarm Across the 32-Bit Microsecond Wrap
Published · Updated
The RP2040 exposes a 64-bit microsecond timebase, but its hardware alarms match the low 32 bits. A timestamp that looks smaller than the current low word can still be the next valid deadline.
Keep the full deadline and the hardware match value separately

At one tick per microsecond, the low word rolls over every 4,294,967,296 µs, about 71 minutes and 35 seconds. Compare long deadlines in a 64-bit software time domain. Before programming a low-word alarm, verify the intended occurrence lies in the hardware scheduling horizon and allow time to arm it.
If setup can overrun the deadline, implement an explicit late path. Waiting for another equality could delay the event for a complete low-word cycle.
Test modular timestamp differences · Test a counter at its boundaries
Add one millisecond near the rollover point

Start from low word 0xFFFFFF00. Adding 1,000 µs advances 256 ticks to zero and then 744 ticks farther, so the new low word is 0x000002E8. That target is in the future in this example.
A plain unsigned comparison of target against current low word says otherwise. Test three cases in firmware: a normal future deadline, a future deadline across rollover and a target already missed while arming. Record the full timestamp and whether the late branch fired.
Can a single low-word match schedule an event two hours away unambiguously?
The low word repeats sooner than two hours. Retain the long deadline in software and arm a nearer rendezvous or use the SDK scheduling facility after checking its documented horizon.
Read the example one step at a time

- Initial low word · 0xFFFFFF00 · 256 µs to rollover
- Requested interval · 1,000 µs · Crosses zero
- Hardware match · 0x000002E8 · 744 µs after zero
Look for missed trigger edges · Check elapsed time and throughput separately
Use the board bring-up checklist.
Raspberry Pi RP2040 Datasheet, 4.6 Timer.
Photograph credit and licence
Phiarc, Raspberry Pi Pico top (Wikimedia Commons), CC BY-SA 4.0. WebP adaptation.
Original photograph https://commons.wikimedia.org/wiki/File:Raspberry_Pi_Pico_top.jpg
Licence https://creativecommons.org/licenses/by-sa/4.0/
Back to Tutorials