Page 2 of 5

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Wed Sep 06, 2017 5:12 am
by tele_player
Interesting, it never occurred to me that he wasn't calling the functions - that would definitely explain it.

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Wed Sep 06, 2017 12:35 pm
by vseven
I didn't know I had to call those within a function so they kept throwing "expected constructor, destructor, or type conversion before '(' token", I was trying to put them with my define lines since I thought they needed to be called before anything else and logically that made sense to me. So when they threw errors I looked at the examples and made them match which now I realize, as you pointed out, I was just defining them and not calling them.

I put them into my setup() and now they compile correctly. I'll test it tonight and see if it worked. Thanks.

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Wed Sep 06, 2017 4:40 pm
by vseven
FYI - my results after making the changes for anyone that could use it:
ESP32-ADC-12-Bit.png
ESP32-ADC-12-Bit.png (17.56 KiB) Viewed 30048 times
ESP32-ADC-11-Bit.png
ESP32-ADC-11-Bit.png (19.81 KiB) Viewed 30048 times
Orange = 6db attenuation
Blue = 11db attenuation

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Wed Sep 06, 2017 4:42 pm
by vseven
Apparently there is a three file max on posts so here is the raw data

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 12:15 am
by mnemonix
The -6dB range with 11 bits looks quite linear, if only this 0.1V offset would not exist.
But for your application with a 0..10V Input you need anyway an external resistor voltage divider, so you can just add a third resistor to lift the voltage by 0.1 V. Here is a possible circuit:
ADC0-10V.png
ADC0-10V.png (4.82 KiB) Viewed 30159 times

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 1:21 am
by vseven
My sensors are actually 4-20ma that I'm converting already with a current -> voltage adapter. The one i have lets me change the zero and max so i have it set for what seemed to be the most linear part of the range which was 0.20v (105 on ADC) and ending at 1.85v (1980 on ADC). I then scalled my sensors, temperature and humidity, to map to that ADC range.

Actual Temp: 61.96* / ESP32 Temp: 62.42*
Actual Humidity: 62.14% / ESP32 Humidity: 62.17%

I'm only reading every minute and a thunderstorm was rolling in (temp was dropping rapidly) so I'm calling it a success even with the slight difference in temperature. I also did a max range test, sending 4ma down the 20ma and i was within 0.1% of both high and low ends.

HUGE difference in linearity using 6db and in reduction of noise using 11-bit.

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 2:30 am
by tele_player
What are you using to determine actual temperature and humidity?

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 2:42 am
by vseven

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 3:11 pm
by tele_player
Interesting.
You compare actual to ESP32 above. What was being compared?

Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?

Posted: Thu Sep 07, 2017 3:16 pm
by vseven
I have a commercial grade device that reads 4 - 20ma and scaled the temp and humidity for those readings. I compared that to known good calibrated temperature and humidity sensors. Once that was calibrated I used that reading against the ESP32 reading to verify the accuracy.