Crystal vs mains synchronisation for clock - Page 1
Forum section: electronics / projects

author: 5321488
author_rank: Contributor
timestamp: June 22, 2017, 07:49:46 am
content: I am building a clock-like device in which I need some method of time keeping. Originally I was going to synchronise with mains power but have since started considering using a crystal, partially because of the less components required but also on the basis of accuracy. What would people recommend to use, keeping in mind that the less components the better? Also, roughly how much can a crystal frequency drift over time?Thanks!

author: Circlotron
author_rank: Super Contributor
timestamp: June 22, 2017, 08:12:27 am
content: Mains varies in frequency ever so slightly from one moment to the next, but over 24 hours it will have an exact amount of cycles. You can run a clock for years from a mains reference without it drifting to any worthwhile extent. In a first world country at least.

author: MosherIV
author_rank: Super Contributor
timestamp: June 22, 2017, 08:20:28 am
content: I have done some work on commercial plug in clocks before and the 32.768KHz crystals area) not exactb) drift a little over time but probably not as noticable as the inital accuracy.the difference for both can be found in the data sheet for the crystal, we are talking parts per million.On the clock project, we had an 8bit micro and we developed an algorithm to correct the time by adjusting the count from the crystal. On the production line, the crystal would be measured. The count would be used to calculate the adjustment which would then have to be programmed into the EEPROM of the clock for the micro to use.Does that help?

author: bktemp
author_rank: Super Contributor
timestamp: June 22, 2017, 08:23:55 am
content: Mains frequency in most countries is probably at least an order of magnitude more accurate than a typical crystal (32768Hz crystals are much worse).The main effect for the drift of crystal oscillators is the temperature dependency, therefore it is quite difficult to compensate unless you spend much time characterising each crystal.Using mains frequency + a crystal as backup when the mains frequency is missing or out of range is probably the best solution.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 22, 2017, 08:46:51 am
content: In most countries, mains will be more accurate long-termOne thing to remember about watch crystals is that in a watch, they are being held at a pretty constant (body) temperature, and I believe they are optimised for this temp.If you want accurate time without mains, then you need a TCXO

author: Benta
author_rank: Super Contributor
timestamp: June 22, 2017, 09:12:01 am
content: If you want it really accurate, use a GPS receiver module.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 22, 2017, 09:13:33 am
content: Quote from: Benta on June 22, 2017, 09:12:01 amNot so good indoors though.

author: tszaboo
author_rank: Super Contributor
timestamp: June 22, 2017, 09:29:16 am
content: I usually not recommend Maxim devices. This will be an exception. There are RTCs with built in crystal, like the DS3231, which are accurate to a few seconds/year. You can buy them in modules, I recommend those fos small projects.

author: mrpackethead
author_rank: Super Contributor
timestamp: June 22, 2017, 09:36:07 am
content: I monitor the frequency of the mains. and just had a look at the averages.. and here in NZ, i got 49.99999998 Hz over the last month.The big issue is when the power goes out. Yoru clock just starts from where it left off.

author: Codebird
author_rank: Regular Contributor
timestamp: June 22, 2017, 09:58:59 am
content: Mains power, in most countries, is spot on long term.It drifts constantly throughout the day - it's actually effected by supply and demand. A sudden surge in power usage makes the frequency drop slightly. But the operator counts! If they are a few hundred cycles short one day, they simply speed the frequency up a little the next.This is a service they provide precisely so it can be used in timekeeping, and dates from the days before practical compact crystal oscillators. When the most precise of domestic clocks involved a synchronous motor linked to a long chain of reduction gears.There is another option: Depending where you are in the world, most regions have a broadcast time signal. The UK one is the MSF time signal. It's a rather low-frequency radio broadcast, but at a high enough power to be picked up anywhere in the country. All it does is broadcast the time, over and over. You can get modules that receive it.Crystal drift depends upon the crystal and the environment - the greatest factor is temperature. Ultra-precise crystal oscillators (which are mostly used for calibrating less-precise ones) use a heated enclosure with a thermostat to maintain a steady, known temperature.

