Quickly Implement Efficient Real-Time Clock/Calendar Functionality in Embedded Designs

By Steve Leibson

Contributed By Digi-Key's North American Editors

Many embedded applications need to know the time for actuating particular tasks at a certain time and date, or to time stamp events, or both. RTCC (real time clock and calendar) chips to perform this function have been available for decades, but designers are challenged to reduce component count and footprint, while minimizing power consumption and design time.

Integrated RTCC devices and innovative modules are meeting these challenges.

This article discusses how to select an RTCC chip and design it into an embedded system quickly, while minimizing space and power consumption. It will include a discussion of MCUs with built-in RTCCs, and the use of available RTCC modules to aid in prototyping with surface mount RTCs and other components.

RTCC chips incorporated into modules are typically supported by Arduino libraries and Raspberry Pi Raspbian driver overlays, which can make embedded experimentation and prototyping with these devices easier.

The role of RTCCs

Many embedded applications need to keep track of time relative to the real world with minimal power consumption while freeing up the main processor for other tasks.

However, by itself, an RTCC chip can’t do much. It requires an accurate crystal for timekeeping—perhaps a temperature compensated crystal for very accurate timekeeping—and backup battery power so that time can be tracked even when the embedded system has been powered down. These auxiliary components define the RTCC’s ability to perform its two main tasks:

  1. To consistently keep accurate time and date in all conditions
  2. To draw minimal power when the rest of the embedded system is powered off

Some microcontrollers incorporate RTCCs

Some microcontrollers, such as the Microchip Technology 32-bit PIC32MZ2064DAA288 microcontroller, incorporate an internal RTCC block. It might seem like a great idea to use such a device for the design of a system that requires accurate timekeeping, especially since the PIC32MZ2064DAA288 microcontroller will automatically switch internal power to its battery input pin (VBAT) when there’s insufficient voltage on the microcontroller’s normal power supply pins (VDDCORE and VDDIO) to power the device.

However, there are some additional challenges with such devices that directly relate to the RTCC’s two essential tasks listed above: accurate timekeeping and low power operation.

First, the PIC32MZ2064DAA288 microcontroller’s RTCC block will require a 32768 Hertz (Hz) crystal attached to its two secondary oscillator pins to maintain accurate time while the microcontroller is powered down. Although it’s possible to use the microcontroller’s main clock oscillator to operate the RTCC block, that oscillator stops running when the microcontroller is in deep sleep mode.

The on-chip RTCC incorporates a calibration register, and Microchip provides a calibration procedure that can reduce timekeeping error to 0.66 seconds per month for crystal oscillator frequencies off by as much as 260 parts per million (ppm). However, the fixed calibration does not account for temperature variation, which can also affect oscillator frequency and therefore timekeeping accuracy.

Secondly, the microcontroller doesn’t completely power down when it switches to the battery supply, except for the RTCC block. Other blocks in the microcontroller may or may not be enabled during battery operation, as controlled by software. The challenge created here is that battery drain and life becomes software dependent.

This challenge is not unique to the PIC32MZ2064DAA288 microcontroller. It’s going to occur with any microcontroller that incorporates an RTCC block. Using a separate RTCC chip overcomes the issue by cleanly isolating the timekeeping function from the microcontroller, and it’s also the only design choice when the microcontroller has no internal RTCC.

RTCC chips and modules

Design engineers have been using separate RTCC chips to keep time in a variety of embedded and computing applications for decades. While several IC vendors now offer such chips, surface mount technology (SMT) has complicated the evaluation of RTCC chips because the devices cannot easily be hand soldered or socketed.

A good solution is to use low cost modules based on these RTCC chips that eliminate the prototyping challenges associated with small surface mounted ICs. These modules also incorporate batteries, usually coin cells, to maintain power even while the main system is powered down.

A good example of such a module is the 255 Chronodot from Adafruit (Figure 1). Such modules are handy for evaluating RTCC chips, for breadboarding and prototyping, and even for volume manufacturing in many cases.

Image of Adafruit’s 255 Chronodot

Figure 1: Adafruit’s 255 Chronodot incorporates an RTCC chip and battery on a through hole module. (Image source: Adafruit)

Table 1 lists six different RTCC modules based on three different RTCC chips from two IC vendors.

RTCC Module RTCC Chip Interface Battery Battery Life Min (Typ)
DFRobot DFR0151 Maxim DS1307 I²C CR1225 9 (17) years
SparkFun BOB-12708 Maxim DS1307 I²C CR1225 9 (17) years
Adafruit 3103 Maxim DS3231 I²C CR1220 NA
Adafruit 255 Chronodot Maxim DS3231 I²C CR1632 8 years
Maxim DS3231MPMB1# Maxim DS3231 I²C CR1025 NA
STM STEVAL-FET001V1 STMicro M41T62 I²C External NA

Table 1: Six RTCC modules illustrate the wide availability and variety of RTCC modules. (Data source: Digi-Key Electronics)

RTCC modules like the six listed in Table 1 make it easy to add timekeeping to prototype systems. A closer look at how these modules are designed reveals useful information when developing a board that incorporates the underlying RTCC chip.

The first thing to note from Table 1 is that all of these RTCC modules share one thing in common, an I2C interface. Early RTCC chips from the 1970s emulated small SRAMs using parallel address and data buses. That was an era in which parallel microprocessor buses were common, and on-board serial protocols had not yet become widespread.

Today, chip-to-chip serial protocols, particularly I2C, is the interface of choice for peripherals that require relatively little bandwidth. RTCC chips certainly qualify because very few bytes are required to transfer the date and time information.

The first two RTCC modules shown in Table 1, the DFR0151 from DFRobot and the BOB-12708 from SparkFun, are both based on the DS1307 RTCC chip from Maxim Integrated, which is an 8-pin device. Because of its popularity, there are Arduino libraries and a Raspberry Pi Raspbian driver overlay available for modules based on this chip.

The DS1307 RTCC has separate pins for the power supply rail and the battery to provide automatic switching between the embedded system’s power supply rail and the backup battery when the system power fails (Figure 2).

Diagram of Maxim Integrated’s DS1307 RTCC chip

Figure 2: Maxim Integrated’s DS1307 RTCC chip automatically switches from VCC to VBAT when the VCC pin voltage drops below approximately 4.5 volts. (Image source: Maxim Integrated)

Figure 2 also shows the connection between the DS1307 RTCC chip and a crystal. For RTCC chips, this crystal is almost always an inexpensive 32768 Hz watch crystal, such as the WATCH-2X6 from IQD Frequency Products. This crystal introduces two new factors to consider when designing with RTCC chips.

The first factor is crystal stability over temperature. Most RTCCs use "tuning fork" crystals that were originally designed for wristwatches. These crystals deviate from their rated frequency over temperature (Figure 3).

Graph of resonant frequency of a 32768 Hz crystal

Figure 3: The resonant frequency of a 32768 Hz crystal varies with temperature, which will affect the RTCC’s timekeeping accuracy. (Image source: IQD Frequency Products)

The IQD WATCH-2X6 crystal’s resonant frequency changes over temperature, which alters the frequency of the oscillator and results in a timekeeping error. Note that a 20 ppm shift in oscillator frequency translates into approximately one minute of timekeeping error per month.

The second factor is hidden by the oversimplification of the connection between the crystal and the RTCC chip in Figure 2. The crystal input pins of RTCC chips typically have very high impedance, making the watch crystal’s leads and the pc board traces act like an antenna. This “antenna” can couple high frequency signals and noise from the rest of the system into the RTCC’s internal crystal oscillator.

Any noise coupled through the traces between the watch crystal and the RTCC chip can cause extra transitions in the RTCC chip’s oscillator circuit, which can cause the clock to run fast. The solution is careful pc board layout. This includes placing the crystal as close as possible to the RTCC chip’s oscillator pins, and placing a ground plane beneath the crystal input pins and the entire body of the watch crystal (Figure 4).

Diagram of crosshatched keep out area beneath the RTCC package

Figure 4: Careful pc board layout over a ground plane prevents unwanted noise from affecting the timekeeping accuracy of an RTCC chip. (Image source: Maxim Integrated)

Additionally, Figure 4 shows a crosshatched keep out area beneath the RTCC package to prevent closely spaced traces from coupling noise to the RTCC chips crystal input pins. If possible, add a guard ring on the component layer of the pc board that surrounds the crystal and the RTCC chip’s crystal input pins to help prevent noise from affecting the timekeeping accuracy.

Getting the watch crystal off of the pc board and into the chip

To circumvent some of the challenges relating to pc board layout for an external crystal, opt for the M41T62 RTCC from STMicroelectronics with a built in crystal. This RTCC chip is available on STMicroelectronics’ STEVAL-FET001V1 evaluation board, which has the footprint of a 24-pin DIP. A schematic for this board appears in Figure 5. There is an Arduino library and a Raspberry Pi Raspbian driver overlay available for the M41T62.

