ESP32 ADC voltage drop after some hours

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

ESP32 ADC voltage drop after some hours

Post by kevinkk525 » Tue Mar 24, 2020 7:37 am

I'm using an ESP32 to measure the EC value of water (my nutrient solution for a hydroponics system, measurements based on https://hackaday.io/project/7008-fly-wa ... er-arduino).

I finally got it working and after a little calibrating the ADC it is quite accurate and I was really happy. But then I noticed that after 4 hours of operation, the measured voltage quickly rose to a higher level, from ~0.91V to ~1.07 and then stayed there until I did a hard reset by button (by machine.reset() doesn't help) a day later. Then the measured voltage levels were back at ~0.91V.
The measurements in the higher range (~1.5V) were not affected or it wasn't that obvious because in that range the PPM value doesn't change that drastically so I probably was ok with it and didn't notice the error.

This is visible in the following picture (note that this represents PPM/EC and therefore the value drops while the voltage rises).
Unbenannt.PNG
PPM drop
Unbenannt.PNG (6.26 KiB) Viewed 143 times
After a hard reset (by button after a cpu crash) it went back to the original value (ignore the short low value, I changed the measured fluid before hitting the reset):
Unbenannt1.PNG
PPN after reset
Unbenannt1.PNG (7.46 KiB) Viewed 143 times

For measurements this is the procedure:
GPIO providing 3.3V -> PowerPin
GPIO providing GND -> GndPin

Connection is like this picture: http://www.element14.com/community/serv ... Pinout.png

While not measuring, both Powerpin and GndPin are set to INPUT to be high impedance because I didn't want to have my fluid connected to a GND all the time.
When measuring, GndPin is set to GND, PowerPin is set to Vcc (both in Output mode) and then quickly measured by ADC. After that put back in the original high impedance input state.
Measurement happens every minute.


Does anyone have any idea how this behaviour is possible? It makes using the ESP32 quite unreliable..
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 4014
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 ADC voltage drop after some hours

Post by pythoncoder » Tue Mar 24, 2020 7:52 am

I suggest you make a minimal test case. Repeat the test replacing your circuit with a low impedance voltage divider or a precision voltage source.

I can't envisage an artefact coming from the measuring device. But that may prove something about my skill rather than about your kit ;)
Peter Hinch

kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP32 ADC voltage drop after some hours

Post by kevinkk525 » Tue Mar 24, 2020 2:26 pm

Looks like I just got lucky a few times because now I can even unplug the board and it still doesn't drop back to the "correct" voltage level.. I now changed the way it measures and use IDF3.3 and for now it is correct, let's see for how long..
Looks like the ESP32 adc is shifting quite a bit for no obvious reasons.

But you are right, I should make a more minimal test-setup with a real voltage divider and do some long-term tests on these.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 4014
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 ADC voltage drop after some hours

Post by pythoncoder » Wed Mar 25, 2020 6:52 am

There seem to me to be three possible sources of error:
  • The ADC.
  • The pin supplying the voltage to the circuit. This voltage may depend on the on-board voltage regulator or possibly some on-chip power control circuitry.
  • The actual measuring device.
If it's the first, it would be good to know about it.

The second could easily be fixed with external electronics.

The third? The ball's in your court there ;)
Peter Hinch

User avatar
tve
Posts: 91
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: ESP32 ADC voltage drop after some hours

Post by tve » Wed Mar 25, 2020 4:47 pm

A fourth possibility may be temperature. I forget how temp compensation works with the esp32 ADC... I'm pretty sure that the internal die temperature can change rapidly due to radio operation, much more rapidly than chip package surface temp.

User avatar
pythoncoder
Posts: 4014
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 ADC voltage drop after some hours

Post by pythoncoder » Thu Mar 26, 2020 10:58 am

Very good point.
Peter Hinch

kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP32 ADC voltage drop after some hours

Post by kevinkk525 » Thu Mar 26, 2020 7:53 pm

I have to do some more proper testing with stable resistors but so far this is what I was able to find out:

The initial voltage is quite wrong and only lasts about 4-6 hours, then it'll rise by about 0.1V. This stays stable during the ongoing operation of the esp32 (currently 2 days) and typically doesn't change when shortly resetting the board to update files. So the initial measurements are actually worthless and I need to wait those 4-6 hours for the readings to be stable.

I have temperature changes in the room ranging from 16 to 22°C and due to the water temperature changing as well, the voltage changes slightly but because the EC measurement is also temperature compensated, the result stayed about the same. So the temperature compensation of the ADC seems to be acceptable. I will confirm that in the next test with real resistors.
It may be possible that the on-chip temperature affects the readings and that it takes 4-6 hours for the ESP32 to reach a stable temperature on the chip? However, that wouldn't result in a sudden change of Voltage, it would slowly change over time and it would change with the load of the chip, not suddenly change and then stay at a certain level.

The overall precision of the ADC is quite strange. I am able to calibrate the readings in software to get the readings within 1% of the theoretical voltage but it requires a quite interesting formula. Reason is that the ESP32 ADC is not linear, it returns 0 at ~0.1V and maxes out at somewhere over 3V (not actually tested). So the compensation formula is U=3.4x+0.112 and when using ATTN_6DB (max 2.2V) it is a lot more extrem with U=1.853x + 0.068

The pin supplying the voltage to the circuit should be fine. Whenever I measured manually, the voltage was stable 3.3V. Also there is not much load on the board and the circuit that could cause a drop in the supply voltage. However, the current way of measuring only pulls the pin high for a few us so it might behave differently than when pulled high all the time so I can measure it manually. However, a sudden change in voltage but otherwise stable operation caused by some pin problems seems odd.

My actual measuring device is a HP-90EPC which was quite accurate compared to the theoretical voltage when I was measuring the voltages for the ADC calibration. (simple voltage dividers measured to ground)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP32 ADC voltage drop after some hours

Post by kevinkk525 » Fri Mar 27, 2020 6:45 am

So I let it run through the night with a voltage divider of 470R and 300R. The voltage didn't change. Temperature in the room changed from 22C to 17C and back to 20C right now. Voltage was always stable. So at least for this temperature range the ADC works reliable.
It also confirms that the ADC generally works stable, once it reaches this stable state.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 4014
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 ADC voltage drop after some hours

Post by pythoncoder » Fri Mar 27, 2020 7:24 am

I did some measurements on the DAC which showed errors of up to 3.3% so I can't say I'm surprised. For accurate measurements you need quality hardware. A Pyboard ;)
Peter Hinch

kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP32 ADC voltage drop after some hours

Post by kevinkk525 » Fri Mar 27, 2020 7:33 am

pythoncoder wrote:
Fri Mar 27, 2020 7:24 am
I did some measurements on the DAC which showed errors of up to 3.3% so I can't say I'm surprised. For accurate measurements you need quality hardware. A Pyboard ;)
Yeah I know the ESP32 is shitty hardware for precision work :lol:
However, after calibration it is quite accurate. I can hook up a 300R resistor and have <2% error, which is absoltely fine in my case. The only question that remains is if it stays this accurate the whole time and independent of big temperature changes..

I'd love to use a pyboard but that is quite outside of my budget for this little garden project. If the esp32 internal ADC doesn't work out, I will consider buying an I2C ADC, those *should* be good enough too. Or I'll just use an Atmega328 that I connect using OneWire protocol :D (but haven't checked how accurate those are)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply