[time-nuts] Simple AC mains zero-cross detector

Charles Steinmetz csteinmetz at yandex.com
Thu Dec 18 01:26:06 EST 2014

Gary <nuts at lazygranch.com> wrote:

>Zero crossing and frequency measurement are not the same thing.
>Generally you zero cross detect to switch a load with the minimum
>glitch. For frequency measurement, I'd filter the signal before
>counting it.

Grid-nuts are interested in *both* the instantaneous frequency of the 
grid and also the transients indicative of grid events (grid 
switching transients, lightning strikes, etc.).  So, a data 
collection system for grid-nuts must capture data sufficient to 
determine both the instantaneous grid frequency and the 
time-of-occurrence of grid events.

If you time stamp the zero crossings, you have all of the information 
you need to compute frequency with any desired windowing, filtering, 
or averaging function you desire (and much more).  So, yes, they are 
the same thing when the "thing" is frequency measurement, but ZCD 
gives you the freedom to set the filtering parameters in 
post-processing rather than at hardware design time.

Of course, in addition to whatever windowing/filtering/averaging 
algorithm you may apply in post-processing, you can also filter the 
signal at the data collection stage.  This can improve the accuracy 
of frequency determinations where little post-processing averaging is 
done (what a time-nut would think of as low-tau measurements).

There has been some lively debate about how much filtering (if any) 
is acceptable here.  On the one hand, the AC line is a very noisy 
source at frequencies above the fundamental, while the fundamental 
frequency is determined mainly by massive rotating machinery that 
cannot change frequency very quickly.  On the other hand, if you pass 
the signal through a narrow filter you could miss the glitches that 
interest the folks who collect such data (grid switching transients, 
lightning strikes, etc.), or they could be delayed and smeared out in 
time so determining when they occurred would be problematic.  The 
filtering in the circuit I posted (two-pole RC lowpass with a -3dB 
frequency of ~475 Hz) is a good compromise.  It filters out the worst 
of the locally-generated hash without masking grid events.  For those 
who want their data raw, the filter can be omitted as noted in the 
description sheet that accompanies the schematic.  (You did download 
and read the material before posting about it, right?)

Best regards,


More information about the time-nuts mailing list