avr as RTC clocked from mains

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

I have done it many times in the past,an avr clocked from zero cross detection pulses used as a timer with long time interval with a very good timing accuracy.Now i intend to add an RTC function in a dimmer application,to use the zero cross as clock pulses.But the problem is the accuracy in long periods,and my question is if someone has try it before.To write the code is very easy,i use already a programmable 1min to 1440 minutes countdown counter,but i am too old to have the patience to watch a watch to see it if it works correctly.

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

Use a FASTER sinewave to trigger the clock circuit?? A 500Hz signal will make things 10 times faster, a 5KHz signal.....you will still be young after the tests. :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

In most countries the long term accuracy of the mains is very good. How to test? Have it keep track of time and compare it with an internet time server each day. After a couple of days you'll have a fair idea.

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

I've heard that power companies try very hard to maintain the average frequency (at least over the span of a day or so) of their grids very close to nominal for exactly the reason that so many clocks use it as a reference. No idea if that's true or not, but I would expect most grids to be pretty darn reliable in that respect anyway for plenty of other reasons.

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

It seems pretty straightforward to me.
You start your RTC with the correct time.
Go to bed. Sleep soundly.
In the morning, compare the RTC with the correct time.

You should see the number of 50Hz cycles that differ.

Let's face it. The 50Hz long term stability should be pretty good. You are actually checking whether your 'zero-cross-detector' has given you extra pulses. e.g. a small glitch around the crossing could trigger an extra pulse.

You can catch 'extras' in software.
Your hardware could detect peak rather than zero crossing.

David.

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

Are you going to sleep using a supercap during short[ish] power outages?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Lee,

I don't know about American power companies, but I doubt if my (English) supplier will attempt to make up for the 3 hour power cut that we had last night.

I would guess that if you are using the mains, it is hardly worth sleeping between each 20ms pulse period.

Regarding your comment seriously. You would maintain a free running 50Hz timer that simply gets synchronised to the mains. A MSF clock free-runs for most of the time. The radio signal simply 'corrects' it.

If you intend to cope with say a 6-hour power cut, a supercap might manage. You would need a watch crystal to have any hope of keeping any accuracy.

David.

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

Quote:

You would need a watch crystal to have any hope of keeping any accuracy.


I wouldn't think so--if you continually/periodically calibrate an internal timer to the mains I'd think that for short duration it should be fine.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

It depends on how accurate you want the time.

Ok, you can calibrate the existing RC by recording the number of RC ticks in 20ms. If your backup power and temperature is stable, a 6 hour outage could be managed.
My naive approach would be to just rely on the factory RC and OSCCAL. Since this is only 1% at best, you could be wrong by 3 minutes in a 6-hour outage. Ok for your bedside alarm clock. Not so good for an unattended machine.

David.

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

I was even thinking about calibrating watchdog timeout/interrupt. That awakens from deep sleep when running off the cap.

Now, if you add a supercap, then the cost of a 32kHz crystal and coin cell may be in the same range.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I will put it as a test function in the final pcb and if worked well i will keep it,otherwise i will not place the push button and nothing happens.There is no need for extraordinary accuracy,or a back up capacitor or battery to keep the timer running,or even to use a crystal is still impossible since all atmega8 pins are reserved.

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

I tested this a year or two ago. Greece is, afaik, on the mainland-europe grid, so this should apply to you:
http://n1.taur.dk/powergr.png

The plot length is just shy of a year, at which point a power outage ended the experiment. As you will see, frequency accuracy over a day is not good (~1000 ppm), over a year it's a few ppm.

Again, this is for mainland europe. It does not include GB, which has its own, or the eastern part of Denmark, Norway, Sweden, Finland, nor does it necessarily include the Greek islands.

Do include some sort of noise suppression, best would be to run a software PLL locked to the mains. You will get funny waveforms and glitches when they switch loads around in the grid, and if you count cycles double, time will (obviously) be off.

/Kasper

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

Finally the frequency of the mains is more stable than i expected.I have a small digital clock from 1983 that uses 50HZ synchronization.All those years it needed readjustment about two times in a month,since it had always an offset of 5-10mins.Recently as i implement some avr timer/temperature projects and readjust the room clocks with time from the mobile phone,this old clock shows a noticeable accuracy over a long period of time,absolutely comparable with the mobile phone time.
After the discussion in think that for timer/clock applications in kitchen ovens,or any other household automations the mains frequency can be used with much success and the accuracy is more than enough.