Datasheet

Table Of Contents
can be used to read the raw time without any latching.
WARNING
While it is technically possible to set the time by writing to the TIMEHW and TIMELW registers, programmers are
discouraged from doing this. This is because the timer value is expected to be monotonically increasing (with a 64-bit
wrap) by the Pico SDK which uses it for timeouts, elapsed time etc.
4.7.3. Alarms
The timer has 4 alarms, and outputs a separate interrupt for each alarm. The alarms match on the lower 32 bits of the 64-
bit counter which means they can be fired at a maximum of 2
32
microseconds into the future. This is equivalent to:
2
32
÷ 10
6
: ~4295 seconds
4295 ÷ 60: ~72 minutes
NOTE
This timer is expected to be used for short sleeps. If you want a longer alarm see Section 4.9.
To enable an alarm:
Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
Once the alarm has fired, the ARMED bit will be set to 0. To clear the latched interrupt, write a 1 to the appropriate bit in
INTR.
4.7.4. Programmer’s Model
NOTE
The Watchdog tick (see Section 4.8.2) must be running for the timer to start counting. The Pico SDK starts this tick at
the start of day.
4.7.4.1. Reading the time
NOTE
Time here refers to the number of microseconds since the timer was started, it is not a clock. For that - see Section
4.9.
The simplest form of reading the 64-bit time is to read TIMELR followed by TIMEHR. However, because RP2040 has 2
cores, it is unsafe to do this if the second core is executing code that can also access the timer. This is because reading
TIMELR latches the value in TIMEHR (i.e. stops it updating) until TIMEHR is read. If one core reads TIMELR followed by
another core reading TIMELR, the value in TIMEHR isn’t necessarily accurate. The example below shows the simplest
form of getting the 64-bit time.
RP2040 Datasheet
4.7. Timer 559