nenya.me

Electronics

Real-time clock

A real-time clock has become such a basic feature that many microcontrollers, esp. ARMs, have one on-chip. Other microcontrollers will often use a dedicated RTC-IC. Apart from the obvious digital clock, a typical application which requires a RTC is a data logger. You log sensor data together with a time stamp, and that usually comes from a RTC.

Data logger shield for Arduino by Adafruit

The Atmel AVR which is used in the Arduino doesn't have an on-chip RTC. Therefore the designers at Adafruit  included one on their data logger shield (shown right). The big piece of metal at the left is a socket for an SD card to store the data. (SD cards are way cheaper than any other large memories). At the bottom of the picture there's the battery for the RTC, with the RTC itself at the right of the battery.
Adafruit chose the Maxim DS1307 for the data logging shield, and SparkFun  has a breakout board with the DS1307. In my opinion not a very good choice. First, it needs a 5 V supply, so you can't use it with 3.3 V microcontrollers. Also, it only features the clock/calendar, and 56 bytes of RAM. That's it. There are many other (better) RTCs around these days. Let's have a look at one from NXP : the PCF85263A .

The PCF85263A

The PCF85263A is a rather new RTC-IC; the original datasheet is dated 18 April 2014. The data logger shield from Adafruit was probably designed long before that, so that may be an obvious reason why they didn't choose this NXP device. (On the other hand, NXP has had several RTCs in production for many years now, which also outperform the DS1307, like the PCF8583.)

One feature which at first may just be "beh" is the 1/100 second resolution. But it's more useful than you might think. The accuracy of a RTC is determined by the accuracy of its crystal. And crystals typically have a base accuracy of 20 ppm. (Base meaning that you have to add the deviation due to temperature changes to that.) Given that a month has about 2.6 million seconds that means that you can have an error of almost a minute a month. If you want to adjust the clock the resolution dictates the smallest adjustment you can make. Making 100 adjustments of 1/100 of a second will go unnoticed for most applications, while a 1 second adjustment may be noticeable in the data: it can mean that you have the same time twice if you sample at 1 sample per second, or that a second is missing.
That said, the PCF85263A has a calibration register which will adjust the clock for you, once it's being set.

The PCF85263A has several other features the DS1307 lacks, like a watchdog, a stopwatch and a lot more RAM, see the table below. But even ignoring those extra features the PCF85263A costs only a fraction of the DS1307 (prices are also in the table).

The DS1307 versus the PCF85263A

I included another interesting RTC IC, the Microchip MCP79410 in the comparison. Major advantage of the MCP79410 is the presence of EEPROM (Microchip is well-known for its EEPROM products), some of which is protected.

  Maxim
DS1307
Microchip
MCP79410
NXP
PCF85263A
Interface I2C I2C I2C
I2C address 0x68 0x6F/0x57 0x51
Oscillator capacitors Internal External Internal
Resolution 1 s 1 s 1/100 s
RAM 56 bytes 64 bytes 240 bytes
EEPROM 128 bytes
protected EEPROM 8 bytes
Leap year tracking Y Y Y
Watchdog Y
Stopwatch Y
Alarms 2 2
Calibration register Y Y
Supply voltage 4.5V - 5.5V 1.8V - 5.5V 1.8V - 5.5V
Maximum Ibatt. 500 nA 1200 nA 420 nA
In-system battery replacement(note 1) Y Y
Footprint smallest package(note 2) 29.4 mm2 6 mm2 6.8 mm2
Price(notes 3, 4) @ 1 USD 3.27 USD 1.10 USD 0.99
@ 100 USD 2.16 USD 0.81 USD 0.693
@ 2500 USD 1.48 USD 0.80 USD 0.406
Datasheet 14 pages 64 pages 100 pages

Notes:

  1. The DS1307 has a separate pin for the battery, and must have a battery connected at all times to operate. The PCF85263A also has separate pins for battery and VDD, but these can be tied together if you don't use the internal switch. You then OR VDD and VBatt with a double diode.
  2. Including pins
  3. Prices at Digikey for SO-8, 2016-02-03
  4. Price for the MCP79410 includes 2 required 8 pF capacitors.

Conclusion

Apart from a clock/calendar the DS1307 has none of the features the others have, yet it's more than 3 times as expensive. Given that both NXP and Microchip are trustworthy suppliers, which have excellent documentation and support, there's no reason to choose the DS1307 over the PCF85263A or MCP79410. If you want EEPROM the only option is the Microchip, if EEPROM isn't necessary I'd go for the NXP.

Replacing the DS1307

Pinout of the PCF85263A

After reading all this you may want to replace the DS1307 on your device. The good news is that the DS1307 and PCF85263A are pin-compatible. Just remove the DS1307 and solder the NXP in its place. Note that you'll have to make changes in your driver software. For starters the DS1307 and PCF85263A use different I2C addresses, but also their register structure is different.

Update dd. 2015-04-24

A couple of days after I wrote this SparkFun came up with an encryption shield for Arduino, which also features a RTC. Here they chose for the Maxim DS3231M, a RTC which uses a MEMS resonator instead of a crystal. Sounds nice, especially since MEMS resonators are more accurate than their crystal counterparts. There's a big “but”, though: this RTC consumes up to a thousand times more power than a crystal-based one! Granted, that's only when you use the temperature sensor to compensate for temperature variations, but wasn't the high accuracy exactly the point of this device? So, unless you keep it powered all the time, instead of having a RTC whose battery you'll have to replace every 5 to 10 years, here you have one whose battery you'll have to replace every month or so. The DS3231M is also an order of magnitude more expensive than the PCF85263A. Since the PCF85263A also allows you to calibrate it, the DS3231M doesn't really offer an advantage here.