Using two ADC pins influences analog input voltage readings



  • Hi,

    up until now, I have only used P13 as an analog input pin and everything worked as expected. But today, I also started using P16 and noticed that both pins now report values that are too high. For example, on P16 I read a voltage of 2.85 instead of 2.5 as measured with my multimeter. If I only use one adc pin, I read the expected voltage. Does anyone has an explanation for this?

    For both pins, I use ADC.ATTN_11DB.



  • @moewex The 4095 is the highest value of the 12 bit ADC. So you could try to call apin.value() instead of just apin, which seems to return the voltage value, which has to be calibrated beforehand. The noise and fluctuation will always be large. So you have to add some kind of lowpass or averaging. For the moisture application with ist slow change, using a digital lowpass filter/averaging is surely appicable. And you do not have to care for absolute precision, just consistency.



  • @robert-hh The moisture sensor output is somewhere between 1V and 2.5V (roughly), so I had not to translate it (where does the 4095 come from anyhow?) :).

    The link you provided is helpful, thank you! So it seems to be an ESP32 problem (which is good to know). By adding a capacitor to the input (connected between input pin and ground, right?), I should be able to reduce the noise and maybe improve the accuracy, don't I? But I guess the best solution is to add more voltage dividers so that I can use a lower attenuation... . Maybe it would be worthwhile adding such a note to the documentation



  • @moewex So you translated than the values in the range 0..4095 yourself into a voltage? Then you should test the real range in advance. These devices do NOT have it's full range at 3.3V. See also here: https://www.esp32.com/viewtopic.php?f=19&t=2881&sid=ed97d32cb10488d58c6d4947d68cb59f&start=10
    The best linearity is at 6dB attenuation.
    The impedance affects mostly the noise. I typically put a small capacitor at the input, like 1 .. 10 nF, which also lowers the impedance.
    Edit: I should add that the ADC of the ESP32 is lousy. The effective resolution you get is about 9 bit. Everything else is noise. If you need precise values, use an external ADC, like from Analog Devices.



  • @robert-hh . For the measurements, I did adc_value() as I essentially just execute the quick usage example.

    I am measuring the analog output of a soil moisture sensor, so the impedance should not be a problem here, right?

    But I tried to also measure the voltage of voltage divider with two 100kOhm resistors, is this problematic?



  • @moewex No, i do not see a pattern except that the ratio is increasing with the voltage, like a non-linear effect. The ESP32 ADC is known for bad linearity. Did you use adc_voltage() or adc_value() for reading the ADC. It may be interesting to try adc_value().
    And you should use a low impedance input (< 10 kOhm).



  • Hi, thx for the response @robert-hh! I double checked, but I only have one power source and am also pretty sure that this is not the reason.

    Furthermore, I did additional testing and somehow the values are now also off if only one adc is measuring as well. I am pretty sure this has not been the case before, but now every value is always slightly too high. Is it possible that I messed up the internal calibration or so?

    I measured four different values (with both my voltmeter and and wipy). These are the results (voltmeter --- wipy --- factor the wipy is to high):

    2.69 --- 3.161 --- 1.175
    2.31 --- 2.642 --- 1.144
    1.62 --- 1.791 --- 1.106
    1.44 --- 1.581 --- 1.098

    As the value differences are not constant, I cannot just calculate "the real" values, or does anyone see a pattern?



  • @moewex GND offset? Are you sure, that the input ciruits have a proper low impedance connection to GND?


Log in to reply
 

Pycom on Twitter