Earlier in March we heard about a quirk of the interconnected continental European electricity grid which caused clocks to lose about six minutes so far this year. This was due to a slight dip in the mains frequency. That dip didn’t put anything out of commission, but clocks that are designed to accumulate the total zero-crossings of the power grid frequency of 50 Hz don’t keep accurate time when that frequency is, say 49.985 Hz for an extended period of time.
An interesting set of conversations popped up from that topic. There were several claims that modern alarm clocks, and most devices connected to mains, no longer get their clock timing from mains frequency. I’ve looked into this a bit which I’ll go into below. But what we really want to know is: are your alarm clocks and other devices keeping time with the grid or with something else?
Continue reading “Ask Hackaday: Is Your Clock Tied to Mains Frequency?”
[Lujji] is playing around with the STM8 microcontroller. In reviewing the official documentation for this chip, he read the external clock can be a sine wave, a triangle wave, or a square wave with a 50% duty cycle. The minimum CPU frequency is 0 Hz. [Lujji] doesn’t have a signal generator, and presumably, he’s all out of crystals. He does have mains AC, though, so why not clock a microcontroller with wall power?
Using mains power as a frequency standard is a concept a hundred years old. Synchronous motors turn at a rate proportional to the mains frequency, and this has been used in clocks for decades. If you’re really clever, you can clock digital circuits with mains AC, but we’ve never seen someone replace a tiny crystal in a microcontroller circuit with mains power.
After an experiment to prove the concept, [Lujji] went on to construct a circuit that wasn’t as dumb as connecting the microcontroller directly to a wall socket. The direct approach didn’t work that well anyway — the STM8 didn’t like low frequency clocks with slow edges. [Lujji] needed a clock with cleaner edges, and a 555 configured as a comparator fit the bill.
The completed circuit sends mains power through an optocoupler to drive a 555 configured as a comparator. The output is a clean 50Hz clock that is connected to the OSCIN pin on an STM8. This is now a chip running at 50Hz, and yes, it works. [Lujji] set up a circuit to write ‘Hello World’ on an old Nokia LCD. That took about three minutes. It works, though, even though it’s completely useless. Maybe this can be applied to some novel timekeeping similar to that one-instruction-per-day clock we looked earlier in the year.