12.10. Always-on timer
12.10.1. Overview
The always-on timer (AON Timer) is the only timer that operates in all power modes. It can be used as a real-time counter or an interval timer and incorporates an alarm which can be used to trigger a power-up event or an interrupt. It incorporates a 64-bit counter intended to count 1ms ticks, but the tick generator can be configured to run faster or slower if required. Note that the AON Timer tick generator is independent of all other tick generators on the chip.
The default tick source is the 32kHz on-chip low-power oscillator (LPOSC), see Section 8.4 . The LPOSC frequency is not precise and may vary with voltage and temperature. When the chip core is powered, the tick source can be switched to the on-chip crystal oscillator (XOSC) for greater precision. If greater precision is also required when the chip core is
unpowered, then a 32kHz clock or a 1ms tick can be supplied from an external source. Alternatively, the AON Timer can be synchronised to an external 1Hz source.
The AON Timer is integrated with the power manager (POWMAN) and shares the POWMAN register block. Writes are limited to 16 bits because a key (
0x5afe) is required in the top 16 bits to prevent erroneous writes from locking up the chip. Most AON Timer registers can be enabled for write by Non-secure software, unlike other POWMAN registers. However, the registers used to select an external clock, select an external tick source, and enable power-up on alarm can only be written by Secure software.
12.10.2. Changes from RP2040
The RP2040 Real Time Clock (RTC) is not used in RP2350. Instead, RP2350 has a timer in the Always-On power domain which is used for scheduling power-up events and can also be used as a real-time counter. The AON Timer works differently from the RP2040 RTC. It counts milliseconds to 64 bits and this value can be used to calculate the date and time in software if required.
12.10.3. Accessing the AON Timer
To start and stop the AON Timer, write to
TIMER.RUN.
To read the current 64-bit AON Timer value, use the following 2 × 32-bit read-only registers:
- •
READ_TIME_UPPER - •
READ_TIME_LOWER
Because the AON Timer can increment during a read, use the following procedure to protect against erroneous reads:
- 1. Read
READ_TIME_UPPER - 2. Read
READ_TIME_LOWER - 3. Read
READ_TIME_UPPER - 4. If the
READ_TIME_UPPERvalue changes between steps 1 and 3, repeat the whole procedure
When used as a real time clock, the 64-bit time value is set using 4 × 16-bit registers. These registers can only be written when the AON Timer is stopped by writing a 0 to
TIMER.RUN:
- •
SET_TIME_63T048 - •
SET_TIME_47T032 - •
SET_TIME_31T016 - •
SET_TIME_15T00
These registers cannot be used to read the time value.
When used as an interval timer, write a 1 to
TIMER.CLEAR to clear the timer value. It is not necessary to stop the AON Timer to do this. The
TIMER.CLEAR register is self-clearing: it returns to 0 when the operation completes. This allows easy implementation of an alarm that wakes the chip or generates an interrupt at regular intervals.
12.10.4. Using the alarm
To set the alarm time, use the following 4 × 16-bit registers:
- •
ALARM_TIME_63T048 - •
ALARM_TIME_47T032
12.10.5.2. Using an external clock in place of LPOSC
If LPOSC isn't sufficiently accurate, an external 32.768kHz clock can be used. This will be multiplexed onto the internal low-power clock and will therefore drive all components that are driven by that clock, including the power sequencer components. The external clock can be used in all power modes. When an external clock is in use, you can stop the LPOSC (see Section 8.4 ).
To select an external 32kHz clock:
- 1. Configure the GPIO source as described in Section 12.10.7 .
- 2. Switch to the external LPOSC by setting
EXT_TIME_REF.DRIVE_LPCK. This register should only be written whenTIMER.RUN = 0and the power sequencer is inactive. You can only write to this register from Secure code.
The external 32kHz clock replaces the clock from LPOSC. Therefore the same registers are used for AON Timer configuration (see Section 12.10.5.1 ):
- •
TIMER.USE_LPOSC - •
TIMER.USING_LPOSC - •
LPOSC_FREQ_KHZ_INT - •
LPOSC_FREQ_KHZ_FRAC
12.10.5.3. Using the XOSC as the AON Timer tick source
The XOSC clock is provided via the reference clock (
clk_ref). The user must ensure the reference clock is being driven from the XOSC before selecting it as the source of the AON Timer tick. This is the normal configuration following boot. To check, look for
CLK_REF_SELECTED = 0x4. The reference clock may be a divided version of the XOSC. The divisor defaults to 1 and can be read from
CLK_REF_DIV.INT. If the chip is operated with a faster XOSC, the clock sent to the AON Timer must not exceed 29MHz.
The AON Timer derives the 1ms tick from the XOSC using a 16.16 bit fractional divider whose divisor is initialised to 12000.0. This assumes a 12MHz crystal is used and the reference clock divisor is 1. If that is not the case, the divisor in the AON Timer can be modified by writing to the following registers:
- •
XOSC_FREQ_KHZ_INT(default value: 12000) - •
XOSC_FREQ_KHZ_FRAC(default value: 0)
These registers should only be written when
TIMER.RUN = 0 or
TIMER.USING_XOSC = 0.
To select the XOSC as the AON Timer tick source, write a 1 to
TIMER.USE_XOSC. It is not necessary to stop the AON Timer to do this. The newly selected tick will be synchronised to the current tick, so the operation may take up to 1 tick cycle (1ms in normal operation). When the operation is complete
TIMER.USE_XOSC will self-clear and
TIMER.USING_XOSC will be set. Due to sampling, a small error of up to 2 periods of the newly selected clock will be subtracted from the time. When switching to XOSC at 12MHz an error of up to 167ns will be subtracted.
When the chip core is powered down the XOSC will stop. If
TIMER.USING_XOSC is set, the power-down sequencer automatically reverts to
TIMER.USING_LPOSC before the XOSC stops.
12.10.5.4. Using an external 1ms tick source
To select an external 1ms tick source, configure the GPIO source as described in
Section 12.10.7
. Then, write a 1 to
TIMER.USE_GPIO_1KHZ. It is not necessary to stop the AON Timer to do this, however the newly selected tick will not be synchronised to the current tick, so the operation so the operation will advance the time by up to 1ms. If using an external 1ms tick it is recommended to set the time after selecting the source. When the operation is complete
TIMER.USE_GPIO_1KHZ will self-clear and
TIMER.USING_GPIO_1KHZ will be set.
The tick is triggered from the falling edge of the selected GPIO. For correct sampling, the GPIO pulse width and interval must both be greater than the period of LPOSC (>31us). This limits the maximum frequency of the external tick to
16kHz.
The external 1ms tick can be used in all power modes.
12.10.6. Synchronising the AON timer to an external 1Hz clock
In applications that use GPS, a 1s tick may be available. This can be used to synchronise the AON Timer and thus compensate for inaccuracy in the LPOSC frequency. It can be used with any tick source, but there is little to be gained if the selected source is already reasonably accurate.
If the LPOSC is fast, the ms counter pauses at a 1 second step until the 1s tick is received. If the LPOSC is slow, the 1s tick causes the ms counter to run very quickly until reaching the 1 second step. This ensures that all ms values are counted, ensuring that any alarm set to ms precision will fire. A more sophisticated synchronisation method can be implemented in software.
To use the hardware synchronisation feature, configure the GPIO source as described in
Section 12.10.7
. Then, enable the feature by writing a 1 to
TIMER.USE_GPIO_1HZ. This can be set at any time, it is not necessary to stop the AON Timer. When the operation is complete
TIMER.USE_GPIO_1HZ will self-clear and
TIMER.USING_GPIO_1HZ will be set.
The tick is triggered from the falling edge of the selected GPIO. For correct sampling, the GPIO pulse width and interval must be greater than the period of LPOSC (>31us).
The external 1s tick can be used in all power modes.
12.10.7. Using an external clock or tick from GPIO
The following features use a GPIO as a clock or a tick:
- • external 32kHz clock source
- • external 1kHz tick
- • external 1Hz tick
Only 4 GPIOs are available for these features. You can only select one, because they share the same GPIO selection logic. The set of 4 GPIOs differs between package types. The selection is controlled by a 2-bit register field.
The AON Timer uses the following GPIOs:
- •
EXT_TIME_REF.SOURCE_SEL = 0→ GPIO12 - •
EXT_TIME_REF.SOURCE_SEL = 1→ GPIO20 - •
EXT_TIME_REF.SOURCE_SEL = 2→ GPIO14 - •
EXT_TIME_REF.SOURCE_SEL = 3→ GPIO22
12.10.8. Using a tick faster than 1ms
The tick rate can be increased by scaling the value written to the LPOSC and XOSC frequency registers. For example, if the frequency value is divided by 4 then the AON Timer will tick 4 times per ms. The minimum value that can be written to the frequency registers is 2.0, therefore the maximum upscaling using this method with LPOSC is 16, giving a time resolution of 1/16th of 1 ms (= 62.5us).
As described previously, the external tick is limited to 16kHz, so the maximum upscaling using this method is also 16. This gives a time resolution of 1/16th of 1 ms (62.5µs).
These limitations can be overcome either by using a faster external clock (see Section 12.10.5.2 ) or keeping the chip core powered so the AON Timer is always running from the XOSC. If a faster external clock is used then the power sequencer timings will also need to be adjusted.
For example, suppose 1µsec timer precision is required. The user could supply an external 2-25MHz clock in place of the LPOSC and program both the LPOSC and XOSC frequency registers in MHz units rather than kHz. The maximum frequency of the external clock is 29MHz.
12.10.9. List of registers
The AON Timer shares a register address space with the power management subsystems in the always-on domain. The address space is referred to as POWMAN elsewhere in this document and a complete list of POWMAN registers is provided in Section 6.4 . The registers associated with the AON Timer are: