[time-nuts] New algorithm, better ADEV

Li Ang lllaaa at gmail.com
Wed Jan 14 10:55:53 EST 2015

    Just now, I changed the way to calculate frequency and get a better
ADEV chart.

    Thanks to John Miles's reply in the thread about ADEV.

> If you feed in frequency samples, it will convert them to phase-difference samples internally, so the
> program itself doesn't really care.  The use of frequency data has a few drawbacks such as less accurate
> ADEV plots due to the counter's dead time between readings, but it's the easiest way to get started and is
> perfectly usable for many purposes.
Old way:
//reset counter every second to avoid the overflow issue
while (1) {
     trigger_and_read_cnt(&refA, &sigA);
     trigger_and_read_cnt(&refB, &sigB);
     Freq = Calc_freq(refB - refA, sigB - sigA);

New way:
//The counter keeps running. The software takes care of the overflow issue.
No dead time.
trigger_and_read_cnt(&ref_prev, &sig_prev);
while (1) {
   trigger_and_read_cnt(&ref_curr, &sig_curr);
   ref_delta = (ref_curr > ref_prev) ? (ref_curr - ref_prev) : (0xffffffff
- ref_prev + ref_curr);
   sig_delta = (sig_curr > sig_prev) ? (sig_curr - sig_prev) : (0xffffffff
- sig_prev + sig_curr);

   Freq = CalcFreq(ref_delta, sig_delta);
   ref_prev = ref_curr;
   sig_prev = sig_curr;

BTW: I've put the counter into a box.
more pictures: http://www.qsl.net/b/bi7lnq/freqcntv4/pic/

More information about the time-nuts mailing list