author: tggzzz
author_rank: Super Contributor
timestamp: June 22, 2017, 10:14:18 am
content: Quote from: 5321488 on June 22, 2017, 07:49:46 amThat depends on the application, which we don't know.QuoteFor crystals, that's a case of RTFDS. You will find OCXO better than TCXO better than XO, and none are as good as oscillators derived from radio frequency standards or GPS.To see the UK's grid frequency as a function of time, go tohttp://www.gridwatch.templar.co.uk/download.phpthe click the "white none" and "red frequency" buttons (sigh).

author: MosherIV
author_rank: Super Contributor
timestamp: June 22, 2017, 10:17:34 am
content: The 32.768KHz crystals are so cheap and yet have very low drift.They are that way because they are used in time pieces like watches, clocks, etc.I think you can get them to 1-2 ppm drift and they are stable across quite a wide temp range.I think it is because of the crystal cut - some kind of a tuning fork arrangement.For commercial products (like the one I worked on) the component cost was the biggest factor.The goal was to get less that 1 sec per month if I remember correctly.Adding a little time on production to calibrate was tolerable. I guess that is the reason why cheap watches drift but expensive watches keep time.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: June 22, 2017, 10:30:17 am
content: "Typical real-time clocks employ 32 KHz tuning fork crystals. While being well suited to thelow-power needs of battery-backed applications, they can drift significantly over theindustrial temperature range –40 to +85°C. At the extreme temperatures, drifts aresomewhere between –108 and –177 parts per million (ppm), a loss of about 5 to 8 minutesper month. "http://www.st.com/content/ccc/resource/technical/document/application_note/55/e2/3d/2a/87/ab/4d/e1/CD00232494.pdf/files/CD00232494.pdf/jcr:content/translations/en.CD00232494.pdf]http://www.st.com/content/ccc/resource/technical/document/application_note/55/e2/3d/2a/87/ab/4d/e1/CD00232494.pdf/files/CD00232494.pdf/jcr:content/translations/en.CD00232494.pdfSo as Mike said earlier temperature is probably your biggest consideration.You need to post some more of your design constraints... if you are not cost sensitive then adding a GPS receiver is a solution (if you have line of sight to the sky), or a LW radio module (if you are near MSD, DCF, etc). or a TCXO, or a RTC chip that will do the temperation compensation for you e.g. Ds3231 et al...

author: bktemp
author_rank: Super Contributor
timestamp: June 22, 2017, 10:30:33 am
content: Quote from: MosherIV on June 22, 2017, 10:17:34 amI wouldn't say stable across a wide temp range. The drift is typically -0.04ppm/°C². That does not sound much, but if you are 10°C away from the stationary point, the frequency will be 10*10*0.04ppm=4ppm off. At +/-20°C it will be 16ppm (1ppm = 2.5s/month).So if the temperature is reasonably constant (like for a typical room temperature) 32768Hz crystals are ok, otherwise temperature compensation should be used (temperature compensated RTCs are quite cheaply available).Just look at the clock of your PC: It often drifts 10s of seconds or even a minute per month because of the unstable temperature on the mainboard.

author: Circlotron
author_rank: Super Contributor
timestamp: June 22, 2017, 11:08:50 am
content: To see how the mains frequency shifts about from moment to moment, put your scope on AC mains trigger then feed it an accurate 1kHz. (1.2kHz for 60Hz mains). The trace creeps to the left for under frequency and to the right for over frequency. You can clearly see when big loads come and go. As long as the total creep evens out, things are good for clock accuracy.

author: klunkerbus
author_rank: Unknown
timestamp: June 22, 2017, 11:49:58 am
content: Another vote for the DS3231 if your project is using a micro controller with an I2C interface available. I've used the AdaFruit ChronoDot on a handful of projects. Wire up power and I2C, insert the battery, set the time on the bench during debug, and done.One problem with using mains power that hasn't been mentioned is noise causing the clock to run fast. A college project of mine used mains for the clock reference, and I never did find the right kind of filtering that would keep the clock from drifting fast. Someone mentioned in a similar thread a few months ago that the best way to leverage the mains frequency as a clock source is to use it as the reference for a PLL circuit.

