RTC
Sample List
This chapter introduces the details of the RTC sample. The RTL87x2G provides the following samples for the RTC peripheral.
Functional Overview
RTC is an independent 32-bit incrementing counter, supporting pre-scaling and comparator functions, and it supports DLPS wake-up functionality.
Feature List
32 KHz clock source.
12-bits pre-scale counter.
32-bits read only RTC counter.
Incremental counter.
4 independent comparators (COMP0-3).
RTC_CMP0-3_NV–interrupt the CPU.
RTC_CMP0-3_WK–can wake up the chip from DLPS mode.
4 independent comparators (COMP0-3GT).
RTC_CMP0-3GT–can wake up the chip from DLPS mode.
Support Comparator interrupt, Tick interrupt and RTC counter overflow interrupt.
Pre-scale counter and interrupt.
Clock and Prescale
The schematic diagram of the RTC clock is shown in the figure:

RTC Clock
RTC contains two counters: a pre-scaler counter and the RTC counter. The 32kHz clock source is converted to RTC_CLK after pre-scaling, for use by the RTC counter. The pre-scaler value can be set by calling RTC_SetPrescaler()
.
When the RTC is running, the pre-scaler counter begins counting. Each time it counts to the set pre-scaler value, the RTC counter increments by 1. Every time the RTC counter increases by 1, a Tick interrupt is triggered.
Comparator and Interrupt
RTC supports 4 independent comparators, namely COMP0-3. The comparator’s comparison value can be set using RTC_SetCompValue()
. When the RTC counter value reaches the comparison value, it will trigger the RTC interrupt for the corresponding channel.
RTC supports pre-scaler comparators.
When the required RTC count time is less than one tick, the
RTC_INT_PRE_COMP
interrupt can be used. CallRTC_SetPreCompValue()
to set the pre-divider comparison value. This interrupt will be triggered when the pre-divider count reaches the set comparison value.When the required RTC count time is greater than one tick but not an integer multiple of a tick, the
RTC_INT_PRE_COMP3
interrupt can be used. In this case, it is necessary to enable both the RTC comparator and the pre-divider comparator to achieve a non-integer multiple tick timing by combining their comparison values. CallRTC_SetCompValue()
to set the comparison value for the COMP3 channel, and callRTC_SetPreCompValue()
to set the pre-divider comparison value. This interrupt will be triggered when both the COMP3 channel comparator and the pre-divider reach their respective comparison values. Note that this type of timing can only be used with the COMP3 channel.
DLPS Wake-up
All comparison channels and interrupts of the RTC support the DLPS wake-up function.
Among them, COMP0-3GT can only be used for DLPS wake-up and not for CPU interrupts, while other channels support both DLPS wake-up and CPU interrupt functions simultaneously.
Call RTC_SystemWakeupConfig()
to enable the RTC DLPS wake-up function.