Page 3 of 5

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

Posted: Mon Oct 09, 2017 4:34 am
by JeffGray
It is not only the offset, but the gain is off as well. I have created ideal lines using the .csv data provided in the thread above (revised files attached). In effect, the 11dB range goes to 3.3V full scale (not 3.6); linear up to 2.6V. The 6dB range goes to 1.8V (not 2V).
In the attached files, you can change cells G1, G2, and I2 to get the best curve fit. Don't change cell I1: that is calculated.

So scale your results accordingly...

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

Posted: Mon Oct 09, 2017 2:17 pm
by vseven
Yeah, thats why I used 0.2 - 1.85 for my range. For me on my chip going up to 1.85 seemed linear still. I have a bad feeling, and based on some other things I've seen, that there is a difference from chip to chip. Makes it kinda hard to mass produce something unless you arbitrarily used like 0.3 - 1.70 to make sure you wouldn't be affected.

With that said my temperature and humidity readings are always within 0.5% of calibrated so I'm happy. If someone needs more precision though they might be in trouble.

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

Posted: Wed Oct 25, 2017 11:04 pm
by Azaelyus
Hello vseven, can u please show me your code for reading the current loop?
Also, if u can provide me your wiring i would be much thankful!!!!

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

Posted: Thu Oct 26, 2017 2:43 pm
by vseven
Azaelyus wrote:Hello vseven, can u please show me your code for reading the current loop?
Also, if u can provide me your wiring i would be much thankful!!!!
Not sure what you mean for wiring, the voltage goes to a analog input pin and the ground to a standard ground pin.

As for reading its just a analogRead of the pin.

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

Posted: Thu Oct 26, 2017 6:12 pm
by Azaelyus
Yeah i know but i wonder how is your 4-20 mA connected.. do u use external power supply? How big resistor do u use?

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

Posted: Fri Oct 27, 2017 12:28 pm
by vseven
Azaelyus wrote:Yeah i know but i wonder how is your 4-20 mA connected.. do u use external power supply? How big resistor do u use?
Oh, I used a current -> voltage converter. I tried doing the resistor thing but it was too hard to get the range correctly. Something like this: https://www.ebay.com/itm/Isolation-Tran ... Sw8HBZHt5e

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

Posted: Tue Oct 31, 2017 6:45 am
by ESP_Dazz
Hi everyone, the ADC calibration issue has actually been addressed in the esp-idf. Please see
https://esp-idf.readthedocs.io/en/lates ... alibration
and https://github.com/espressif/esp-idf/tr ... sp_adc_cal.

Essentially there is a chip to chip variation with regards to the internal LDO that supplies the reference voltage for the ADC on the ESP32. Ideally the ADC reference voltage should be 1100mV, however ESP32s can have reference voltages varying from 1000mV and 1200mV. Therefore the slope of the True Voltage vs ADC-Reading curve will be dependent on the chip's ADC reference voltage.

We've made a function that will route the ADC reference voltage to a GPIO pin so that users can then read the voltage manually with a multi-meter. See https://esp-idf.readthedocs.io/en/lates ... gpio_num_t.

The reference voltage can then be input as a parameter in the function

Code: Select all

esp_adc_cal_get_characteristics() 
of the the esp_adc_cal component. This function essentially calculates the correct shifting and scaling parameters (based on the reference voltage) needed to calibrate the ADC reading to the true voltage. Once the characteristics have been calculated, there is a function called

Code: Select all

esp_adc_cal_raw_to_voltage()
which uses the characteristics and various lookup tables included in the source files in order to convert the raw ADC reading (value from 0 to 4095) to a voltage in mV (for full details, see the API reference of the esp_adc_cal component).

esp-idf functions should be callable in Arduino as long as the correct header files are included. If I recall correctly, the header files that need to be included are

Code: Select all

#include "esp_adc_cal.h"
#include "driver/gpio.h"
#include "driver/adc.h"

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

Posted: Tue Oct 31, 2017 2:44 pm
by vseven
ESP_Dazz wrote:Hi everyone, the ADC calibration issue has actually been addressed in the esp-idf. Please see
https://esp-idf.readthedocs.io/en/lates ... alibration
and https://github.com/espressif/esp-idf/tr ... sp_adc_cal.
So just to be clear this will have to be done for every single chip used? If so that seems very inefficient, especially if trying to use this on a mass scale. Is this going to be fixed in the hardware in the future or is this the best there is, manually reading the output voltage each time and putting in a custom calibration for every chip?

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

Posted: Tue Oct 31, 2017 3:47 pm
by ESP_krzychb
vseven wrote:So just to be clear this will have to be done for every single chip used? If so that seems very inefficient, especially if trying to use this on a mass scale. Is this going to be fixed in the hardware in the future or is this the best there is, manually reading the output voltage each time and putting in a custom calibration for every chip?
Now you need to do it for every single chip used. This going to be fixed in the hardware in the future, see viewtopic.php?f=12&t=2334&p=10942#p11351

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

Posted: Thu Feb 01, 2018 11:53 am
by hgptamn
Getting an official answer from Espressif, they do plan on fixing the factory calibration in the near future