RTC — Real-time counter

The real-time counter (RTC) module provides a generic, low-power timer on the low frequency clock source (LFCLK).

Figure 1. RTC block diagram
RTC block diagram

The RTC module features a 24-bit COUNTER, a 12-bit (1/X) prescaler, capture/compare registers, and a tick event generator.

Clock source

The RTC will run off the LFCLK.

When started, the RTC will automatically request the LFCLK source with RC oscillator if the LFCLK is not already running.

See CLOCK — Clock control for more information about clock sources.

Resolution versus overflow and the prescaler

The relationship between the prescaler, counter resolution, and overflow is summarized in the following table.

Table 1. RTC resolution versus overflow
PrescalerCounter resolutionOverflow
030.517 μs512 seconds
28-17812.5 μs131072 seconds
212-1125 ms582.542 hours

The counter increment frequency is given by the following equation:


    fRTC [kHz] = 32.768 / (PRESCALER + 1 )
    

The PRESCALER register can only be written when the RTC is stopped.

The prescaler is restarted on tasks START, CLEAR and TRIGOVRFLW. That is, the prescaler value is latched to an internal register (<<PRESC>>) on these tasks.

Examples:

  1. Desired COUNTER frequency 100 Hz (10 ms counter period)

    PRESCALER = round(32.768 kHz / 100 Hz) - 1 = 327

    fRTC = 99.9 Hz

    10009.576 μs counter period

  2. Desired COUNTER frequency 8 Hz (125 ms counter period)

    PRESCALER = round(32.768 kHz / 8 Hz) – 1 = 4095

    fRTC = 8 Hz

    125 ms counter period

Counter register

The internal <<COUNTER>> register increments on LFCLK when the internal PRESCALER register (<<PRESC>>) is 0x00. <<PRESC>> is reloaded from the PRESCALER register. If enabled, the TICK event occurs on each increment of the COUNTER.

Figure 2. Timing diagram - COUNTER_PRESCALER_0
Timing diagram - COUNTER_PRESCALER_0
Figure 3. Timing diagram - COUNTER_PRESCALER_1
Timing diagram - COUNTER_PRESCALER_1

Reading the counter register

To read the COUNTER register, the internal <<COUNTER>> value is sampled.

To ensure that the <<COUNTER>> is safely sampled (considering that an LFCLK transition may occur during a read), the CPU and core memory bus are halted for four PCLK16M cycles. In addition, the read takes the CPU two PCLK16M cycles, resulting in the COUNTER register read taking maximum six PCLK16M clock cycles.

Overflow

An OVRFLW event is generated on COUNTER register overflow (overflowing from 0xFFFFFF to 0).

The TRIGOVRFLW task will set the COUNTER value to 0xFFFFF0, to allow software test of the overflow condition.

Note: The OVRFLW event is disabled by default.

Tick event

The TICK event enables low-power tickless RTOS implementation, as it optionally provides a regular interrupt source for an RTOS with no need for use of the ARM® SysTick feature.

Using the TICK event, rather than the SysTick, allows the CPU to be powered down while keeping RTOS scheduling active.

Note: The TICK event is disabled by default.

Event control

To optimize the RTC power consumption, events in the RTC can be individually disabled to prevent PCLK16M and HFCLK from being requested when those events are triggered. This is managed using the EVTEN register.

This means that the RTC implements a slightly different task and event system compared to the standard system described in Peripheral interface. The RTC task and event system is illustrated in the following figure.

Figure 4. Tasks, events, and interrupts in the RTC
Tasks, events, and interrupts in the RTC

Capture

The RTC implements one capture task for every available capture/compare register.

Every time TASKS_CAPTURE[n] is triggered, <<COUNTER>> is copied to the corresponding CC[n] register.

If the CAPTURE and CLEAR tasks are triggered at the same time, the CAPTURE task will be prioritized. This means that the CC[n] register for the corresponding CAPTURE[n] task will be set to the captured value before the counter is reset. There is a delay of 6 PCLK16M periods from when the TASKS_CAPTURE[n] is triggered until the corresponding CC[n] register is updated.

