[time-nuts] New algorithm, better ADEV
Tom Van Baak
tvb at LeapSecond.com
Wed Jan 14 18:27:10 UTC 2015
Hi Li Ang,
You're making good progress. Thanks for the update and the photos. I am impressed with both the project and the way you are documenting and sharing the progress on the qsl.net web site.
The new algorithm is good. Yes, the whole idea of a timestamping counter is that you start it once and then let it run indefinitely, checking on the deltas only as much as you need to prevent counter aliasing.
One correction -- when you compute deltas using two's compliment integer variables there is no need for a special-case overflow check. This is a common misunderstanding by non-assembly programmers.
So, instead of your:
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);
Just use:
ref_delta = ref_curr - ref_prev;
sig_delta = sig_curr - sig_prev;
Not only is it much simpler but it also works in every case (your code would fail whenever curr equals prev).
Here's a test program in case you don't believe me: http://leapsecond.com/tools/wrap1.c
/tvb
More information about the Time-nuts_lists.febo.com
mailing list