Go Down

Topic: High accuracy Timing precision. Driving me crazy (Read 2118 times) previous topic - next topic

Cascode

Oct 22, 2013, 03:49 pm Last Edit: Oct 22, 2013, 03:56 pm by Cascode Reason: 1
Hello. I'm developing a project where the timing  precision is a must. I use a PPS signal from a GPS to restart a counter of two Arduino Due. Moreover, the ADC of each device converts the output of a piezoelectric membrane at its highest conversion frequency (close to 1MHz). Whenever that output gets higher than a threshold, the Due gets the value of the counter and prints it. This is the simplest software I developed to tests the accuracy between two different Arduino's, which share the same PPS signal and the same input to the ADC peripheral. They also run the same exact software. The thing that is driving me crazy is that the printed values of both devices have a usual difference of 200 to 4000 timer counts (usually), being the counter configured at 42Mcps. For my project this is unacceptable, as they should be much more accurate, not even say that in the real project there is more hardware and much more lines in the main loop.

any idea why this happens? I was trying to relate it with the inaccuracy of the Main Clock but I don't think that can make that big difference.

thank you

haturi

I used the TC hardware and it works fine.  The max internal clock is 42MHz in any TC channel.  I would look for interaction between ADC and TC, however insignificant it may seem.

Here is an idea.  The time gap you mention is from 5 to 95 microseconds and that is enough time to be captured in almost any oscilloscope.  But that is the net result after executing some lines of code or doing some activity.  When the two activities start getting out of time sync, they will be nanoseconds apart initially (I think).  However, the gap would grow to microseconds by the time you see the printouts.

If you could break your code or hardware activity in a few sections and an end of each section drive an external pin high, then a 2 channel scope can tell you who  is causing the lag and the pattern about how the lag grows to microseconds.

Regards.

Cascode

#2
Oct 23, 2013, 10:01 am Last Edit: Oct 23, 2013, 10:28 am by Cascode Reason: 1
Thanks Haturi for the answer. I did a more simple tests that I couldn't do it before because I don't have a good waveform source. There's a 'FIX' output in my GPS modules which blinks some ms every 15s when fixed, so I used this signal (from the same module) as the input of the ADC in both devices and synchronized the TCs with two different GPS modules. Surprisingly the timing accuracy improved A LOT. Now the count difference is around 20-60 counts and that's actually expected as the deviation from one Main Clock to the other is around 120 ticks so this can be corrected with a lineal deviation curve. Which that means that the problem is in the input or in the ADC configuration (which I'm still struggling with). I also was thinking that the problem may be the inaccuracy of the internal Vref (does it make sense?). Now I'm wondering how to connect the piezoelectric element, which needs a differential input, and at the same time use the comparison mode of the ADC, which I'm not capable of making it work with the differential configuration. I wouldn't like to use a rectifier for the membrane and a ground referenced configuration as that adds more hardware and lowers the '0 sensibility' of my sensor. Any idea?

thanks

Cascode

#3
Oct 23, 2013, 03:14 pm Last Edit: Oct 24, 2013, 09:03 am by Cascode Reason: 1
Well, I think I can say the Vref of both devices really affects the measure. There is an inaccuracy of 15mV in the reference voltage between both Due (...really ) so obviously with the same threshold values one device detects the signal earlier (always the same one) . With an impulsive signal as the 'FIX' one that I used from the GPS or using a switch as I also tested, the improvement is noticeable as the signal change is 'instantaneous' but a low frequency signal from a piezoelectric membrane, can take some us or ms to rise those 15mV of difference in the Vref. I tested it using a potentiometer and yes, the difference in accuracy is awful as the signal has a low slew rate. I'm trying to tune both thresholds but that should not be the solution as I need a universal idea. Maybe implement an external Vref? I cannot believe there is that much difference from one to another...

BTW, I realized how to configure the comparison mode with a differential configuration. It's a bit tricky tho.

haturi

You sure have nailed the problem.  You know you are dealing with a cpu that is jam-packed with features and costs only about $10 in large volume.  Compare that to a precision Burr-Brown instrumentation amp with good CMR, laser cut resistors inside and it costs more than the Due cpu!  So, high precision is probably not to be expected in this class of devices.

I am glad that you found the problem.  I shall remember that when I tinker with the ADC.

Cascode

http://www.datasheetarchive.com/dl/Datasheets-A2/DSAUTAZ0020985.pdf

that's the low cost voltage regulator that features the Arduino. The output accuracy is 1.25% so in our case is +-41mV. That's almost 13 LSB in the 10 bit resolution!! I'm thinking about changing that regulator. It uses a common configuration with decoupling in/out caps so should be easy to find a more accurate replacement. Or maybe adding this thing nearby and tune the Vref:
http://www.analog.com/en/special-linear-functions/voltage-references/adr4533/products/product.html

]:D

If you sometime use the compare mode of the ADC remember to scale the threshold values from 0-2048, even if you use a 10 bit resolution or change the gain or type of input.

Go Up