Datasheet

19.6.3.2 16-Bit Counter (Mode 1)
When the RTC Operating Mode bits in the Control register (CTRL.MODE) are 1, the counter operates in
16-bit Counter mode as shown in Figure 19-2. When the RTC is enabled, the counter will increment on
every 0-to-1 transition of CLK_RTC_CNT. In 16-bit Counter mode, the 16-bit Period register (PER) holds
the maximum value of the counter. The counter will increment until it reaches the PER value, and then
wrap to 0x0000. This sets the Overflow interrupt flag in the Interrupt Flag Status and Clear register
(INTFLAG.OVF).
The RTC counter value can be read from or written to the Counter Value register (COUNT) in 16-bit
format.
The counter value is continuously compared with the 16-bit Compare registers (COMPn, n=0–1). When a
compare match occurs, the Compare n interrupt flag in the Interrupt Flag Status and Clear register
(INTFLAG.CMPn, n=0–1) is set on the next 0-to-1 transition of CLK_RTC_CNT.
19.6.3.3 Clock/Calendar (Mode 2)
When CTRL.MODE is two, the counter operates in Clock/Calendar mode, as shown in Figure 19-3. When
the RTC is enabled, the counter will increment on every 0-to-1 transition of CLK_RTC_CNT. The selected
clock source and RTC prescaler must be configured to provide a 1Hz clock to the counter for correct
operation in this mode.
The time and date can be read from or written to the Clock Value register (CLOCK) in a 32-bit time/date
format. Time is represented as:
Seconds
Minutes
Hours
Hours can be represented in either 12- or 24-hour format, selected by the Clock Representation bit in the
Control register (CTRL.CLKREP). This bit can be changed only while the RTC is disabled.
Date is represented as:
Day as the numeric day of the month (starting at 1)
Month as the numeric month of the year (1 = January, 2 = February, etc.)
Year as a value counting the offset from a reference value that must be defined in software
The date is automatically adjusted for leap years, assuming every year divisible by 4 is a leap year.
Therefore, the reference value must be a leap year, e.g. 2000. The RTC will increment until it reaches the
top value of 23:59:59 December 31st of year 63, and then wrap to 00:00:00 January 1st of year 0. This
will set the Overflow interrupt flag in the Interrupt Flag Status and Clear registers (INTFLAG.OVF).
The clock value is continuously compared with the 32-bit Alarm register (ALARM0). When an alarm
match occurs, the Alarm 0 Interrupt flag in the Interrupt Flag Status and Clear registers
(INTFLAG.ALARMn0) is set on the next 0-to-1 transition of CLK_RTC_CNT. E.g. For a 1Hz clock counter,
it means the Alarm 0 Interrupt flag is set with a delay of 1s after the occurrence of alarm match. A valid
alarm match depends on the setting of the Alarm Mask Selection bits in the Alarm
A valid alarm match depends on the setting of the Alarm Mask Selection bits in the Alarm 0 Mask register
(MASK0.SEL). These bits determine which time/date fields of the clock and alarm values are valid for
comparison and which are ignored.
If the Clear on Match bit in the Control register (CTRL.MATCHCLR) is one, the counter is cleared on the
next counter cycle when an alarm match with ALARM0 occurs. This allows the RTC to generate periodic
interrupts or events with longer periods than are possible with the prescaler events (see 19.6.9.1
SAM D21 Family
RTC – Real-Time Counter
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40001882D-page 261