ADC readings off on Itsy Bitsy M4

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: ADC readings off on Itsy Bitsy M4

Post by blnkjns »

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".

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

Post by adafruit_support_bill »

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

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: ADC readings off on Itsy Bitsy M4

Post by blnkjns »

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

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

Re: ADC readings off on Itsy Bitsy M4

Post by Bekar_T »

Any updates on this?

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

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

Re: ADC readings off on Itsy Bitsy M4

Post by Bekar_T »

No resolution? No updates? No nothing?

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

Post by adafruit_support_bill »

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

User avatar
adafruit2
 
Posts: 22144
Joined: Fri Mar 11, 2005 7:36 pm

Re: ADC readings off on Itsy Bitsy M4

Post by adafruit2 »

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!"

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

Post by danhalbert »

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.

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

Post by danhalbert »

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.

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

Re: ADC readings off on Itsy Bitsy M4

Post by Bekar_T »

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?

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

Post by danhalbert »

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.

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

Re: ADC readings off on Itsy Bitsy M4

Post by Bekar_T »

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.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC readings off on Itsy Bitsy M4

Post by adafruit_support_bill »

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

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC readings off on Itsy Bitsy M4

Post by danhalbert »

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.

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

Re: ADC readings off on Itsy Bitsy M4

Post by Bekar_T »

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?

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”