The CAPTURE[n] tasks will not generate COMPARE[n] events, even though CC[n] will then equal the COUNTER.

Compare

The RTC implements one COMPARE event for every available compare register.

When the COUNTER is incremented and then becomes equal to the value specified in the register CC[n], the corresponding compare event COMPARE[n] is generated.

When writing a CC[n] register, the RTC COMPARE event exhibits several behaviors. See the following figures for more information.

If a CC value is 0 when a CLEAR task is set, this will not trigger a COMPARE event.

Figure 5. Timing diagram - COMPARE_CLEAR
Timing diagram - COMPARE_CLEAR

If a CC value is N and the COUNTER value is N when the START task is set, this will not trigger a COMPARE event.

Figure 6. Timing diagram - COMPARE_START
Timing diagram - COMPARE_START

A COMPARE event occurs when a CC value is N, and the COUNTER value transitions from N-1 to N.

Figure 7. Timing diagram - COMPARE
Timing diagram - COMPARE

If the COUNTER value is N, writing N+2 to a CC register is guaranteed to trigger a COMPARE event at N+2.

Figure 8. Timing diagram - COMPARE_N+2
Timing diagram - COMPARE_N+2

If the COUNTER value is N, writing N or N+1 to a CC register may not trigger a COMPARE event.

Figure 9. Timing diagram - COMPARE_N+1
Timing diagram - COMPARE_N+1

If the COUNTER value is N, and the current CC value is N+1 or N+2 when a new CC value is written, a match may trigger on the previous CC value before the new value takes effect. If the current CC value is greater than N+2 when the new value is written, there will be no event due to the old value.

Figure 10. Timing diagram - COMPARE_N-1
Timing diagram - COMPARE_N-1

If the COMPARE[i]_CLEAR short is enabled, the COUNTER will be cleared one LFClk after the COMPARE event.

Figure 11. Timing diagram - COMPARE_CLEAR
Timing diagram - COMPARE_CLEAR

Task and event jitter/delay

Jitter or delay in the RTC, is due to the peripheral clock being a low frequency clock (LFCLK), which is not synchronous to the faster PCLK16M.

Registers in the peripheral interface that are part of the PCLK16M domain, have a set of mirrored registers in the LFCLK domain. For example, the COUNTER value accessible from the CPU is in the PCLK16M domain, and is latched on a read from an internal COUNTER register in the LFCLK domain. The COUNTER register is modified each time the RTC ticks. The registers are synchronised between the two clock domains (PCLK16M and LFCLK).

CLEAR and STOP (and TRIGOVRFLW, which is not shown) will be delayed as long as it takes for the peripheral to clock a falling edge and a rising edge of the LFCLK. This is between 15.2585 μs and 45.7755 μs – rounded to 15 μs and 46 μs for the remainder of the section.

Figure 12. Timing diagram - DELAY_CLEAR
Timing diagram - DELAY_CLEAR

When a STOP task is triggered, the PCLK16M domain will immediately prevent the generation of any EVENTS from the RTC. However, as seen in the following figure, the COUNTER value can still increment one final time.

Figure 13. Timing diagram - DELAY_STOP
Timing diagram - DELAY_STOP

The START task will start the RTC. Assuming that the LFCLK was previously running and stable, the first increment of COUNTER (and instance of TICK event) will be typically after 30.5 μs ±15 μs. Additional delay will occur if the RTC is started before the LFCLK is running, see CLOCK — Clock control for LFLK startup times. The software should therefore wait for the first TICK if it has to make sure that the RTC is running. Sending a TRIGOVRFLW task sets the COUNTER to a value close to overflow. However, since the update of COUNTER relies on a stable LFCLK, sending this task while LFCLK is not running will also add additional delay as previously described. The figures show the smallest and largest delays on the START task, appearing as a ±15 μs jitter on the first COUNTER increment.