author: bktemp
author_rank: Super Contributor
timestamp: June 22, 2017, 12:14:42 pm
content: I have used mains frequency for years as a clock source and hat never experienced a problem with a clock running too fast (except during some days of power grid maintenance when a small area was supplied from a mobile generator set. Then the mains frequency often gets increased from 50Hz to slightly above 53Hz because this forces all solar inverters to shut down. Something I hadn't seen before.)A simple <100Hz low pass filter for removing any high frequency noise followed by a schmitt trigger generates a clean 50 or 100Hz squarewave signal (depending on where the signal is sensed before or after a bridge rectifier).

author: Dr. Frank
author_rank: Super Contributor
timestamp: June 22, 2017, 12:34:14 pm
content: You should at first clarify your requirements, in terms of required accuracy and stability.Accuracy is the absolute value of your frequency. In case of an XTAL, this can be initially trimmed to ppm level or better, depending of the type of the XTAL and the oscillator circuit.Stability of the initial frequency value drifts over temperature and over time, and stability is different also, if you average over different time scales.Accuracy and stability determine the overall precision of your time keeping.Just for interest, I have taken the UK data and let Ulrich Bangerts PLOTTER program calculate the Allan deviation.The mains frequency is accurate to about 18ppm, as its average frequency over 7 years is about 50.0009044 Hz, stdev is about 0.1%, so a quite jittery clock.As you can see from the Allan deviation, on a 1h time scale, the stability is around these 1000ppm only, and only after 1 year of operation, you may get a stability of about 10ppm. Over the 7 years, there obviously have been about 480 brown- or blackouts (zero frequency reading), which may further disturb a clock based on mains.A good quality 4MHz XTAL, may achieve these 10ppm accuracy w/o any further measures, and stabilities over a short time scale well below 0.001ppm, but drift over temperature and time may limit accuracy to another 10ppm.These tuning fork type / clock crystals are not suited to precision time keeping, due to their high T.C. dependency.But there exist TCXOs with these crystals, being not cheap.Frank

author: Gyro
author_rank: Super Contributor
timestamp: June 22, 2017, 12:53:51 pm
content: Quote from: MosherIV on June 22, 2017, 10:17:34 amYes, they are a tuning fork cut. They typically have a fairly large inverted 'V' temperature coefficient with frequency dropping off quite steeply both sides of typical wrist temperature (~25'C).I'm currently in the situation where my 1940s Synchronome electric pendulum master clock is achieving 5 times better timekeeping than my mid-range Citizen Quartz watch (Both checked against a DCF77 synchronized clock).It only takes a few ppm to noticably throw off long term timekeeping, I'd vote for mains based with crystal backup too.P.S. Synchronomes used to be used next to synchronous motor clocks in power stations to monitor mains frequency offset. Now it's compared against GPS of course.http://www.hvtesla.com/masters/syncro_power_intro.html

author: 5321488
author_rank: Contributor
timestamp: June 25, 2017, 09:04:44 am
content: Thanks everyone, looks like mains is the go.

author: StillTrying
author_rank: Super Contributor
timestamp: June 25, 2017, 01:31:17 pm
content: How about XTAL, but with a software correction regularly calculated from the mains.Timing the mains for 6 minutes would give about 1ppm. A running average of the mains corrections over 2 or 3 days should be better than 1ppm long term.Save the correction value occasionally so it doesn't have to start from nothing after a mains failure.

author: tszaboo
author_rank: Super Contributor
timestamp: June 25, 2017, 05:01:13 pm
content: Quote from: StillTrying on June 25, 2017, 01:31:17 pmYeah, you should build a neural network, and Linux, with GPS, NTP and DCF77 just to make a stupid clock.

author: Gyro
author_rank: Super Contributor
timestamp: June 25, 2017, 05:58:59 pm
content: Quote from: StillTrying on June 25, 2017, 01:31:17 pmNope, not a chance. Depending on the time of day (load) the mains frequency could be off by 1% or more for the entire 6 minutes. Timing it over 24 hours then yes, maybe. You would have to have your 'gate' time set to 24 hours though, preferably midnight to midnight which, I think, is where they try to get the cycles to add up.