Time synchronization with mains frequency (or: most accurate way to measure time)?

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey freaks!

 

I found a nice-looking "eternity calendar" in my local supermarket, it's made from metal and you're manually supposed to move around some magnets to show the current weekday and date...

As soon as I saw it, I thought it would be a great idea to stuff some LED's behind the cut out numbers in the metal to light up the weekday and date. With different colors I can even make it show the month too (green = month, red = day, for example).

Maybe somehow I can make it show the time too without modifying it too much.

 

Now the thing is, I want the clock to be as accurate as possible but without it costing a fortune. What I would like to do is set the time once, and not need to adjust it ever again or as seldom as possible.

 

What I'm thinking about is either using a 32kHz crystal or synchronize it with the frequency of the mains voltage (50Hz).

I've heard that, over time, the mains frequency is pretty much the most accurate timing source you can find here in Europe, although in periods it may drift in one direction or the other. I'm not sure if it's true, but it sounds plausible.

 

What would be the best way to sync my µC to the mains? 230V to 5V AC transformer, a single diode and resistor to ground, connect it to an input pin set up as digital input? Maybe with a zener to prevent over voltage on the input?

 

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will use a photo coupler.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This may not entirely answer your question, but it's quite interesting. Or at least, I thought so.

https://www.bbc.co.uk/news/scien...

 

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kabasan wrote:
I will use a photo coupler.

 

Not a bad idea, I might go with that instead of diode/resistor/zener.

 

John_A_Brown wrote:
This may not entirely answer your question, but it's quite interesting. Or at least, I thought so. https://www.bbc.co.uk/news/scien...

 

Very interesting indeed! :)

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Geronimo wrote:
Now the thing is, I want the clock to be as accurate as possible but without it costing a fortune. What I would like to do is set the time once, and not need to adjust it ever again or as seldom as possible.
Is Wi-Fi available?

If yes then NTP.

An inexpensive Wi-Fi and Bluetooth 4.2 module that's a new arrival at Mouser :

https://www.mouser.com/new/espressif/espressif-esp32-solo-1-module/

Geronimo wrote:
What I'm thinking about is either using a 32kHz crystal ...
drifts with temperature.

A 32KHz TCXO that's 13s/month at 25C :

https://www.mouser.com/new/cts/cts-tt32-hcmos-tcxo/

The operator can walk an accurate clock to your clock then adjust its time.

The following is for EU (DCF) and UK (MSF) :

https://store.oregonscientific.com/us/rm511a-radio-controlled-alarm-clock-black.html

There's an IC for DCF DCF77, MSF, WWV WWVB (and ...? JJY and HGB

 


http://www.npl.co.uk/science-technology/time-frequency/products-and-services/time/msf-radio-time-signal

C-MAX

CME8000

Radio Clock Receiver IC

Data Sheet

https://www.avrfreaks.net/sites/default/files/CME8000.pdf

http://www.c-max-time.com/products/showProduct.php?id=2 (C-MAX, CME8000)

 

Edits: strikethrus, CME8000 datasheet and product URLs

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Sat. Sep 15, 2018 - 12:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Geronimo wrote:
Now the thing is, I want the clock to be as accurate as possible but without it costing a fortune. What I would like to do is set the time once, and not need to adjust it ever again or as seldom as possible.   What I'm thinking about is either using a 32kHz crystal or synchronize it with the frequency of the mains voltage (50Hz).

 

You would want to do both, or even 3  (add support for a 1pps from a GPS module)

 

The TCXO linked above looks nifty, and I'd run all signal sources into their own totalizers, and then you can confirm which one is proven most stable.

 

Geronimo wrote:
What would be the best way to sync my µC to the mains? 230V to 5V AC transformer, a single diode and resistor to ground, connect it to an input pin set up as digital input?

Maybe with a zener to prevent over voltage on the input?

 

No. The hard part is going to be ensuring all the crap and lightning strikes etc do not affect your clock.  Ignore diodes/optocouplers  ....

Check if your MCU has schmitt pins, and then make an analog filtered mains copy, that is 0~Vcc.

 

That circuit is a good start, as D1/R1 becomes a R1/C1/R2/C2/R3 pathway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your Idea from post #1 looks pretty decent as an intial start.

I also agree with Who-me. Keeping the nasty stuff out is a big issue.

Replacing the diode with a resistor wil pull your signal actively to GND. No floating input / reliance on the pull down resistor, so you can use higher value resistors, which makes it easier to filter the crap out of it.

 

Also:

Do you have DCF77 reception in Denmark?

DCF77 modules are cheap and widely available (For example in of the shelf kitchen varietie radio controlled clocks).

This also solves the need to adjust the clock twice a year for summer / winter time.

 

For indoor use you can also pick up mains humm with a simple antenna.

When I touch my scope probe with my finger I usually measure a 60V+ humm @50Hz.

I use this often as a sanity check to see if a scope channel is enabled, the probe is connected to the right channel, etc.

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Geronimo wrote:
What I'm thinking about is either using a 32kHz crystal or synchronize it with the frequency of the mains voltage (50Hz).

