Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

ADC readings off on Itsy Bitsy M4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: ADC readings off on Itsy Bitsy M4

by blnkjns on Mon Apr 26, 2021 9:01 am

3 steps: download the IDE, go to tools ->boards add the Adafruit SAMD boards->select the port under the same tools menu and click "Play".

blnkjns
 
Posts: 624
Joined: Fri Oct 02, 2020 3:33 am

Re: ADC readings off on Itsy Bitsy M4

by adafruit_support_bill on Mon Apr 26, 2021 12:36 pm

I see similar results on an M4 Grand Central board. I'll check with the CircuitPython team.

adafruit_support_bill
 
Posts: 81319
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

by blnkjns on Mon Apr 26, 2021 4:57 pm

Maybe you can fix the range in Circuitpython as well. It is weird that a ADC with 12 bits resolution outputs 0-65535

blnkjns
 
Posts: 624
Joined: Fri Oct 02, 2020 3:33 am

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Thu Apr 29, 2021 3:52 am

Any updates on this?

Is there a way I could adjust the periphery initialization parameters myself?

Bekar_T
 
Posts: 22
Joined: Wed Apr 21, 2021 12:41 am

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Wed May 05, 2021 12:52 pm

No resolution? No updates? No nothing?

Bekar_T
 
Posts: 22
Joined: Wed Apr 21, 2021 12:41 am

Re: ADC readings off on Itsy Bitsy M4

by adafruit_support_bill on Wed May 05, 2021 1:07 pm

I'll ping the CircuitPython team again regarding this issue...

adafruit_support_bill
 
Posts: 81319
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

by adafruit2 on Wed May 05, 2021 1:11 pm

The M4 ADC and DAC are better than the ESP32's but we have seen they're not perfect and you could be seeing the affect of traces/pcb layout and the internal peripheral.
if you need excellent performing ADCs for DAQ, we recommend an external ADC - there's a fair chance that even after we investigate the answer will be "yep, we agree!"

adafruit2
Site Admin
 
Posts: 20054
Joined: Fri Mar 11, 2005 7:36 pm

Re: ADC readings off on Itsy Bitsy M4

by danhalbert on Wed May 05, 2021 1:12 pm

blnkjns wrote:Maybe you can fix the range in Circuitpython as well. It is weird that a ADC with 12 bits resolution outputs 0-65535

We scale everything to 16 bits so the range is uniform. In the future we might make it possible to change the resolution.

danhalbert
 
Posts: 2430
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

by danhalbert on Wed May 05, 2021 1:23 pm

The SAMD51 ADC has a number of problems. See the ADC errata in this document: https://ww1.microchip.com/downloads/en/ ... 00748L.pdf

Having said that there are probably differences in how our SAMD51 Arduino implementation differs from the CircuitPython implementation. We may have favored speed at the cost of some accuracy. I will look at that in more detail, but as adafruit2 says, if you are looking for accuracy, using a purpose-built ADC breakout is going to be much better.

danhalbert
 
Posts: 2430
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Wed May 05, 2021 1:45 pm

danhalbert wrote:We may have favored speed at the cost of some accuracy.

Is it not possible to give an end user certain control over what they want to sacrifice instead of finding a one-size-fits-all solution?

Bekar_T
 
Posts: 22
Joined: Wed Apr 21, 2021 12:41 am

Re: ADC readings off on Itsy Bitsy M4

by danhalbert on Wed May 05, 2021 2:20 pm

There are about a dozen different knobs to twist on the ADC settings, including resolution, scaling, voltage reference, sampling time, oversampling, offset compensation (which is partly broken, according to the errata document), etc. So we didn't provide an API for all of those: it takes space to hold the code and time to create it. We are creating an API for the majority of uses, but not all. The Arduino API provides control over the resolution, but not much else. To do what you want would require C programming close to the metal.

The non-linearity your are seeing appears to be inherent. There are calibration values that are stored on each chip at the factory, and we apply those, but they are not perfect. We have seen similar issues on the ESP32-S2.

The SAMD21 ADC is better than the SAMD51 ADC, which seems to suffer from a number of design defects. Both only have 8 or 9 bits of effective accuracy when you look in detail at the data sheets. See the Electrical Characteristics for single-end ADC operation. Differential operation would be better, but that's yet more complicated.

I looked at the Arduino vs the CircuitPython code and I don't see a difference in the way the ADC is setup.

In general, when confronted with a non-linear and noisy transducer, your best bet is to use your own calibration calculations, and calibrate against more accurate standards. For noise, averaging helps.

I'm not sure what you application is here, but you appear to want to measure voltages that can be down in the noise. Differential use of a higher-quality ADC would help.

danhalbert
 
Posts: 2430
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Wed May 05, 2021 2:49 pm

danhalbert wrote:The non-linearity your are seeing appears to be inherent. There are calibration values that are stored on each chip at the factory, and we apply those, but they are not perfect. We have seen similar issues on the ESP32-S2.

The SAMD21 ADC is better than the SAMD51 ADC, which seems to suffer from a number of design defects. Both only have 8 or 9 bits of effective accuracy when you look in detail at the data sheets.

I realize that there are certain inherent limitations, but the fact that there's a five fold difference between max error of the same block of code running on Itsy M0 and Xiao, makes me think that perhaps there's a similar headroom for improvement on M4 too.

If max delta was 10mv instead of 50mv, to me at least, that would make a world of difference.

Bekar_T
 
Posts: 22
Joined: Wed Apr 21, 2021 12:41 am

Re: ADC readings off on Itsy Bitsy M4

by adafruit_support_bill on Wed May 05, 2021 3:06 pm

Of the boards I have here on my bench, the average deviation is different for each - indicating that there is some variability per chip. As a whole, the SAMD21 boards seem to deviate less than the SAMD51 boards. This is consistent with Dan's observation that the SAMD51 chip has some design issues in the analog section.

As with any system, for critical accuracy, you need to calibrate in place: https://learn.adafruit.com/calibrating- ... -calibrate

adafruit_support_bill
 
Posts: 81319
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

by danhalbert on Wed May 05, 2021 3:12 pm

Note that we have not enabled offset compensation (REFCOMP) because the errata doc says you have to discard five readings before the value stabilizes. So that may be causing the variation among samples. Right now we don't track other uses of the ADC so we don't know when the five times has passed. We could just read six times every time, but that seemed excessive.

We have had other problems with the ADC circuitry. The internal temperature monitoring works sometimes but other times can simply cause the ADC to hang. It varies by chip sample, not even by revision.

danhalbert
 
Posts: 2430
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Thu May 06, 2021 12:53 am

I took some more readings, did some regression analysis and it turns out that in my case, the error is pretty reliably at 2% of the reading (with R^2 of 0.92).

I will waste some cycles and compensate in the code but does this perhaps hint at a culprit more specifically?

Bekar_T
 
Posts: 22
Joined: Wed Apr 21, 2021 12:41 am

Please be positive and constructive with your questions and comments.