Diagram of STMicroelectronics M41T62 RTCC chip

Figure 5: The STMicroelectronics M41T62 RTCC chip (center) is available on the STEVAL-FET001V1 evaluation board, packaged as a 24-pin DIP. (Image source: STMicroelectronics)

As the schematic shows, the M41T62 has only a VCC pin. It does not have a separate VBAT pin to switch to when the main power rail fails because the device, which measures only 1.5 x 3.2 mm, is designed to be used in wearable devices and digital cameras. In these embedded applications, the battery is typically the only power source and space is at a premium.

Note that it’s also possible to use a supercapacitor as the power source for the M41T62. In an embedded system, the system supply or a charger can be connected to the M41T62’s VCC pin through a blocking diode, D1 (Figure 6).

The diode would need to be a low leakage type like the 1N4148WS shown in Figure 5 above to prevent discharging of the supercapacitor back through the system power supply when rest of the system is powered down.

Diagram of rechargeable supercapacitor powering the M41T62 RTCC chip

Figure 6: It’s possible to use a rechargeable supercapacitor to power the M41T62 RTCC chip. (Image source: STMicroelectronics)

Temperature compensation tames the crystal

Three of the RTCC modules listed in Table 1 (the Adafruit 3013, the Adafruit 255 Chronodot, and the Maxim DS3231MPMB1#) are based on Maxim’s DS3231 RTCC chip (Figure 7). Along with an integrated crystal, the device includes a temperature sensor, which explains the device’s long official name, “Extremely Accurate I²C-Integrated RTC/TCXO/Crystal.”

Diagram of Maxim DS3231 RTCC chip

Figure 7: The DS3231 RTCC chip integrates the 32768 Hz watch crystal, a temperature sensor, and a switched capacitor array to keep the device’s timekeeping accurate to within ±2 minutes per year. (Image source: Maxim Integrated)

As shown in the block diagram, the DS3231’s temperature compensated crystal oscillator (TCXO) consists of the internal crystal, a temperature sensor, and a switched capacitor array. Like the DS1307 RTCC, the DS3231 also has separate pins for the main power (VCC) and the backup battery (VBAT).

As with the STMicroelectronics M41T62 RTCC chip, the DS3231 RTCC chip dispenses with the layout challenges of an external crystal. Its TCXO reduces the timekeeping accuracy variation caused by temperature swings. The DS3231’s internal TCXO holds the timekeeping accuracy of the device to within plus or minus 2 minutes per year over a very wide operating temperature range of -40°C to +85°C.

Because of its popularity, there are several Arduino libraries and a Raspberry Pi Raspbian driver overlay available for modules based on the DS3231 RTCC chip.

How long will the battery last?

Batteries are maintenance items that won’t last forever. When adding an RTCC to an embedded design, it’s important to note the battery current required by the RTCC chip to appropriately size the backup battery.

Battery life in an RTCC application will be determined by the current drain of the RTCC chip while it’s keeping time, the minimum operating voltage required by the RTCC chip, and the amount of time the battery will be able to supply the required current before its output voltage drops below that minimum operating voltage (Table 2).

RTCC Chip Battery Current (nA) Typ (Max)
Maxim DS1307 300 (500)
Maxim DS3231 840 (3000)
STMicro M41T62 5000 (7000)

Table 2: Battery supply current ratings for RTCC chips help you size the appropriate backup battery. (Data source: Digi-Key Electronics)

For the RTCC modules shown earlier in Table 1, the backup batteries have already been selected. Some of the module vendors include battery life numbers on the module data sheets, also shown in Table 1. Lithium coin cells are currently the battery type of choice for these modules. The table diameters vary at 10, 12, and 16 mm. Granted, the larger the battery capacity, the more space and weight it tends to add, but the clear upside is longer battery life for a given current draw.

Conclusion

Care should be taken when selecting RTTC devices, when choosing the companion crystal and battery to ensure accurate operation, and when laying out the pc board. Alternatively, available modules based on RTCC chips provide a shortcut for breadboarding and prototyping, greatly reducing development time.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Steve Leibson

Steve Leibson was a systems engineer for HP and Cadnetix, the Editor in Chief for EDN and Microprocessor Report, a tech blogger for Xilinx and Cadence (among others), and he served as the technology expert on two episodes of “The Next Wave with Leonard Nimoy.” He has helped design engineers develop better, faster, more reliable systems for 33 years.

About this publisher

Digi-Key's North American Editors