I've heard that, over time, the mains frequency is pretty much the most accurate timing source you can find here in Europe, although in periods it may drift in one direction or the other.

This site gives the gives the current stability of the European grid, including its time deviation. At this very moment, the grid is 26.72s behind the real time. Earlier this year, it was six minutes because of a dispute in the Balkans.

- John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jfiresto wrote:

This site gives the gives the current stability of the European grid, including its time deviation. At this very moment, the grid is 26.72s behind the real time. Earlier this year, it was six minutes because of a dispute in the Balkans.

 

Nice link.

 

Seems it can 'wander' quite rapidly, and with no real long-term average discipline, so looks like not even worth bothering - but it might be cool to be able to show that  'dazed wandering' effect :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Geronimo wrote:
I found a nice-looking "eternity calendar" in my local supermarket, it's made from metal and you're manually supposed to move around some magnets to show the current weekday and date... As soon as I saw it, I thought it would be a great idea to stuff some LED's behind the cut out numbers in the metal to light up the weekday and date. With different colors I can even make it show the month too (green = month, red = day, for example). Maybe somehow I can make it show the time too without modifying it too much.

Any images ?

 

There is a common segmented LCD 4 Digit 0.17" that might peek thru any slot.

Last Edited: Wed. Sep 12, 2018 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GPS was already mentioned above.

 

If you really want a long term, accurate, clock, then I use a crystal on the micro, (not the internal RC Osc), and once every now and then I'd update the software clock with the GPS data.

 

This is easier to do if the device sits by a window, so it can pick up the GPS signal.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would go for DCF reception.

in the past couple of months the 50Hz net has been found to not be as stable as it was in the past so you might get deviation from that. ( if 1 or 2 countries decide to stop the export of energy the rest has to compensate but that causes the grids frequency to drop)

also DFC will compensate for summer/winter time. Or not when it no longer is needed. in that way you never have to manually change the clock 2 times a year or ever set it back on time. take in account leap years.......

 

combine with a 32KHz crystal for when DCF signal should ever fail to be received for a short time you should be able to make a nice and highly accurate clock.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

- Brian

Last Edited: Thu. Sep 13, 2018 - 08:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

“Time is an illusion. Lunchtime doubly so.”

 

According to the late, great Douglas Adams.

 

WiFi NTP can be done very easily with a cheap ESP8266 pcb, although you may struggle to find enough I/O (maybe why gchapman suggested the ESP32 "big brother"). Where I live, DCF is a bit flakey, your mileage may vary, but it can be susceptible to inteference from computers etc.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In response to John_A_Brown.

England is a lot fruther from mainflingen (DCF77) then Denmark.

Here in the Netherlands the cheap DCF77 receivers have intermittent results.

During daytime there can be hours on end without reception, and during the night there can be hours on end without a single time code missing.

I use the DCF receiver to syncronize an AVR clock one a day.

It is running from a regular off the shelf uC crystal (11.0592MHz) and it tends to gain or loose a few seconds during a 24hour period.

Regular uC crystals are not great for time keeping, but good enough for me, and it was a good learning experience.

 

On my site (see below) there is still (among others) the code for my DCF clock.

This might have a serious bug though. It still might have the runaway pointer which keeps track of the place where to store a received time bit.

This code might be somewhat unique in that it measures the pulse width with a pin change interrupt, and depending on the pulse widht measured it makes an estimation on the reliability of the received DCF signal.

 

I also thought about NTP, but ESP8266 / ESP32 is not AVR. But they do have their place. "Wemos D1 Mini" is a nice small development board for these critters.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Thu. Sep 13, 2018 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"I also thought about NTP, but ESP8266 / ESP32 is not AVR."

 

Very true. Although I thought this was in the General Electronics section.

For anyone interested, there is an Arduino project somewhere that claims to be able to extract the DCF/MSF signal from a very noisy signal. It does require a good quality crystal, however, as I believe it uses some sort of digital filtering.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John_A_Brown wrote:
It does require a good quality crystal, however, as I believe it uses some sort of digital filtering.
One can easily roll the front-end for such as the electronics are simple and fed into a MCU's ADC; there are ICs to ease the implementation.

The antenna can be an issue though there are antennas to improve reception within buildings, structures, and earth.

For when one has to walk the time signal deeper into a building, structure, or earth :

hand held instrument, small display at top, four buttons in a membrane keypad, operator's instructions on membrane

via

C-MAX

http://www.c-max-time.com/home/index.php

 


C-MAX

Technology

Advantage of the CME8000

http://www.c-max-time.com/tech/advCME8000.php

[block diagrams of low frequency time signal front-ends]

https://octopart.com/manufacturers/c-max

http://www.northstarmicro.com/product/c-max

 


due to https://www.cl.cam.ac.uk/~mgk25/time/lf-clocks/ (browse up for time by RDS, DVB-T, GNSS, NTP) (and cellular?) is :

 

