Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.

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

What is the value of the resistors used?

blnkjns

Posts: 429
Joined: Fri Oct 02, 2020 3:33 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

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

Also please post the code you are using.

Posts: 80997
Joined: Sat Feb 07, 2009 10:11 am

Also please post the code you are using.

Screenshot_20210424_191910.png (37.98 KiB) Viewed 114 times

Code: Select all | TOGGLE FULL SIZE
`import boardimport analogiodac_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

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

Posts: 80997
Joined: Sat Feb 07, 2009 10:11 am

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

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.

Posts: 80997
Joined: Sat Feb 07, 2009 10:11 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-->1810-->2620-->4630-->5040-->5650-->7260-->7870-->9080-->9490-->110100-->114110-->180120-->130130-->164140-->162150-->164160-->172170-->184180-->196190-->210200-->206210-->228220-->236230-->244240-->256250-->272260-->280270-->342280-->296290-->316300-->326310-->330320-->344330-->346340-->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: 429
Joined: Fri Oct 02, 2020 3:33 am

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

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

Posts: 80997
Joined: Sat Feb 07, 2009 10:11 am

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

Please try my code to rule out board malfunctioning.

blnkjns

Posts: 429
Joined: Fri Oct 02, 2020 3:33 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