Choosing the right clock chip (often called a Real-Time Clock or RTC) is a critical decision for many embedded projects. The "right" choice depends entirely on your project's requirements.
Here is a structured guide to help you select the appropriate clock chip.
The Quick Decision Guide
For those who want a fast answer, here's a flowchart to narrow down your options:
Step 1: Ask the Fundamental Questions
Start by defining your project's needs. The answers will immediately rule out many options.
-
What is the primary purpose of the clock?
-
Basic Timekeeping: Logging data with a timestamp, scheduling daily events (e.g., turning a light on at 7 PM).
-
High Precision: Scientific instruments, data acquisition systems, or network synchronization where even a few seconds of drift per day is unacceptable.
-
Time Stamping: Recording the exact time of an external event (e.g., a power failure, a button press).
-
Calendar/Alarms: Generating periodic interrupts (every second, minute, etc.) to wake up a microcontroller from sleep.
-
-
What is your power source?
-
Mains Powered: (e.g., plugged into a wall). Power consumption is less critical. You can prioritize features and accuracy.
-
Battery Powered: This is the most common scenario for RTCs. Ultra-low power consumption is paramount. The RTC must keep time for months or years on a small backup battery (like a coin cell).
-
-
What is your accuracy requirement?
-
Low: Drifting a few seconds per day is acceptable (e.g., a simple kitchen timer).
-
Medium: Drifting a few seconds per week is acceptable (e.g., a data logger that is calibrated occasionally).
-
High: Drifting less than a second per month is required (e.g., a clock that never needs setting, a financial transaction logger).
-
-
What microcontroller interface do you prefer?
-
I²C (Inter-Integrated Circuit): The most common choice. Uses 2 pins (SDA, SCL). Simple but can be slower. Great for most applications.
-
SPI (Serial Peripheral Interface): Faster and more robust over longer distances. Uses 3 or 4 pins (MOSI, MISO, SCK, CS). Good if you need to read time data very quickly or if you're in a noisy environment.
-
Parallel: Very rare for modern RTCs. Used in older systems.
-
-
Do you need additional features?
-
Battery Backup Input: A pin for connecting a coin cell or supercapacitor.
-
Temperature Compensation: Crucial for high accuracy. The chip measures its own temperature and adjusts its internal oscillator to counteract drift.
-
Programmable Alarms: Multiple alarms that can trigger an output pin to interrupt the microcontroller.
-
Square Wave Output: A configurable frequency output (e.g., 1Hz, 32.768kHz) that can be used as a clock signal for other chips.
-
RAM: Some RTCs include a few bytes of non-volatile RAM that persists on the backup battery. Useful for storing small amounts of critical data.
-
Power-Fail Detect: A circuit that monitors the main power supply and can generate an interrupt before it fails completely.
-
Step 2: Understand the Key Specifications
When you look at a datasheet, focus on these parameters:
-
Accuracy (Drift): Measured in parts per million (ppm).
-
Seconds drifted per day = ppm × 86,400 / 1,000,000
-
Example: A 20 ppm chip can drift
20 * 0.0864 = ±1.73 seconds per day
. -
Crystal-based RTCs (like DS1307, PCF8563): Typically ±20 ppm or worse (±1.7 sec/day). Highly dependent on temperature and crystal quality.
-
Temperature-Compensated RTCs (like DS3231): Typically ±2 ppm (±0.17 sec/day). The gold standard for affordable accuracy.
-
-
Supply Current (Power Consumption):
-
Timekeeping Current: The current drawn by the RTC when it's only keeping time on battery backup. This is the most important number for battery life.
-
Active Communication Current: The current drawn when you are reading from or writing to the RTC via I²C/SPI. This is usually much higher but happens infrequently.
-
-
Operating Voltage:
-
Ensure the RTC can run at the same voltage as your microcontroller (e.g., 3.3V or 5V). Many modern RTCs work from 1.8V to 5.5V.
-
Step 3: Review Common RTC Chips & Their Best Use Cases
Here are the most popular RTC chips categorized by their strengths.
Category 1: The "Good Enough" Standard (I²C, Low Cost)
-
DS1307:
-
Pros: The classic, well-understood, very cheap, includes 56 bytes of RAM.
-
Cons: Low accuracy (±20 ppm or worse, so ~1-2 seconds drift per day), no temperature compensation.
-
Best For: Mains-powered projects, hobbyist projects where cost is the primary driver and accuracy isn't critical.
-
-
PCF8563 (or the compatible AT24C32):
-
Pros: Extremely low power consumption (~0.25 µA typical), very cheap, common on breakout boards.
-
Cons: Low accuracy (similar to DS1307), no built-in RAM.
-
Best For: Battery-powered projects where long battery life is more important than high accuracy.
-
Category 2: The "High-Accuracy" Champions (Temperature Compensated)
-
DS3231 (I²C) / DS3234 (SPI):
-
Pros: Excellent accuracy (±2 ppm, which is about ±1 minute per year!), built-in temperature-compensated crystal oscillator (TCXO). The DS3231 is the industry workhorse.
-
Cons: Higher cost, higher power consumption (~1 µA timekeeping current) than the PCF8563, but still very good for battery use.
-
Best For: The default choice for most serious projects. Perfect for data loggers, clocks you never want to set again, and applications where accuracy matters. If you're unsure, get a DS3231.
-
Category 3: The "Ultra-Low-Power" Specialists
-
RV-8803-C7:
-
Pros: Exceptionally low current (~0.045 µA), higher accuracy than standard crystals (±3.5 ppm at 25°C), and excellent temperature stability.
-
Cons: More expensive, less common on hobbyist breakout boards.
-
Best For: Ultra-long-life battery applications (10+ years on a coin cell) where you still need good accuracy.
-
Category 4: Microcontroller with Integrated RTC
-
Many modern MCUs (like ESP32, STM32, RP2040) have a built-in RTC peripheral.
-
Pros: No external component needed, zero additional cost.
-
Cons: Crucially, it needs an external 32.768 kHz crystal to be accurate. The accuracy of this crystal is poor (often ±50 ppm or worse). It also loses time immediately when main power is cut, unless you add a battery backup circuit.
-
Best For: Quick prototypes, applications where approximate timing is okay, or when you are willing to add the external crystal and battery circuitry.
-
Step-by-Step Selection Algorithm
-
Is the project battery-powered?
-
YES: Go to Step 2A.
-
NO (Mains-Powered): Go to Step 2B.
-
-
A) For Battery-Powered:
-
Is high accuracy (±2 ppm) required?
-
YES: Choose DS3231 (if power budget allows) or RV-8803 for the best balance of accuracy and power.
-
NO (Longest battery life is key): Choose PCF8563 or RV-8803.
-
-
-
B) For Mains-Powered:
-
Is high accuracy required?
-
YES: The choice is easy: DS3231/DS3234.
-
NO: Choose the most cost-effective option, usually DS1307 or PCF8563.
-
-
-
Check Interface (I²C vs. SPI):
-
Most projects use I²C (DS1307, PCF8563, DS3231). Choose SPI (DS3234) if you need the speed or robustness.
-
-
Verify Features:
-
Do you need extra RAM? (DS1307 has it).
-
Do you need multiple, very precise alarms? (DS3231 is excellent).
-
Final Recommendation
For 90% of projects, the DS3231 is the best choice. It offers an incredible combination of high accuracy, low enough power for battery backup, a standard I²C interface, and is readily available on cheap breakout boards. It removes the worry of time drift almost entirely.
Start with a DS3231 unless you have a specific, overriding requirement for ultra-low power (then choose PCF8563/RV-8803) or absolute lowest cost (then choose DS1307).