Real Time Clock Circuit Design Guide
A real time clock keeps time while the rest of the system is unpowered, which means it spends most of its life running from a small battery and drawing almost nothing. Every microampere matters, every picofarad of load capacitance shifts the frequency, and the two constraints together make the clock circuit one of the more delicate parts of a board design.
What a Real Time Clock Does
The device counts seconds, minutes, hours and often a date, and presents them over a serial bus. Its accuracy comes from a quartz crystal, usually at 32.768 kilohertz because that frequency divides by two fifteen times to give exactly one second and because a tuning fork crystal at that frequency draws very little current.
The clock also provides alarm and wake outputs, and often a small amount of battery backed memory. Those features are why the device is separate from the main processor rather than being a function inside it: the clock keeps running with the processor off, and it can wake the processor when an event is due.
Power consumption is specified in microamperes, and a well designed circuit draws around a microampere from the backup source. At that level a small coin cell lasts for several years, which is what makes the backup practical in equipment that is not serviced regularly.
Crystal Choice and Frequency
crystal oscillator performance at 32.768 kilohertz is dominated by the crystal rather than by the integrated circuit. The parameters that matter are the frequency tolerance at room temperature, the temperature coefficient, the equivalent series resistance and the load capacitance for which the crystal is specified.
Tuning fork crystals have a parabolic frequency versus temperature curve with a turning point near 25 degrees Celsius and a drift of about 0.035 parts per million per square degree away from it. That means a clock that is accurate in an office can lose or gain several minutes a year in equipment that runs hot or cold, and the error is systematic rather than random.
The equivalent series resistance affects the oscillator margin. A crystal with a high resistance needs more drive to start reliably, and a design that uses a low power oscillator with a high resistance crystal may fail to start at low temperature. The integrated circuit datasheet usually specifies a maximum resistance, and it should be respected rather than treated as a guideline.

Load Capacitance and Frequency Accuracy
load capacitance is the total capacitance seen by the crystal, and it determines the actual oscillating frequency. It is made up of the two external capacitors in series plus the parasitic capacitance of the pins and the traces, and the crystal is specified for a particular value such as six or twelve picofarads.
The two external capacitors are usually equal, and their value is chosen so that the total matches the specification. Because the parasitic capacitance is not known exactly, the calculated value is a starting point, and the actual capacitance should be measured or adjusted so that the clock runs at the correct rate. An error of a picofarad at 32.768 kilohertz corresponds to roughly two parts per million, which is over a minute a year.
Capacitor tolerance also matters. Two capacitors with ten percent tolerance can shift the frequency by several parts per million even when the nominal value is correct, and their temperature coefficients add a drift of their own. Where the clock has to be accurate, capacitors with a stable dielectric and a tight tolerance are worth the small additional cost.
Backup Battery and Power Switching
The backup battery has to take over when the main supply falls, and it has to do so without allowing current to flow back into the main rail or through the battery into a shorted load. A diode in each path works but wastes voltage, so most designs use a switch with a low forward drop or an integrated power path in the clock circuit.
The battery voltage has to suit the clock. Some devices accept a coin cell directly and operate down to about 1.3 volts, while others need a higher supply and will not switch over until the main rail has fallen below the battery. Checking the switchover behaviour on a prototype, by slowly lowering the main supply, confirms that the clock keeps running throughout.
Backup battery life is set by the clock current plus any leakage. A leakage path through contamination on the board can be comparable to the clock current, which is why the battery current should be measured in the finished assembly rather than calculated from the datasheet. A current that is higher than expected usually indicates a leak path or a bus that is being driven during backup.

Timekeeping Accuracy and Temperature
timekeeping accuracy over the product life depends on three contributions: the initial tolerance of the crystal, the temperature drift and the ageing of the crystal. Initial tolerance is removed by calibration at production, ageing is slow and predictable, and temperature drift is the dominant term in equipment that operates over a wide range.
Compensation is possible in two ways. The clock circuit can measure its own temperature and apply a correction to the divider, which requires a temperature sensor and a calibration curve. Alternatively, the system can correct the clock periodically from an external time reference, which is the approach used in anything connected to a network.
Where neither is available, the design should at least keep the crystal at a stable temperature. Placing the clock and its crystal away from heat sources and away from the main processor reduces the temperature swing, and a small thermal mass around the crystal smooths the short term variations. Neither measure removes the drift, but both reduce it.
Layout of the Oscillator
The oscillator pins are high impedance and sensitive, so the crystal and its capacitors must be placed as close to the device as the layout allows, with short and direct connections. Any additional trace length adds capacitance and picks up interference from nearby signals, both of which affect the frequency and the stability.
Guard the oscillator from digital switching. Route no clock, data or switching supply trace under the crystal or between the oscillator pins, and keep a quiet ground area beneath the crystal on the layers below. Where the board has a ground plane, connect the crystal ground pins to it with short, direct vias.
The capacitors should return to the same ground point as the clock device, not to a distant part of the plane. A ground difference between the two capacitors appears as a change in the effective load capacitance, and the resulting frequency shift is small but permanent. Our guide to ferrite bead selection covers the related question of keeping switching noise out of a quiet supply.
Timekeeping in Firmware
The registers of a real time clock are usually in binary coded decimal, which requires conversion before use. Reading the registers while the clock is updating can produce a value that mixes the old and new seconds, so most devices provide a flag that indicates an update in progress, and the read should be repeated if the flag is set.
Setting the clock requires care with the divider chain. Many devices need the divider to be reset when the time is written, and omitting that step produces a clock that is offset by a fraction of a second or that counts erratically for the first second after being set.
Where the clock is used to timestamp events, the firmware should also record whether the time was set from an external reference. A timestamp from an unset clock is worse than no timestamp, because it looks plausible. Marking the time as valid only after it has been set once removes that ambiguity.
Verification and Common Faults
Verify the oscillator by measuring the frequency at the output pin, if one is provided, or by comparing the clock against a reference over several days. A short measurement is not enough to detect a few parts per million, and the error that matters accumulates slowly. Recording the difference each day shows both the rate and the direction of the error.
A clock that stops when the main supply is removed usually has a backup switching problem rather than a battery problem. Measuring the voltage at the clock supply pin during the transition shows whether it dips below the operating minimum, and the cause is often a capacitor that discharges through the wrong path.
A clock that loses several minutes a year but keeps perfect time in a temperature controlled room has a temperature drift problem, and no amount of layout work will fix it. A compensated clock, or periodic correction from a network reference, is the answer. The production checks that catch assembly problems before they reach the field are listed in our guide to PCB design release checklist, and the partition between the quiet oscillator area and the rest of the board follows the rules in mixed signal board design.
FAQ
How accurate is a typical real time clock? With an uncompensated tuning fork crystal, expect a few minutes a year over a moderate temperature range. A compensated clock improves this by an order of magnitude.
Can I use the main processor clock to keep time? Only while the processor is powered. A real time clock is used precisely because it continues to run when everything else is off.
How do I choose the oscillator capacitors? Match the total load capacitance to the crystal specification, including the parasitic capacitance of the pins and traces, then verify by measuring the frequency over a period of days.



