Inaccurate RTC

Measured over 24 hours with a time reference device (GPS clock) the MkrZero RTC is grossly out of whack, exhibiting a 30 ppm drift rate (a mediocre watch would be in the 5 to 1 ppm range).
I know the RTC can be frequency-adjusted but the RTCZero library does not offer that option and I have a hard time turning what I read in the SAMD21 documentation into effective instructions.
Can anyone help ?

Almost 600 reads and no answer probably signals that this topic is of little interest to Arduino users. However I’ll report what I have found so far, hoping that it may be useful to another lonesome maker somewhere, who foolishly believes, like I did, that the Mkr0 RTC may be of any use.

1- Having tested 3 Mkr0s I confirm the poor performance of the combination crystal + RTC (the RTC is not the only one to be blamed).

2- The frequency correction register may be read or written to by using the variable name : REG_RTC_FREQCORR, to be found well hidden in (hold your breath):

c:\Users\username\AppData\Local\arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0\CMSIS\Device\ATMEL\samd10\include\instance\rtc.h

and defined as :
#define REG_RTC_FREQCORR (*(RwReg8 *)0x4000140CU) /**< \brief (RTC) Frequency Correction.

It can take a value of +/-127, each unit adding or substracting 1 ppm to the oscillation period.

3- Regardless of how the circuit is powered, battery, USB, Vin, every time an SD card is inserted the RTC is reset to 0 (date 00/00/00, time 00 :00 :00).

4- Every time the Mkr0 is reset (for example when loading a program) ) the RTC « loses » about 1.6 second.

5- Minor, but not mentioned in the RTC0 lib : the RCT codes the year value on 6 bits, ie 17 is fine but 2017 is not. The SAMD21 documentation defines Year as « a value counting the offset from a reference value that must be defined in software » (and must be a leap year if you want leap years to be handled properly).

Conclusion :

  • If you need accurate, dependable time keeping don’t count on the the Mkr0 RTC. A DS3231 rated at 2ppm and easily adjustable to less than .5 ppm is a better choice and with a 3-volt back up battery it is totally immune to the processor’s hiccups.

  • On the other hand if all you need is an alarm defined as « 3 days, 6 hours and 27 seconds from now, give or take 15 seconds » the RTC is fine (but don’t fiddle with that SD card !).

Hi jmkymoe

Thanks for your post here. I just started working with the MKRZero and the internal RTC. Not much information on the web and your post also does not sound that good regarding the internal RTC. At least it contains a lot of usefull hints.

One strage thing for a RTC beginner (like me): I have to install the external lib RTCZero, right?

Oliver

if timing is so critical then it makes more sense to add ethernet or WiFi and use NTP as the source.

No more worries.

Even most of today's computers / tablets / phones will loose or have errors in timing were it not for the fact that most get it directly from the internet.

Seen a tablet loose an hour after not being connected for a few weeks and self rectify the moment its switched on with an available connection.

Seen computers loose all track of date and time when the internal battery gets to replacement point.

Its not a new issue with technology or Arduinos in particular.

Thanks for a very helpful post, jmkymoe ! It answered all my questions but one:

Does anyone know if you can power the RTC with a dedicated battery? Not the Li-Po that powers the whole board, but a separate coin cell for the RTC only?

hi mhopeng,

You can buy lots of RTC's that are battery powered, just look on eBay or Amazon, anywhere they sell Arduino or Arduino like boards should have some like Adafruit or SparkFun and many others. They are powered by its own battery (may not be included). The units I have are Tiny RTC I2C module but they are based on the DS1307 chip and use a CR1225 battery.

ltheoret

Hi

Just wanted to add have found the same issues in playing about. The RTC of the SAMD21 loses time during a reset (a few seconds). I also don't see a battery backup really being an option either to maintain the RTC as if power is removed the battery would try and power the entire controller and keep it running, and going flat pretty quickly.

The RTC could just be considered temporary during operation and set from a known good source after power up or reset (such as NTP) if available, however in that case it isn't really providing much more than a software solution RTC which seems a shame.

In terms of accuracy of the SAMD21 RTC that is of course dependant on the crystal and matching capacitors and I've got around a second a day which seems about right for the crystal I'm using which is spec'd at 10ppm on a home built board (Link to board in the Gallery). I expect though crystals generally on bought Arduinos or clones may not be as well specified.

My own solution I 've added a DS3231 which resolves all the issues, but I was wondering if I could do away with it and use the SAMD21 RTC but alas not. It's a shame as the Dallas chip is around twice the price of the SAMD21 chip!