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 schematic
RTC block schematic

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

Clock source

The RTC runs off the LFCLK.

The COUNTER resolution is 30.517 µs. Depending on the source, the RTC is able to run while the HFCLK is OFF and PCLK16M is not available.

The software has to explicitly start LFCLK before using the RTC.

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

Resolution versus overflow and the PRESCALER

Counter increment frequency:


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

The PRESCALER register is read/write when the RTC is stopped. The PRESCALER register is read-only once the RTC is STARTed. Writing to the PRESCALER register when the RTC is started has no effect.

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

Examples of different frequency configurations are as following:

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

COUNTER register

The COUNTER 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. The TICK event is disabled by default.

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

Overflow features

The TRIGOVRFLW task sets the COUNTER value to 0xFFFFF0 to allow SW test of the overflow condition.

OVRFLW occurs when COUNTER overflows from 0xFFFFFF to 0.

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 a RTOS without the need to use the ARM® SysTick feature.

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

Note: The TICK event is disabled by default.

Event control feature

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

For example, if the TICK event is not required for an application, this event should be disabled as it is frequently occurring and may increase power consumption if HFCLK otherwise could be powered down for long durations.

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 Tasks, events, and interrupts in the RTC.

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

Compare feature

There are a number of Compare registers.

For more information, see Registers.

When setting a compare register, the following behavior of the RTC compare event should be noted:

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, 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 read from an internal register called COUNTER in the LFCLK domain. COUNTER is the register which is actually modified each time the RTC ticks. These registers must be synchronised between clock domains (PCLK16M and LFCLK).

The following is a summary of the jitter introduced on tasks and events.

Table 2. RTC jitter magnitudes on tasks
TaskDelay
CLEAR, STOP, START, 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
Note: 32.768 kHz clock jitter is additional to the numbers provided above.
CLEAR and STOP (and TRIGOVRFLW; not shown) will be delayed as long as it takes for the peripheral to clock a falling edge and rising 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 11. Timing diagram - DELAY_CLEAR
Timing diagram - DELAY_CLEAR
Figure 12. 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. In some cases, in particular if the RTC is STARTed before the LFCLK is running, that timing can be up to ~250 μs. The software should therefore wait for the first TICK if it has to make sure 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 start LFCLK, but the update will then be delayed by the same amount of time of up to ~250 μs. The figures show the shortest and longest delays on the START task which appears as a +/-15 μs jitter on the first COUNTER increment.
Figure 13. Timing diagram - JITTER_START-
Timing diagram - JITTER_START-
Figure 14. Timing diagram - JITTER_START+
Timing diagram - JITTER_START+

Reading the COUNTER register

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

To ensure that the <<COUNTER>> is safely sampled (considering an LFCLK transition may occur during a read), the CPU and core memory bus are halted for three cycles by lowering the core PREADY signal. The Read takes the CPU 2 cycles in addition resulting in the COUNTER register read taking a fixed five PCLK16M clock cycles.

Figure 15. Timing diagram - COUNTER_READ

Registers

Instances

InstanceBase addressDescription
RTC00x4000B000Real-time counter 0
RTC10x40011000Real-time counter 1

Configuration

InstanceConfiguration
RTC0CC[0..2] implemented, CC[3] not implemented
RTC1CC[0..3] implemented

Register overview

RegisterOffsetDescription
TASKS_START0x000Start RTC COUNTER
TASKS_STOP0x004Stop RTC COUNTER
TASKS_CLEAR0x008Clear RTC COUNTER
TASKS_TRIGOVRFLW0x00CSet COUNTER to 0xFFFFF0
EVENTS_TICK0x100Event on COUNTER increment
EVENTS_OVRFLW0x104Event on COUNTER overflow
EVENTS_COMPARE[0]0x140Compare event on CC[0] match
EVENTS_COMPARE[1]0x144Compare event on CC[1] match
EVENTS_COMPARE[2]0x148Compare event on CC[2] match
EVENTS_COMPARE[3]0x14CCompare event on CC[3] match
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[0]0x540Compare register 0
CC[1]0x544Compare register 1
CC[2]0x548Compare register 2
CC[3]0x54CCompare register 3

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

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[0]

Address offset: 0x140

Compare event on CC[0] match

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

EVENTS_COMPARE[1]

Address offset: 0x144

Compare event on CC[1] match

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

EVENTS_COMPARE[2]

Address offset: 0x148

Compare event on CC[2] match

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

EVENTS_COMPARE[3]

Address offset: 0x14C

Compare event on CC[3] match

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

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
CRWCOMPARE[0]Write '1' to enable interrupt for event COMPARE[0]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCOMPARE[1]Write '1' to enable interrupt for event COMPARE[1]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
ERWCOMPARE[2]Write '1' to enable interrupt for event COMPARE[2]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
FRWCOMPARE[3]Write '1' to enable interrupt for event COMPARE[3]
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
CRWCOMPARE[0]Write '1' to disable interrupt for event COMPARE[0]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCOMPARE[1]Write '1' to disable interrupt for event COMPARE[1]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
ERWCOMPARE[2]Write '1' to disable interrupt for event COMPARE[2]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
FRWCOMPARE[3]Write '1' to disable interrupt for event COMPARE[3]
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
CRWCOMPARE[0]Enable or disable event routing for event COMPARE[0]
Disabled0Disable
Enabled1Enable
DRWCOMPARE[1]Enable or disable event routing for event COMPARE[1]
Disabled0Disable
Enabled1Enable
ERWCOMPARE[2]Enable or disable event routing for event COMPARE[2]
Disabled0Disable
Enabled1Enable
FRWCOMPARE[3]Enable or disable event routing for event COMPARE[3]
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
CRWCOMPARE[0]Write '1' to enable event routing for event COMPARE[0]
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable
DRWCOMPARE[1]Write '1' to enable event routing for event COMPARE[1]
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable
ERWCOMPARE[2]Write '1' to enable event routing for event COMPARE[2]
Disabled0Read: Disabled
Enabled1Read: Enabled
Set1Enable
FRWCOMPARE[3]Write '1' to enable event routing for event COMPARE[3]
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
CRWCOMPARE[0]Write '1' to disable event routing for event COMPARE[0]
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable
DRWCOMPARE[1]Write '1' to disable event routing for event COMPARE[1]
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable
ERWCOMPARE[2]Write '1' to disable event routing for event COMPARE[2]
Disabled0Read: Disabled
Enabled1Read: Enabled
Clear1Disable
FRWCOMPARE[3]Write '1' to disable event routing for event COMPARE[3]
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[0]

Address offset: 0x540

Compare register 0

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

CC[1]

Address offset: 0x544

Compare register 1

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

CC[2]

Address offset: 0x548

Compare register 2

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

CC[3]

Address offset: 0x54C

Compare register 3

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