SAM D21 Real-Time Counter (RTC) Overview

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.


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.



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

 Learn More

RTC Configuration
Learn more >
RTC Example Project
Learn more >
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.