gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:48 am

I made a clock using a Raspberry Pi and an Adafruit SPI OLED display. It can be seen in operation here on Youtube. To make the clock, I followed the instructions in this blog post, and wrote a Python script following the example provided.

The way it works is that the Raspberry Pi boots up while connected to the net and gets the time from an NTP server. Then I log in via SSH, start a screen session and execute the Python script. That gets the clock up and running. I close the SSH connection and disconnect the ethernet cable from the Pi and position it where it needs to go.

The contraption runs fine for the most part, but I have found that whatever (internal/software) clock the Pi is using isn't very accurate. Every day the Pi drifts forward by ~12 seconds. So if I sync the clock at 6AM on day 0, at 6AM (per the NTP server and a GPS clock I made with an Arduino) the Pi shows 06:00:12 on day 1, 06:00:24 on day 2, 06:00:36 on day 3, and so on.

I was expecting the Pi to be perhaps may be a bit more accurate than drifting half-a-second every hour (~140ppm!). The easy (offline) solution is to hook up an RTC like the DS1307 (~23ppm) or DS3231 (~2ppm) on an I2C bus and sync the clocks every so often. That's not a concern.

My question is: Is the Raspberry Pi really this bad (~140ppm) at keeping track of time on its own?

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:07 am

A first glance that looks terrible, however having had a look at CPC's web site, they offer 15ppm to 60 ppm with a crystal advertised as a watch component at 20 ppm. So thats only 7 times more accurate than a RPi.
>)))'><'(((<

User avatar
jojopi
Posts: 3079
Joined: Tue Oct 11, 2011 8:38 pm

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 11:47 am

If you think about it, 150ppm would be very good accuracy for measuring distance, mass, voltage, temperature, or nearly any other property. It would even be okay for measuring time, if it were not for the fact that we have more accurate clocks to compare against.

Errors around 200ppm are normal for general-purpose high-frequency crystals, and the better 32768Hz watch crystals are usually around 20ppm. To improve on that you have to go to temperature-controlled or -compensated oscillators.

You can buy rubidium atomic oscillators on ebay for about $100. They are like 2ppb but draw 10W.

User avatar
RaTTuS
Posts: 10415
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 11:52 am

most PC's when not connected to the internet drift more than that TBH
they all need syncing on a regular basis [YMMV]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

jfornango
Posts: 113
Joined: Fri Sep 14, 2012 7:46 pm
Location: St. Louis, MO USA
Contact: Yahoo Messenger

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 1:30 pm

It was my understanding that the RPi didn't have an RTC on board. If that is the truly the case, then I wouldn't expect any level of accuracy without an external time-sync (read "NTP Server"). Even your GPS Clock solution doesn't do terribly well at actual time tracking. It just used a differential signal to determine how far away from the satellite you are.

In fact, most computers these days have terrible hardware drift. The industry makes an assumption that if you care about time, you'll be hitting an external reference (again, read "NTP Server").

I just got my RPi in yesterday, and I'm already planning some basic hardware additions. I've already installed the P6 header, and I'll be adding a DS1307 pretty quick.
I'm only wearing black until they find something darker.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 2:01 pm

I've had to fight this problem in industry.

If your customer has paid £10k for your kit, and is being paid a million or two to carry out a 3,000 hour test, they get rather annoyed when the data log only shows 2,999.5 hours of testing.

The problem in that case was not so much that there was a 150ppm error, it was that the clock doing the logging was on one PC, and the clock doing the test timing was on another. The trick is to use the same clock for both or to synchronise the clocks, and it is not always easy to accomplish, especially when the customer can see any clock jitters down to fractions of a second and will complain about those too.

Almost every other physical variable is only measurable to around 0.1% unless you are the NPL. Temperature for instance is horribly inaccurate: 1C is good, 0.1C requires great care, and thermal resistance means you are almost certainly losing 2-4C between the surface you are testing and the probe. But time needs incredible accuracy in quite ordinary circumstances.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:03 pm

Most Pis will have a full time internet connection when running and will be split second accurate. Back in the bad old days before regular internet connectivity, PC clocks that gained or lost more than a minute a day weren't unknown. I'd say 12 seconds a day is pretty good without NTP to keep it in line.

All three of my Pis are connected to the 'net and all three of them are to within the second.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

lewmur
Posts: 368
Joined: Sun Dec 25, 2011 3:20 pm
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:07 pm

gragib wrote:I made a clock using a Raspberry Pi and an Adafruit SPI OLED display. It can be seen in operation here on Youtube. To make the clock, I followed the instructions in this blog post, and wrote a Python script following the example provided.

The way it works is that the Raspberry Pi boots up while connected to the net and gets the time from an NTP server. Then I log in via SSH, start a screen session and execute the Python script. That gets the clock up and running. I close the SSH connection and disconnect the ethernet cable from the Pi and position it where it needs to go.

The contraption runs fine for the most part, but I have found that whatever (internal/software) clock the Pi is using isn't very accurate. Every day the Pi drifts forward by ~12 seconds. So if I sync the clock at 6AM on day 0, at 6AM (per the NTP server and a GPS clock I made with an Arduino) the Pi shows 06:00:12 on day 1, 06:00:24 on day 2, 06:00:36 on day 3, and so on.

I was expecting the Pi to be perhaps may be a bit more accurate than drifting half-a-second every hour (~140ppm!). The easy (offline) solution is to hook up an RTC like the DS1307 (~23ppm) or DS3231 (~2ppm) on an I2C bus and sync the clocks every so often. That's not a concern.

My question is: Is the Raspberry Pi really this bad (~140ppm) at keeping track of time on its own?
If all you are off is 12 seconds per day, then that is not bad of a $35 device. Your problem is that you are not re-syncing with NTP.
I know that you want the device to work without the ethernet cable attached, so here is a work around. It seems your device is pretty consistent at being off by 12 seconds each day. So write a routine to "adjust" the clock by .5 seconds each hour. You should still plug in the ethernet cable once in a while to re-sync with NTP.

gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:24 pm

The reason I was surprised by the observed 140ppm (12 seconds per day) accuracy is that I have a bedside clock that's only connected to AC power and it is accurate to better than 1 second per month. I've had this clock for close to 14 years now, so I'm acutely aware of its observed characteristics.

[My house is full of clocks and watches. At last count, I think I had 20 or 23. I need time-keeping devices just as much as I need food, water and air. :ugeek:]

Now I need to find my Adafruit Chronodot DS3231 with temperature compensated crystal oscillator - drifts less than 1 second per month.

On a side-note, does all this mean we shouldn't use our cell phones/smart phones as stop-watches if we need millisecond accuracy? :?

@lewmur

In the past 24 hours, it was off by 11 seconds.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:43 pm

gragib wrote: a bedside clock that's only connected to AC power and it is accurate to better than 1 second per month.
AC power has an incredibly accurate frequency over the long term. They adjust it often so the average is exactly right.

These days even AC powered clocks just have crystals in them and they are as bad as all the rest, but the older ones used to count AC cycles and so were much more accurate.

User avatar
fbutler
Posts: 302
Joined: Thu Mar 15, 2012 4:09 pm
Location: Surrey, England

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:45 pm

gragib wrote:In the past 24 hours, it was off by 11 seconds.
If you want accurate time you could always buy something like this for your Pi:

https://www.modmypi.com/raspberry-pi-ex ... ock-module

gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:48 pm

rurwin wrote:
gragib wrote: a bedside clock that's only connected to AC power and it is accurate to better than 1 second per month.
AC power has an incredibly accurate frequency over the long term. They adjust it often so the average is exactly right.

These days even AC powered clocks just have crystals in them and they are as bad as all the rest, but the older ones used to count AC cycles and so were much more accurate.
That makes so much sense :!:

mind == blown :o

gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:50 pm

fbutler wrote:If you want accurate time you could always buy something like this for your Pi:

https://www.modmypi.com/raspberry-pi-ex ... ock-module
I have an I2C RTC somewhere in my house. I just need to find it.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 4:56 pm

gragib wrote:The reason I was surprised by the observed 140ppm (12 seconds per day) accuracy is that I have a bedside clock that's only connected to AC power and it is accurate to better than 1 second per month. I've had this clock for close to 14 years now, so I'm acutely aware of its observed characteristics.

[My house is full of clocks and watches. At last count, I think I had 20 or 23. I need time-keeping devices just as much as I need food, water and air. :ugeek:]

Now I need to find my Adafruit Chronodot DS3231 with temperature compensated crystal oscillator - drifts less than 1 second per month.

On a side-note, does all this mean we shouldn't use our cell phones/smart phones as stop-watches if we need millisecond accuracy? :?

@lewmur

In the past 24 hours, it was off by 11 seconds.
Bedside clocks are often linked to the AC frequency and the generators usually speed and slow the grid system to keep such devices long term accurate. If not they don't usually have a multi-tasking operating system and probably a cheap inaccurate crystal in the way. Digital clocks and watches (and most RTC modules) almost always use 32.768 kHz crystals (you divide it by two 15 times which is dead easy to to with logic chips and it gives a 1 Hz - 1 click per second signal), they are purely used for timekeeping and made by the hundreds of million (by far the most popular frequency for crystals) and are expected to be accurate. Most other crystals don't matter so much so they are often hundreds of PPM away from their nominal frequency. The pi has a multitasking operating system so the timekeeping isn't locked absolutely to the crystal, It usually looks in on a watchdog timer which follows the clock frequency to keep time. They can be miles out if not locked to NTP.

I have a hard time getting the stop watch on my android phone to start and stop to within 5 seconds, damn vague touch screens......
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:02 pm

Will using an RTOS instead of Linux improve the accuracy, or is this a limitation of the hardware?

User avatar
Burngate
Posts: 5972
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:06 pm

rurwin wrote:AC power has an incredibly accurate frequency over the long term. They adjust it often so the average is exactly right.
I read somewhere (long ago and far away...) that every generator control room had an electric clock on the wall.
They could slow down the generator when they had too much load, but had to increase the revs to bring the clock back when the load was light.
So when Corrie finished and the kettles went on, the clocks slowed down, but they'd be right come 7:30 in the morning

gritz
Posts: 449
Joined: Sat Jan 28, 2012 2:33 am

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:28 pm

Burngate wrote:
rurwin wrote:AC power has an incredibly accurate frequency over the long term. They adjust it often so the average is exactly right.
I read somewhere (long ago and far away...) that every generator control room had an electric clock on the wall.
They could slow down the generator when they had too much load, but had to increase the revs to bring the clock back when the load was light.
So when Corrie finished and the kettles went on, the clocks slowed down, but they'd be right come 7:30 in the morning
Yeah, I remember reading something about there being a certain number of cycles in a day - even though the Hz could ebb and flow in the short term. Dad still has a prewar electric clock from his mum's house. I put a new power cord on it about ten years ago and it works a treat (bar not restarting automatically after a power cut).

So there's a project - pick up the 50Hz mains hum via induction and drive a counter from it. RTC with no internet!

gragib
Posts: 99
Joined: Sat Dec 22, 2012 8:09 pm
Location: Calgary, AB, Canada

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:32 pm

gritz wrote:So there's a project - pick up the 50Hz mains hum via induction and drive a counter from it. RTC with no internet!
I approve this message! 8-)

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:41 pm

Get yourself a Radio Controlled Clock - http://cgi.ebay.co.uk/ws/eBayISAPI.dll? ... 0892307808

Richard S.

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:44 pm

gragib wrote:
gritz wrote:So there's a project - pick up the 50Hz mains hum via induction and drive a counter from it. RTC with no internet!
I approve this message! 8-)
Or, go right to the horses mouth, or at least the same trough as the National Grid :http://roevalley.com/newsbrowser/interface/rugby.htm
>)))'><'(((<

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 5:46 pm

Burngate wrote:
rurwin wrote:AC power has an incredibly accurate frequency over the long term. They adjust it often so the average is exactly right.
I read somewhere (long ago and far away...) that every generator control room had an electric clock on the wall.
They could slow down the generator when they had too much load, but had to increase the revs to bring the clock back when the load was light.
So when Corrie finished and the kettles went on, the clocks slowed down, but they'd be right come 7:30 in the morning
Nowadays the entire national grid runs at the same frequency, but the main grid control room can control the frequency by instructing the individual power stations to speed and slow their generators. Its pretty complex when you've got a lot of power stations and each station controls its own load by attempting to speed and slow the whole grid. (Its all about phase, the generators will always be in phase with the grid) connecting and disconnetcting generators from a grid is a precision process. Its usually connected off load with it running in sync and then the power is wound up so the generator 'pushes' against the prevailing grid frequency. If it done all at once it can shift the frequency of the grid.

In another life I was in the Royal Navy as a marine engineer,I once saw a 10 ton diesel generator jump a foot in the air against its mountings and make a hell of a racket when some dumb 'greenie' (name for the electrical branch) attempted to connect it to the ships grid 180 degrees out of phase. One of the big steam generators also supplying the ships grid went off load, overspeeded and tripped out. The other steam generator and the diesel couldn't handle the load, and the automatic load dumping system turned off the lights in our compartment (and a lot of others). It goes without saying we gave him a cursing, and the captain gave him a bigger one.......
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
Burngate
Posts: 5972
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 6:50 pm

gritz wrote:... Dad still has a prewar electric clock from his mum's house. I put a new power cord on it about ten years ago and it works a treat (bar not restarting automatically after a power cut)...
Image
Image
Wesley Edward was my Grandfather - and the clock has a new cable too!

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 6:55 pm

Has it got a little springy thingy that tweaks the armature into rotating when you turn it ?
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 6:55 pm

Isn't this circuit a slight over kill - http://roevalley.com/newsbrowser/interface/rugby.htm surely the MSF module has a TTL output why are there several other components (not counting the turning coil)??

Richard S.

hippy
Posts: 5787
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Accuracy of Raspberry Pi "clock"

Fri Jan 11, 2013 7:15 pm

gritz wrote:I remember reading something about there being a certain number of cycles in a day - even though the Hz could ebb and flow in the short term.
And there's the conspiracy theory that between 09:00 and 17:00 they run the frequency slow to squeeze a longer day's work out of you than you're paid for, and they adjust it right at night time and you get less sleep than you think you had.

There used to be an old analogue clock in the bar I frequented which had a dicky minute hand. It lagged approaching the 12 o'clock position, advanced after; that gave quite a few minutes extra ordering time before the bar closed but drinking-up time was rather short.

Return to “General discussion”