Edit: Northstar Micro Electronics URL

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Sep 13, 2018 - 06:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP initially asks:

Time synchronization with mains frequency (or: most accurate way to measure time)?

 One has to be a bit careful of terminology, here. Mains cannot provide time information. It can only provide a standard frequency (50Hz or 60Hz) with a very good long term average. Short term, it can be significantly worse. Thus, mains cannot provide "time synchronization", only a standard frequency from which you determine incremental time.

 

In this sense, mains are not much better than watch crystals.

 

If you want actual time, there are several choices:

 

1. Standard time/frequency broadcasts including WWV, until that is shut down soon

2. NTP (Network Time Protocol) over the internet

3. GPS

4. Time is available in some cellular networks

5. Uncle Charlie's wrist watch or any of the other millions of personal time standards

 

Bye-bye WWV (and WWVB and WWVH). Its been good to know you. Thank you, Mr. Trump, for cleaning up our technical capabilities.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John_A_Brown wrote:
“Time is an illusion. Lunchtime doubly so.”

 

According to the late, great Douglas Adams.

Lunch is never an illusion unless someone ate your lunch.

John_A_Brown wrote:
(maybe why gchapman suggested the ESP32 "big brother")
No ... caught my attention as prices of the modules from Espressif are only a bit different (ESP8266 vs ESP32)

 


https://www.forbes.com/sites/ruchikatulshyan/2014/08/22/why-your-lunch-break-is-sacred/#37abc4307d6b

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Bye-bye WWV (and WWVB and WWVH). Its been good to know you.

http://www.osec.doc.gov/bmi/budget/FY19CBJ/NIST_and_NTIS_FY2019_President's_Budget_for_508_comp.pdf

just below mid-page "NIST 25"

USA FY2019 starts 1-Oct'18 after USA Congress has a go at it ... or not (filibuster, federal government shutdown, dust-up, make up)

ka7ehk wrote:
Thank you, Mr. Trump, for cleaning up our technical capabilities.
... or privatizing.

A guess is there's a need for WWVB and WWVB becomes fee-for-service as revenue via receiver IC sales and/or a tariff.

Would like to see WWVB survive as GNSS has multiple vulnerabilities (high energy electrons, galactic cosmic rays are up significantly and will be more so due to the Big 3, ASAT)

A GNSS alternate may be time from LEO and VLEO ISP satellites but these are vulnerable to the South Atlantic anomaly (can offset some or most of that by increasing the thickness of aluminum used as an ESD shield)

World-wide experience with public and/or private infrastructure varies (Texans and toll roads, can raise a stink) (have read about UK commuter rail)

 


https://www.nist.gov/pml/time-and-frequency-division/radio-stations/wwvb (WWVB)

Big 3 :

  • grand solar minimum starts in '30 for an estimated 50 years
  • Earth's magnetic filed strength looks asymptotic
  • Sol exits the local galactic cloud sometime "soon" (as within a few millennia)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well, the nice thing is, you can call WWV & get the time, and hear all the ticks & tones 1-303-499-7111

 

No such fun with GPS (as far as I know)

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

'I always suspected the poetic description of Time like an ever-rolling stream. Time, in his experience, moved more like rocks ... sliding, pressing, building up force underground and then, with one jerk that shakes the crockery, a whole field of turnips mysteriously slips sideways by six feet.'

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Fri. Sep 14, 2018 - 06:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RDS is also an option, if you have it in your country.

Personally, I use a watch crystal synchronised from a photcell on my sundial. It's not very accurate, but it's an improvement, as I was spending too much on those candles.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
One has to be a bit careful of terminology, here. Mains cannot provide time information. It can only provide a standard frequency (50Hz or 60Hz) with a very good long term average. Short term, it can be significantly worse. Thus, mains cannot provide "time synchronization", only a standard frequency from which you determine incremental time.

 

You are absolutely right, though I thought it should be clear what I meant from my content wink

 

Anyway, what I want(ed) is to create a clock that is very stable over a long period of time, hence the mains frequency to tick the clock!

It doesn't necessarily need to be on the second, but if I could have it normally stay within a minute or two of the actual time without needing to actually adjust the time, ever, that would be great.

 

However I didn't even think about DCF77 at the time of writing, utilizing DCF77 (or GPS/NTP/RDS) I could simplify the user interface, no need to input the current time and no need to readjust the time ever again since it could synchronize automatically!

 

John_A_Brown wrote:
RDS is also an option, if you have it in your country.

 

We do, I'll have to look into the specs, I wasn't aware that a time signal is available in RDS!

A problem is though, that the politicians are talking about shutting down the FM band in favor of DAB, and from what I understand RDS is overlaid the FM-radio stations, right?

So it might only work for a few years! sad

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Over here, we still have FM and DAB, althought I know there has been talk of turning off FM.

 

I would use an ESP module and internet time, even if you have to use some extra hardware to drive that many LEDs. But I'm biased, as I've made a couple of clocks already that use this method.

 

Four legs good, two legs bad, three legs stable.