Real-Time Clock technology maintains accurate time in electronic devices. It studies clock operation and integration in systems.
Even with the computer turned off for weeks, when we turn it back on the clock shows the correct time. This is thanks to the RTC (*Real-Time Clock*), a small circuit that keeps counting time, usually powered by a button cell battery even when the rest of the system is off. It provides seconds, minutes, hours, day, month, and year, and consumes very little [1][2][3][4].
An RTC contains an oscillator, a frequency divider, a set of counters, and an interface to the processor.
- Quartz oscillator at $32\,768\ \mathrm{Hz}$: the tuning fork quartz is small and inexpensive, and oscillates at $2^{15}$ Hz.
- Binary divider: $15$ stages each divide by two, and from the frequency of $2^{15}\ \mathrm{Hz}$ an impulse of $1\ \mathrm{Hz}$ (one second) is obtained.
- BCD format counters (binary-coded decimal) for seconds, minutes, hours, day of the week, day of the month, month, and year, with handling of months of different lengths and leap years.
- Registers to set and read the time, for programmable alarms, and for status.
- Interface I²C or SPI to the microcontroller, with an interrupt output for the alarm and a square wave output [1][2][3][4].
The frequency is a power of two: $32\,768 = 2^{15}$. A fifteen-stage binary counter, simple and very low power, divides the frequency exactly to obtain one second. At higher frequencies the circuit consumption would be greater, and at lower frequencies the quartz would be too large. Tuning fork quartz crystals at $32.768\ \mathrm{kHz}$ are produced in large quantities at low cost [1][2][3].
The RTC has an input for a backup battery (usually a lithium button cell of $3\ \mathrm{V}$, type CR2032, or a supercapacitor). A circuit automatically switches between the main power and the battery when the former is absent. The current drawn in backup mode is on the order of microamperes or less, and the battery lasts for years. Some RTCs also have a small RAM powered by the battery, to retain data when the system is off [1][2][3][4].
The quartz frequency changes with temperature according to a parabolic law, with a maximum near $25\ ^\circ\mathrm{C}$: $\Delta f/f \approx -0{,}034\ \mathrm{ppm/K^{2}}\cdot(T - T_0)^{2}$. At $25\ ^\circ\mathrm{C}$ the typical error is $\pm20\ \mathrm{ppm}$ for an inexpensive quartz, and worsens at the extremes. Precision RTCs are temperature compensated (TCXO): an internal temperature sensor and oscillator compensation reduce the error to about $\pm2\ \mathrm{ppm}$ over a wide range. Other RTCs are calibrated with a register that adds or removes pulses [1][2][3].
The ideal model assumes exact counting. In practice, drift caused by the crystal, temperature, and aging accumulates over time, so an RTC without correction can be off by minutes per month. Devices connected to a network periodically correct themselves using synchronization protocols (NTP) or time signals (GPS, radio). Other issues include the battery running out (time is lost), the crystal's sensitivity to shocks, and the need to handle daylight saving time changes and time zones in software, because the RTC counts only the set local time.
An RTC with a crystal at $32\,768\ \mathrm{Hz}$ and a CR2032 battery of $220\ \mathrm{mAh}$ (typical values).
1. Division: $2^{15} = 32\,768$, then $15$ stages each divide by two and yield $1\ \mathrm{Hz}$.
2. With an error of $20\ \mathrm{ppm}$: drift of $20\cdot10^{-6}\cdot86\,400 = 1.73\ \mathrm{s}$ per day, and $20\cdot10^{-6}\cdot30\cdot86\,400 = 52\ \mathrm{s}$ in a month.
3. With a compensated RTC at $\pm2\ \mathrm{ppm}$: $0.17\ \mathrm{s}$ per day and $5.2\ \mathrm{s}$ per month.
4. For an uncompensated crystal at $T - T_0 = 40\ \mathrm{K}$ from the maximum (for example at $65\ ^\circ\mathrm{C}$): $0{,}034\cdot40^{2} = 54\ \mathrm{ppm}$, i.e. $4.7\ \mathrm{s}$ per day, late.
5. With a consumption of $1\ \mathrm{\mu A}$ the $220\ \mathrm{mAh}$ battery lasts $220/0.001 = 220\,000\ \mathrm{h}$, i.e. theoretically $25$ years; in practice, the lifetime is limited by the battery’s self-discharge, at about $5$-$10$ years.
RTCs are used in computers (system clock), phones, data loggers and energy meters (event time recording), access control systems, programmable appliances, alarm systems, and devices that wake up at programmed intervals to save power.
[1] Wikipedia (it): Real-time clock
[2] Wikipedia (en): Real-time clock
[3] Wikipedia (de): Echtzeituhr
[4] Wikipedia (fr): Horloge temps réel
Generating summary…