real time clocks & 60hz from power company

Sep 29, 2003 34 Replies

Does anyone know of any reason to not use the 60hz/110VAC signal coming from the electric utility companies to drive an "approximate" elapsed time clock? Isn't that what digital alarm clocks used for their clock source not too many years ago? The board I'm working on doesn't have a crystal that divides down neatly to seconds (milliseconds, etc.) using any of the built in timers/prescalers, and I'm having trouble maintaining a moderately accurate real time clock with it. One of my coworkers stated an opinion that power compaines don't have any guarantee about the accuracy, stability, etc. of the 60hz AC that's associated with our AC power here in the USA, especially when the power grid switches things around, and that if I use that 60hz to drive my clock it'll lose time regularly (i.e., several seconds per day).



Anyone have any comments on this issue?



Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

I don't know about the USA but in the UK the frequency is adjusted to maintain the long term accuracy of clocks and timers. Just remember not to export any of your devices to Europe or you'll certainly lose time running at 50Hz. The alternative that we chose is to add a real time clock like the PCF8535. If you are short of cash then adapt an analog watch to give you a one second interrupt.

Peter

Depends on how "approximate" you can tolerate it to be, and what your viable alternatives are. There's always the basic isolation / safety regulations to keep in mind, for starters. You want to be _very_ careful on that end.

Sure. Some of them may even still be in operation, and the power companies know that. This *should* imply that as long as your requirements match those of an alarm clock, you should be fine. But as usual, the real answer can only be had straight from your horse's mouth, i.e. your local powercorp.

I don't see why that should pose any problems. The second is not a sacred unit if all you really want to know is the amount of time, is it? Yes, you may have to perform a division of large-ish operands if you finally have to display the result in units of seconds --- but that's mainly a problem of representing the result, not of the measurement itself.

In other words: what's stopping you from measuring times in units of crystal cycles or timer ticks (of your own definition), and only translating that result into seconds if needed, using a pocket calculator or whatever? Using an approach similar to the Bresenham line drawing method of computer graphics, it may well be possible to reach a very precise result even without having to actually divide.

The 60 Hz (which are of course 50 Hz around here ;-) are said to have rather good long-time stability, exactly because of those mains-driven clocks of old. But short-term fluctuations do, indeed, happen. So you shouldn't assume you can accurately time one second by counting 60 mains cycles --- but still, a day will quite reliably be 86400*60 cycles long.

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

If he has a crystal, resonator or even some RC clocks, he can easily detect whether it's a 50Hz or 60Hz nominal line, but I really don't see why he can't use any particular frequency crystal to make an accurate clock. He has to write firmware that accumulates any errors to better accuracy than the crystal tolerance.

Best regards, Spehro Pefhany

"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com

I can, .... he will have problem with uart's i guess.

Same in the US. It may vary slightly during the day, but they adjust it to make sure that over a 24-hour period the number of cycles is dead-on. That's what they told me at the local power plant -- and I've heard the same from people I know in the power industry in other parts of the county as well.

Grant Edwards grante Yow! I'm working under at the direct orders of WAYNE visi.com NEWTON to deport consenting adults!

The 60 Hz power frequency does vary slightly, but I doubt it's ever off by as much as several seconds, and over the long term it stays accurate. Here's a thread on it:

formatting link

or:

formatting link

-----

formatting link

The frequency of the crystal is largely irrelevant, but the fact that you want a real time clock sort of hints that you might have a micro. That makes things easy, even if you don't have the micro you can always divide your crystal to almost any number to get a secondary time base which is a convenient fraction of a second.

Al

Dave Sudolcan wrote:

Please remove capitalised letters to reply My apologies for the inconvenience Blame it on the morons that spam the net

I have a venerable old Heathkit digital clock that is driven off the power line. It sometimes gains seconds and sometimes loses seconds, but it's never exactly correct except for shortly after I set it to the NTP time. It certainly doesn't drift by seconds a day, though.

No doubt the power line drifts and I don't know how accurate the power company is trying to keep the frequency. In spite of their efforts there are still the considerations of how your circuit is designed so that it doesn't count extra pulses due to line noise or loose pulses.

Since you state that "approximate" is acceptable, then the power line should work fine for elapsed times of reasonably short duration.

Oh heck, why not just include a GPS receiver and get a very accurate, stable time reference? :-)

...Tom

Remove "SpamMeNot-" from address if responding via email. Tom Sheppard Real-Time Fundamentals instructor-led and web-based training courses http://www.Surreal-Time.com/

In the short term, the 60 Hz may drift somewhat. But in the long term, they will maintain a 60 Hz corrected average.

So it's accurate, not precise. (Your Power Company May Vary.)

Ron Sharp.

"John carlton" schreef in bericht news:3f783f6d$0$58711$ snipped-for-privacy@news.xsall.nl...

The frequency of the crystal is not important (it is for the uart).

What you need is a solid and regular interrupt, one that does not have much jitter.

Suppose the interrupt comes every 1721 uS, as a result of your crystal and funny prescalers. No problem at all.

int16 uSec; int16 mSec; int8 Seconds; int8 Minutes; int8 Hours;

interrupt() { uSec += 1721;

if(uSec>10000) { uSec -= 10000; mSec += 10; if(mSek>1000) { mSek -= 1000; Second++; if(Second>59) { Second = 0; Minutes++; if(Minutes>59) { Minutes = 0; Hours++; if(Hours>23) { Hours = 0; } } } } } }

Untested code. Will run just fine.

Even allows for calibration of the crystal, by adding, every hour, the nummer of mSeconds it runs to fast or too slow.

Still, I prefer a RTC with backup for clocks. A ds1302 runs about

2 days on a 0.047F supercap. Enough for most power problems. Real batteries for handhelds.
Thanks, Frank Bemelman (remove 'x' & .invalid when sending email)

You can use any known frequency to create an accurate clock as long as the frequency is stable and known. You just need a piece of software.

-jm

You have to ask yourself, what is the time used for ?

If it is used just for human consumption as a nice feature ("nice to have"), it should be fine. However, time stamps between your system and some other systems based on crystal/GPS timing are used, then the situation is much more complicated.

A long time ago, we had a PDP-11 as the central controller (which used mains derived clock), communicating with various micros over half a dozen serial lines, which counted their time from the local crystal oscillators. Some of these identical micros were in a moving open frame construction with good ventilation, while some were in closed, stationary boxes with poor ventilation. All the clocks in the micros were synchronised over the serial line prior to start of operations.

The system was very critical about the drift between the various micros and worst of all, the drift rate depended on the speed the open frame devices moved and also if the doors to the hall were open (-30 C outside), so the drift could be quite bad.

It was unthinkable to use a separate clock line to all devices (some connected through slip rings).

Finally, we had to abandon the too unreliable crystal derived clocks and use the mains as the common time base to all devices, counting cycles since the serial line reset command, avoiding any clock problems fora few decades.

It really depends what you are trying to achieve.

Paul

Tom Sheppard said for all posterity...

I had one of those that I put together in 1975, I think. It had 3

2-digit gas discharge displays. I noticed the same periodic fluctuations in the seconds, but there never seemed to be any significant accumulation of errors over time.

For a bit of nostalgia, this link shows a picture of the model I had.

formatting link

Casey

Okay... I've heard enough on this topic. Thanks for all the input. I think the 60 hz clock will do just fine for my elapsed run time timer.

+/- a few seconds occasionally should not be an issue for this system. I've already got both an analog and a digital filter on the clamped signal derived from my power supply transformer, so I think all will be okay. If it turns out otherwise, I'll post an OOOPS with details.

Thanks again, Dave.

Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

When I was at the university, years ago, they had been using the 60Hz signal from the power line for timing a telescope. Someone noticed one day at just before midnight that the clock sped up to about 120Hz for a few seconds. The law required them to put out so many cycles in a day and they were just catching up. So it just depends on how "approximate" you need.

I still don't understand why you can't use the crystal-driven timer on your board.

Grant Edwards grante Yow! I'm in ATLANTIC CITY at riding in a comfortable visi.com ROLLING CHAIR...

Considering how tightly synced the grid is I doubt the local utility somehow sped up the cps on the wires. I would rather guess there was some bug in the rest of the system. I would shudder to think what jumping the grid frequency would do to some industrial customers using BIG 3 phase motors.

Jim

"James Beck" schreef in bericht news: snipped-for-privacy@news.east.earthlink.net...

That 120Hz is a joke of course. I'd bet my last penny that it's not more than 60.1Hz no less than 59.9Hz during the catching up. And a nationwide correction.

Thanks, Frank Bemelman (remove 'x' & .invalid when sending email)

The local utilities do guarantee that the number of cycles per day is exact. The correction is not that dramatic though. Just a small speed up or slow down to make it correct. Good for clocks and such but not for any kind or real accurate work. I can't remember the exact spec but +/- a few seconds is what I remember. Plus the correction is graduadually applied.

Doug

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required