Figure 14. Timing diagram - JITTER_START-
Timing diagram - JITTER_START-
Figure 15. Timing diagram - JITTER_START+
Timing diagram - JITTER_START+

The following tables summarize jitter introduced for tasks and events. Any 32.768 kHz clock jitter will come in addition to these numbers.

Table 2. RTC jitter magnitudes on tasks
TaskDelay
CLEAR, START, STOP, TRIGOVRFLOW+15 to 46 μs
Table 3. RTC jitter magnitudes on events
Operation/FunctionJitter
START to COUNTER increment± 15 μs
COMPARE to COMPARE 1± 62.5 ns

Registers

Instances

InstanceDomainBase addressTrustZoneSplit accessDescription
MapAttDMA
RTC0 : S
RTC0 : NS
APPLICATION0x50014000
0x40014000
USSNANoReal time counter 0
RTC1 : S
RTC1 : NS
APPLICATION0x50015000
0x40015000
USSNANoReal time counter 1
RTC0NETWORK0x41011000HFNSNANoReal-time counter 0
RTC1NETWORK0x41016000HFNSNANoReal-time counter 1

Register overview

RegisterOffsetTZDescription
TASKS_START0x000Start RTC counter
TASKS_STOP0x004Stop RTC counter
TASKS_CLEAR0x008Clear RTC counter
TASKS_TRIGOVRFLW0x00CSet counter to 0xFFFFF0
TASKS_CAPTURE[n]0x040Capture RTC counter to CC[n] register
SUBSCRIBE_START0x080Subscribe configuration for task START
SUBSCRIBE_STOP0x084Subscribe configuration for task STOP
SUBSCRIBE_CLEAR0x088Subscribe configuration for task CLEAR
SUBSCRIBE_TRIGOVRFLW0x08CSubscribe configuration for task TRIGOVRFLW
SUBSCRIBE_CAPTURE[n]0x0C0Subscribe configuration for task CAPTURE[n]
EVENTS_TICK0x100Event on counter increment
EVENTS_OVRFLW0x104Event on counter overflow
EVENTS_COMPARE[n]0x140Compare event on CC[n] match
PUBLISH_TICK0x180Publish configuration for event TICK
PUBLISH_OVRFLW0x184Publish configuration for event OVRFLW
PUBLISH_COMPARE[n]0x1C0Publish configuration for event COMPARE[n]
SHORTS0x200Shortcuts between local events and tasks
INTENSET0x304Enable interrupt
INTENCLR0x308Disable interrupt
EVTEN0x340Enable or disable event routing
EVTENSET0x344Enable event routing
EVTENCLR0x348Disable event routing
COUNTER0x504Current counter value
PRESCALER0x50812-bit prescaler for counter frequency (32768 / (PRESCALER + 1)). Must be written when RTC is stopped.
CC[n]0x540Compare register n

TASKS_START

Address offset: 0x000

Start RTC counter

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STARTStart RTC counter
Trigger1Trigger task

TASKS_STOP

Address offset: 0x004

Stop RTC counter

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STOPStop RTC counter
Trigger1Trigger task

TASKS_CLEAR

Address offset: 0x008

Clear RTC counter

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_CLEARClear RTC counter
Trigger1Trigger task

TASKS_TRIGOVRFLW

Address offset: 0x00C

Set counter to 0xFFFFF0

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_TRIGOVRFLWSet counter to 0xFFFFF0
Trigger1Trigger task

TASKS_CAPTURE[n] (n=0..3)

Address offset: 0x040 + (n × 0x4)

Capture RTC counter to CC[n] register

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_CAPTURECapture RTC counter to CC[n] register
Trigger1Trigger task

SUBSCRIBE_START

Address offset: 0x080

Subscribe configuration for task START

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task START will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_STOP

Address offset: 0x084

