[time-nuts] evaluating an oscillator with the allan deviation

Tom Van Baak tvb at LeapSecond.com
Fri Feb 8 12:52:52 UTC 2019


Hi Folkert,

That's a very nice test. You're using an Arduino and its micros() function to timestamp pulses from two different sources with 1 us resolution, which are columns 1 and 2 of your raw data.

The Arduino oscillator is of unknown accurate and stability. However, one of the inputs is GPS/1PPS so while the Arduino thinks it is measuring GPS, GPS is actually measuring the Arduino timebase. This is a standard trick. That's why your column 3, which is column 2 - column 1, is useful. It subtracts the common mode Arduino error which leaves you with just a comparison between your function generator and GPS; the error in the Arduino timebase "drops out".

Thanks for the raw data. Attached is Folkert-02.png which is the ADEV from column 1 (your function generator vs. Arduino) and column 2 (your Adafruit 1PPS vs. Arduino). In this case it's quite clear that the Arduino crystal is much better than your function generator. In other words, you probably didn't need the Adafruit GPS. But you can't know that until you make the measurement.

Attached is Folkert-03.png which is the ADEV from column 3. This is a truer ADEV of your function generator. Note the two plots are almost identical except near the right side you can see that by using GPS you have corrected for the drift in the Arduino oscillator. Well done.

But your Python / allantools plot is wrong for a couple of reasons.

1) Your Arduino is outputs raw integer microseconds. So you need to scale those to seconds (divide by 1e6) before using statistics software. Easy fix.

2) There is a glitch at line 24694 in your raw data. Note that you have timestamps at second 24698.4, 24699.4, 24701.4, 24702.4. But missing is a timestamp at second 247000.4. It could be a serial dropout. Or could it be related to how you handle interrupts? It looks like your code assumes one input precedes the other.

In some cases (like comparing one GPS with another) missed samples are ok. But here you have a frequency generator that is off-frequency and so phase is growing rapidly during the run. Missing even a single sample causes a massive frequency spike in the data, which causes harm to an ADEV calculation.

You can find these sorts of glitches by using tools like Stable32 and TimeLab. In general, never (seriously, never, ever) do an ADEV plot without first looking at the phase plot and the frequency plot. Doing so instantly reveals the error at line 24694.

3) Column 3 of your data file has samples in the 4 billion range. That's because you're printing as unsigned instead of signed. Negative numbers are fine when you compare two clocks. So if you see a number like 4294966796, that is not a bad data point to be deleted, but instead compute 4294966796 - 2^32 = -500 microseconds, which is a valid measurement.

In general do not delete data. When you see what you think is a glitch, this is often Nature quietly trying to catch your attention.

4) I haven't used allantools but it appears you have computed only a couple of data points, only a few tau. In some cases this is ok, but when making measurements of a function generator using an Arduino with its own set of quantization effects, you probably want to maximize the number of tau that you compute. Here are two Stable32 plots using the "all tau, or many tau" option:

Folkert-09.png -- ADEV via Stable32
Folkert-10.png -- PSD via Stable32

As you jump into the data in more detail you will see all sorts of wonderful periodic phase ramps. You may want to confirm that their behavior is consistent with the code in your function generator. I didn't include plots, but as you play with the data as phase residuals or normalized frequency you'll see what I mean.

5) Final comment. As much as I respect Python and appreciate Anders Wallin's allantools library, these "don't worry, trust me, I will do it all for you, in one line of code" kind of tools are dangerous IMHO. They give you results but they steal your opportunity to think, to learn, to understand. So I strongly advise you to process your data with Stable32 or TimeLab rather than using canned functions that can't tell bad data from good data. ADEV, in particular, is highly sensitive to bad data.

Ok, that was a long answer, but it was an intriguing question you asked. Your web page is wonderful and your project very interesting. Thanks for sharing.

/tvb




----- Original Message ----- 
From: "folkert" <folkert at vanheusden.com>
To: <time-nuts at lists.febo.com>
Sent: Friday, February 08, 2019 1:39 AM
Subject: [time-nuts] evaluating an oscillator with the allan deviation


> Hi,
> 
> Due to hobby-budget limits I build a very simple function generator
> from an arduino and a dac ( https://vanheusden.com/Arduino/funcgen/ ).
> I would like to evaluate its performance.
> 
> To do so, I setup another arduino which is connected to a pps signal
> from a gps. This arduino then subtracts the timestamp from when the DUT
> pulses (DUT = function generator) and when the GPS/PPS pulses (
> https://vanheusden.com/Arduino/funcgen/osciltest.ino ). The result of
> this is plotted using https://github.com/aewallin/allantools/ :
> https://vanheusden.com/Arduino/funcgen/funcgen-allandev.svg
> 
> I'm far from an expert but this graph looks a bit too good to be true.
> Can anyone spot the mistake I make in the process?
> 
> 
> regards
> 
> Folkert van Heusden
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Folkert-02.png
Type: image/png
Size: 31826 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20190208/cb57eba6/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Folkert-03.png
Type: image/png
Size: 31262 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20190208/cb57eba6/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Folkert-09.png
Type: image/png
Size: 70170 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20190208/cb57eba6/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Folkert-10.png
Type: image/png
Size: 76785 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20190208/cb57eba6/attachment-0003.png>


More information about the Time-nuts_lists.febo.com mailing list