0

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

Please be positive and constructive with your questions and comments.

ADC readings off on Itsy Bitsy M4

by Bekar_T on Fri Apr 23, 2021 10:26 am

I'm feeding a voltage from resistive divider into adc and readings are both unstable and imprecise.

As an experiment I output adc voltage into a dac and fed it into another adc to print out the delta at different input voltages.

What I see is that reading is spot on while input is at about 1.3V, lower the input voltage goes the delta goes into negative values reaching almost -0.1 volts near 0, and approximately 0.1 volts at 2.6 input.

In other words, it reads low when input is above 1.3V and high when it goes lower.

Anyone seen this kinda behavior?

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

Re: ADC readings off on Itsy Bitsy M4

by blnkjns on Fri Apr 23, 2021 10:50 am

What is the value of the resistors used?

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Fri Apr 23, 2021 11:02 am

It occured to me that it could have been the matter of impedance, so I tried using a much lower value resistor too. Not much changed.

What I'm normally using is 33K but for an experiment I tried a 5K pot.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Sat Apr 24, 2021 10:58 am

Nobody has encountered this problem before?

Can someone point me to literature where it's described how I can adjust the ADC parameters?

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 Sat Apr 24, 2021 11:04 am

Please post some photos showing your circuit.
Also please post the code you are using.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Sat Apr 24, 2021 11:27 am

adafruit_support_bill wrote:Please post some photos showing your circuit.
Also please post the code you are using.


Screenshot_20210424_191910.png
Screenshot_20210424_191910.png (37.98 KiB) Viewed 262 times


Code: Select all | TOGGLE FULL SIZE
import board
import analogio

dac_0 = analogio.AnalogOut(board.A0)
dac_1 = analogio.AnalogOut(board.A1)
adc_4 = analogio.AnalogIn(board.A4)
adc_5 = analogio.AnalogIn(board.A5)

for i in range(1000):
    print(adc_4.value / 65535 * adc_4.reference_voltage)
    time.sleep(0.1)

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 Sat Apr 24, 2021 1:13 pm

Please post a photo of the actual circuit so we can see all the connections.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Sat Apr 24, 2021 2:30 pm

adafruit_support_bill wrote:Please post a photo of the actual circuit so we can see all the connections.


To eliminate all circuit factors I just connected A0 and A4 pins with a jumper wire and ran this code:

Code: Select all | TOGGLE FULL SIZE
dac_0 = analogio.AnalogOut(board.A0)
adc_4 = analogio.AnalogIn(board.A4)

for i in range(0, 65500, 6550):
    dac_0.value = i
    time.sleep(0.1)
    print((adc_4.value / 65535 * 3.3)-(i / 65535 * 3.3))


I get very similar results repeatably:

0.00483406
0.00050354
0.00100708
0.0111787
0.0245733
0.0347443
0.0336375
0.0421982
0.0507574
0.0512609

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 Sun Apr 25, 2021 5:58 am

Looks like it is reading high by as much as 51mv. Try with a different set of pins to see if the result is the same. Also, print out the value of 'i' so we can see what the expected voltage should be.

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

Re: ADC readings off on Itsy Bitsy M4

by blnkjns on Sun Apr 25, 2021 7:06 am

Try this in the Arduino IDE, if it yields similar results as I got, the board works. I tried the same (the simple one, wire between A0 and A4), with these results:
Code: Select all | TOGGLE FULL SIZE
0-->18
10-->26
20-->46
30-->50
40-->56
50-->72
60-->78
70-->90
80-->94
90-->110
100-->114
110-->180
120-->130
130-->164
140-->162
150-->164
160-->172
170-->184
180-->196
190-->210
200-->206
210-->228
220-->236
230-->244
240-->256
250-->272
260-->280
270-->342
280-->296
290-->316
300-->326
310-->330
320-->344
330-->346
340-->356

Using this code:
Code: Select all | TOGGLE FULL SIZE
void setup() {
  analogWriteResolution(12);
  analogReadResolution(12);
  Serial.begin(9600);
}

void loop() {
  for (int n=0;n<4096;n+=10){
    analogWrite(A0,n);
    delay(20);
    Serial.print(n);
    Serial.print("-->");
    Serial.println(analogRead(A4));
    delay(20);
  }
}

So it is slightly off, but nowhere noisy.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Sun Apr 25, 2021 4:46 pm

adafruit_support_bill wrote:Looks like it is reading high by as much as 51mv. Try with a different set of pins to see if the result is the same. Also, print out the value of 'i' so we can see what the expected voltage should be.


I switched to pins A1 and A5, here are the results from 2 consecutive tries:

0.0112795 0
0.00050354 6550
0.00100708 13100
0.00473332 19650
0.0245733 26200
0.0315213 32750
0.0384717 39300
0.0470314 45850
0.0443125 52400
0.044816 58950

0.00966811 0
-0.00433052 6550
0.00261831 13100
0.00473332 19650
0.0245733 26200
0.0363555 32750
0.0336375 39300
0.0438089 45850
0.0443125 52400
0.0512609 58950

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 Sun Apr 25, 2021 4:58 pm

Also, print out the value of 'i' so we can see what the expected voltage should be.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Sun Apr 25, 2021 10:29 pm

adafruit_support_bill wrote:Also, print out the value of 'i' so we can see what the expected voltage should be

They are right there after the space. Didn't come to mind how to format it prettier.

I took new readings just in case, in here, columns go actual value, expected value, delta:

0.0112795 , 0.0 , 0.00483406
0.327104 , 0.329824 , -0.00594187
0.663877 , 0.659647 , -0.000604153
1.00387 , 0.989471 , 0.00312209
1.34548 , 1.31929 , 0.0245733
1.68709 , 1.64912 , 0.0379667
2.01419 , 1.97894 , 0.0320258
2.34774 , 2.30876 , 0.0325298
2.67646 , 2.63859 , 0.0427008
3.01645 , 2.96841 , 0.0560951

0.0128908 , 0.0 , 0.00805676
0.327104 , 0.329824 , -0.00110781
0.662266 , 0.659647 , -0.000604153
0.994204 , 0.989471 , 0.0111787
1.34387 , 1.31929 , 0.0245733
1.69837 , 1.64912 , 0.0347443
2.0158 , 1.97894 , 0.0336375
2.34935 , 2.30876 , 0.037364
2.68451 , 2.63859 , 0.0459232
3.01001 , 2.96841 , 0.044816

You can see how the values fluctuate given the same exact conditions only seconds apart, so I guess that's what I'm refering to with "unstable".

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

Re: ADC readings off on Itsy Bitsy M4

by blnkjns on Mon Apr 26, 2021 12:09 am

Please try my code to rule out board malfunctioning.

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

Re: ADC readings off on Itsy Bitsy M4

by Bekar_T on Mon Apr 26, 2021 12:47 am

blnkjns wrote:Please try my code to rule out board malfunctioning.


I've actually never coded these boards in anything but Python so I'm not sure what adjustments are necessary to run an arduino code.

For further experiments though I ran the same code in same configuration on Itsy M0 and Seeeduino Xiao.

On M0 I got about half the error of M4, but a lot more randomly, instead of how it is on M4, where error increases pretty neatly with voltage.

So the biggest delta I got while running that code on M0 was about 25mv and on Xiao it was generally less than a 2mv, very occasionally going up to 5mv.

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

Please be positive and constructive with your questions and comments.