Subscribe configuration for task STOP

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task STOP will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_CLEAR

Address offset: 0x088

Subscribe configuration for task CLEAR

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task CLEAR will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_TRIGOVRFLW

Address offset: 0x08C

Subscribe configuration for task TRIGOVRFLW

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task TRIGOVRFLW will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_CAPTURE[n] (n=0..3)

Address offset: 0x0C0 + (n × 0x4)

Subscribe configuration for task CAPTURE[n]

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task CAPTURE[n] will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

EVENTS_TICK

Address offset: 0x100

Event on counter increment

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_TICKEvent on counter increment
NotGenerated0Event not generated
Generated1Event generated

EVENTS_OVRFLW

Address offset: 0x104

Event on counter overflow

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_OVRFLWEvent on counter overflow
NotGenerated0Event not generated
Generated1Event generated

EVENTS_COMPARE[n] (n=0..3)

Address offset: 0x140 + (n × 0x4)

Compare event on CC[n] match

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_COMPARECompare event on CC[n] match
NotGenerated0Event not generated
Generated1Event generated

PUBLISH_TICK

Address offset: 0x180

Publish configuration for event TICK

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that event TICK will publish to
BRWEN
Disabled0Disable publishing
Enabled1Enable publishing

PUBLISH_OVRFLW

Address offset: 0x184

Publish configuration for event OVRFLW

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that event OVRFLW will publish to
BRWEN
Disabled0Disable publishing
Enabled1Enable publishing

PUBLISH_COMPARE[n] (n=0..3)

Address offset: 0x1C0 + (n × 0x4)

Publish configuration for event COMPARE[n]

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that event COMPARE[n] will publish to
BRWEN
Disabled0Disable publishing
Enabled1Enable publishing

SHORTS

Address offset: 0x200

Shortcuts between local events and tasks

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A-DRWCOMPARE[i]_CLEAR (i=0..3)Shortcut between event COMPARE[i] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTICKWrite '1' to enable interrupt for event TICK
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWOVRFLWWrite '1' to enable interrupt for event OVRFLW
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
C-FRWCOMPARE[i] (i=0..3)Write '1' to enable interrupt for event COMPARE[i]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTICKWrite '1' to disable interrupt for event TICK
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWOVRFLWWrite '1' to disable interrupt for event OVRFLW
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
C-FRWCOMPARE[i] (i=0..3)Write '1' to disable interrupt for event COMPARE[i]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled

EVTEN

Address offset: 0x340

Enable or disable event routing

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTICKEnable or disable event routing for event TICK
Disabled0Disable
Enabled1Enable
BRWOVRFLWEnable or disable event routing for event OVRFLW
Disabled0Disable
Enabled1Enable
C-FRWCOMPARE[i] (i=0..3)Enable or disable event routing for event COMPARE[i]
Disabled0Disable
Enabled1Enable

EVTENSET

Address offset: 0x344

Enable event routing

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTICKWrite '1' to enable event routing for event TICK
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable
BRWOVRFLWWrite '1' to enable event routing for event OVRFLW
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable
C-FRWCOMPARE[i] (i=0..3)Write '1' to enable event routing for event COMPARE[i]
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable

EVTENCLR

Address offset: 0x348

Disable event routing

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTICKWrite '1' to disable event routing for event TICK
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable
BRWOVRFLWWrite '1' to disable event routing for event OVRFLW
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable
C-FRWCOMPARE[i] (i=0..3)Write '1' to disable event routing for event COMPARE[i]
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable

COUNTER

Address offset: 0x504

Current counter value

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARCOUNTERCounter value

PRESCALER

Address offset: 0x508

12-bit prescaler for counter frequency (32768 / (PRESCALER + 1)). Must be written when RTC is stopped.

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWPRESCALERPrescaler value

CC[n] (n=0..3)

Address offset: 0x540 + (n × 0x4)

Compare register n

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCOMPARECompare value
1 Assumes RTC runs continuously between these events.