ADC readings off on Itsy Bitsy M4
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- blnkjns
- Posts: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: ADC readings off on Itsy Bitsy M4
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".
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADC readings off on Itsy Bitsy M4
I see similar results on an M4 Grand Central board. I'll check with the CircuitPython team.
- blnkjns
- Posts: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: ADC readings off on Itsy Bitsy M4
Maybe you can fix the range in Circuitpython as well. It is weird that a ADC with 12 bits resolution outputs 0-65535
- Bekar_T
- Posts: 22
- Joined: Wed Apr 21, 2021 12:41 am
Re: ADC readings off on Itsy Bitsy M4
Any updates on this?
Is there a way I could adjust the periphery initialization parameters myself?
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
No resolution? No updates? No nothing?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADC readings off on Itsy Bitsy M4
I'll ping the CircuitPython team again regarding this issue...
- adafruit2
- Posts: 22144
- Joined: Fri Mar 11, 2005 7:36 pm
Re: ADC readings off on Itsy Bitsy M4
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!"
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!"
- danhalbert
- Posts: 4649
- Joined: Tue Aug 08, 2017 12:37 pm
Re: ADC readings off on Itsy Bitsy M4
We scale everything to 16 bits so the range is uniform. In the future we might make it possible to change the resolution.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
- danhalbert
- Posts: 4649
- Joined: Tue Aug 08, 2017 12:37 pm
Re: ADC readings off on Itsy Bitsy M4
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.
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.
- Bekar_T
- Posts: 22
- Joined: Wed Apr 21, 2021 12:41 am
Re: ADC readings off on Itsy Bitsy M4
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?danhalbert wrote:We may have favored speed at the cost of some accuracy.
- danhalbert
- Posts: 4649
- Joined: Tue Aug 08, 2017 12:37 pm
Re: ADC readings off on Itsy Bitsy M4
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.
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.
- Bekar_T
- Posts: 22
- Joined: Wed Apr 21, 2021 12:41 am
Re: ADC readings off on Itsy Bitsy M4
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.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.
If max delta was 10mv instead of 50mv, to me at least, that would make a world of difference.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADC readings off on Itsy Bitsy M4
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
As with any system, for critical accuracy, you need to calibrate in place: https://learn.adafruit.com/calibrating- ... -calibrate
- danhalbert
- Posts: 4649
- Joined: Tue Aug 08, 2017 12:37 pm
Re: ADC readings off on Itsy Bitsy M4
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.
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.
- Bekar_T
- Posts: 22
- Joined: Wed Apr 21, 2021 12:41 am
Re: ADC readings off on Itsy Bitsy M4
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?
I will waste some cycles and compensate in the code but does this perhaps hint at a culprit more specifically?
Please be positive and constructive with your questions and comments.