SAM D21 Real-Time Counter (RTC) Overview

Last modified by Microchip on 2023/11/09 09:01

The SAM D21 Real-Time Counter (RTC) is a 32-bit counter with a 10-bit programmable prescaler that typically runs continuously (including low-power sleep modes) to keep track of time. The RTC keeps track of time in the system and enables periodic events, as well as interrupts and events at a specified time. It can also wake the device from sleep using the alarm/compare wake-up, periodic wake-up, or overflow wake-up mechanisms.

The RTC is typically clocked by the 1.024 kHz output from the 32.768 kHz High-Accuracy Internal Crystal Oscillator (OSC32K). This configuration produces the lowest power consumption. It can also use other clock sources provided by the Generic Clock module (GCLK), or an external 32.768 kHz crystal connected to the XIN32 and XOUT32 pins, along with any required load capacitors.

The RTC has three modes:

  • 32-bit Counter
  • 16-bit Counter
  • Clock/Calendar

32-bit Counter

The counter will increment until it reaches the top value of 0xFFFFFFFF and then wrap to 0x00000000. This overflow can generate an interrupt. It can also count up to the value programmed into the compare register (four configurable compare values). This can also produce an interrupt. The counter can be automatically cleared on a match.

32-bit Counter

16-bit Counter

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.

The counter value is continuously compared with the 16-bit compare registers (six configurable compare values). When a compare match occurs, the 'Compare n' interrupt flag is set.

16-bit Counter

Clock/Calendar

The time and date can be read from or written to the Clock Value register (CLOCK) in a 32-bit time/date format. The clock value is continuously compared with the 32-bit Alarm register (ALARM0). When an alarm match occurs, the 'Alarm 0' Interrupt flag is set.
Time is represented as:

  • Seconds
  • Minutes
  • Hours (12- or 24-hour format)

Date is represented as:

  • Day (The numeric day of the month)
  • Month (The numeric month of the year)
  • Year (A value counting the offset from a reference (defined in software))
  • Automatically adjusted for leap years

Clock/Calendar