[time-nuts] Building a mains frequency monitor

Tom Van Baak tvb at LeapSecond.com
Mon Apr 11 17:31:57 EDT 2016


Hi Jay,

> Q1: Assuming the schmitt trigger in the picPET triggers at a consistent
> point in the waveform, the frequency at any given cycle is easy to 
> calculate: 1.0 / (timestamp2 - timestamp1)    ...but, is there a better
> way? That method just feels... naive, for some reason.

Ah! if it "feels naive" then I've accomplished my goal for the picPET: a simple solution that gives superb results.

Is there a better way? Well, another way to measure mains frequency is record the duration of each cycle directly (e.g., 16.6666 ms). It works, but be careful:

1) Period, or especially frequency readings are susceptible to numerical round-off errors.
2) Depending on how the interval is measured there may be deadtime effects, or timing windows.
3) With period or frequency measurements, if you lose even a single reading, you lose track of phase (timekeeping).
4) Certain types of noise create erratic or too-short periods which are hard or impossible to repair in the data.
5) Double wide cycles are detectable but missed cycles are not.

Here are the advantages of the timestamping method:

1) You get accurate period data by just subtracting adjacent timestamps.
2) There is zero deadtime; and never rounding errors.
3) You get perfect long-term phase tracking, even if there is noise or glitches or lost or corrupted data.
4) If you want, you get a count of expected or unexpected events.
5) Extra or missing cycles are easy to detect and repair with no loss of phase information.
6) picPET output is directly readable by TimeLab via serial/USB.
7) Unwrapped timestamp data can be decimated to any level for frequency(tau) averaging, simultaneously.


> Q2: What are the sources of noise in this design? Assuming the picPET is as

There is some noise but it was too low for me to worry about. Look at the ADEV plot to understand why.

At the seconds level, even at the cycle level, mains wanders around so much that jitter at the microsecond level is uninteresting from a timekeeping perspective. If you're interested in a full phase noise spectrum or THD and the like, then a zero-crossing detector and counter is not the right instrument; go with high-speed ADC sampling instead.


> Q3: The open-ended question: How do I improve on this?

I'd say see if you have a problem before you worry about improving it. I originally had plans for a fancy zero-crossing detector or robust mains signal filtering, as others have proposed. But when I tried a plain 6.3VAC signal (via 1kR) on the PIC's Schmitt trigger input pin I got such clean data for days and months at a time that I never went back and made it more complicated. I now log once a second (instead of once a cycle).

/tvb

----- Original Message ----- 
From: "Jay Grizzard" <elfchief-timenuts at lupine.org>
To: <time-nuts at febo.com>
Sent: Wednesday, April 06, 2016 6:21 PM
Subject: [time-nuts] Building a mains frequency monitor


> Since it seems to be a week for new projects on time-nuts... ;)
> 
> So I've been wanting to set up a power line frequency monitor for a while,
> and now(ish) seemed to be a good time for me.
> 
> So initially, I was planning on doing a simple design that was posted here
> a couple of years back, which basically works out to:
> 
>  mains -> simple 9v ac/ac power brick -> dropping resistor -> picPET
> 
> I have a good 10MHz reference to feed the picPET, so this seems like it
> would make a good first shot. But, of course, I eventually want to do
> better than just a first shot. So, I have questions!
> 
> Q1: Assuming the schmitt trigger in the picPET triggers at a consistent
> point in the waveform, the frequency at any given cycle is easy to 
> calculate: 1.0 / (timestamp2 - timestamp1)    ...but, is there a better
> way? That method just feels... naive, for some reason.
> 
> Q2: What are the sources of noise in this design? Assuming the picPET is as
> accurate as my 10MHz reference is, I can think of a few potential places
> that phase noise could creep into the measurements:
>  - Whatever is in the power brick beyond the transformer (I don't think a step down transformer alone would add phase noise, right?)
>  - The dropping resistor will slowly change the amplitude of the waveform (and thus the point in the cycle that the schmitt trigger fires) due to thermal and aging effects, if we're measuring anything that's not the exact zero crossing
>  - The point at which the schmitt trigger in the picPET fires will change over time for the same reasons. Also potentially due to picPET input voltage, depending on how the comparitor is built
>  - Am I missing any?
> 
> Q3: The open-ended question: How do I improve on this? I suspect the main place for improvement will be in the trigger, but I'm not sure where to go with that.  Most designs I've seen involve a schmitt trigger, generally with reference voltages set by things like voltage dividers. This seems dubious at best, to me, since that means the reference voltage will be affected by the same effects I'm calling out above. Is there a *specific* design (rather than "make a zero crossing detector!" or something similarly vague) that someone can point me to, that would minimize this kind of trigger noise?
> 
> Q3.1: Is there a better way to get mains voltage down to something I can work more directly with? I saw at least one design that just used a couple of megaohm resistors inline -- does that introduce appreciably less phase noise than random AC/AC power brick?
> 
> I apologize if any of this is overly basic. I've actually read everything I could find both in the time-nuts archives and the internet at large about this kind of project, but I've still found myself left with the questions above.
> 
> I appreciate any comments / feedback / pointers!
> 
> -j
> _______________________________________________
> time-nuts mailing list -- time-nuts at febo.com
> To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
> and follow the instructions there.


More information about the time-nuts mailing list