Close

Command line frequency counter

A project log for Silly software wishlist

Motivation to do some software projects by writing them down.

lion-mclionheadlion mclionhead 06/17/2020 at 23:110 Comments

https://cdn.hackaday.io/files/1380505906331200/countfreq.c


If you're into knowing the relative frequency of something to very high precision, oscilloscopes of lion kingdom vintage are pretty bad, but you can transfer a waveform to a computer & run this program on it.  Newer oscilloscopes can definitely do better.  It can't get absolute frequencies to very high precision because that depends on the oscilloscope crystal.

Some sample waveforms show 2 surface mount 32.768 crystals running at 32766 & a 3rd through hole crystal at 32768.  They can also be affected by the probing method.  As lions discovered from creating Heroineclock II, crystals can vary by a lot.  .01% precision for a resistor is high precision, but for a crystal is way out.

It gives the standard deviation of the wavelength in samples, useful for knowing how stable the signal is.  In the sample data, the through hole appears much more stable than the surface mount, but the standard deviation also depends on the samplerate.  Frequency is not as affected by samplerate as the standard deviation.  The surface mount standard deviation drops to 20 when sampled at 100 megsample.

Best results have come from counting zero crossings with a debounce delay, rather than counting peaks & troughs with hysteresis.  The best debounce depends on how noisy the signal is.  The zero crossings are where the waveform is steepest, so the time of the zero crossing can be known to the most precision.  Slight errors in where each cycle begins can create huge errors in the frequency measurement & the standard deviation.

Of course, to just see if 2 crystals are way off, load them in an audio editor & play them back.

Discussions