[time-nuts] Building a mains frequency monitor

Nick Sayer nsayer at kfu.com
Thu Apr 7 00:34:02 EDT 2016


I did this not too long ago.

I used GPS PPS as the reference.

I took a 9v wall wart, pinned one side to ground, ran the other through a rectifier diode and into one input of an LM358 wired as a comparator, comparing to 2.5 volts (Vcc/2). The 358 was slow enough that hysteresis wasn’t required. When I tried the same thing with an LM393, it flapped a lot because it was so much faster.

What I did for the code was simply count the rising edges on the 60 Hz pin between each rising edge of the PPS pin. Most of the time, it was 60. When it wasn’t, I output a serial line with the delta. That fed into a Raspberry Pi serial port that was running a simple daemon that logged every line it got to syslog. Syslog is handy because it timestamps everything for you and keeps rotating log files and the like.

Some awk scripts turned the log file(s) into CSVs, and excel graphed them.

My results were that I could definitely see that there was discipline being applied to the frequency (so the long term average number of cycles per day was correct), but the short term drift was in the thousands of cycles. Enough that if you drove a clock directly from the 60 Hz, it would be just about pointless to give it a second hand.

The short term results were so wide that I felt quite confident that the actual effects I was seeing would have overwhelmed any measurement subtleties from the relative imprecision of the circuit I had designed.


More information about the time-nuts mailing list