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

JeffGray
Posts: 4
Joined: Mon Oct 09, 2017 4:25 am

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

Postby JeffGray » Mon Oct 09, 2017 4:34 am

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...
Attachments
ESP32-S ADC Mapping 11-bit.xlsx
(13.51 KiB) Downloaded 1186 times
ESP32-S ADC Mapping - 12-bit.xlsx
(15.77 KiB) Downloaded 1076 times

vseven
Posts: 21
Joined: Wed Aug 30, 2017 3:22 am

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

Postby vseven » Mon Oct 09, 2017 2:17 pm

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.

Azaelyus
Posts: 13
Joined: Tue Oct 24, 2017 7:38 pm

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

Postby Azaelyus » Wed Oct 25, 2017 11:04 pm

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!!!!

vseven
Posts: 21
Joined: Wed Aug 30, 2017 3:22 am

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

Postby vseven » Thu Oct 26, 2017 2:43 pm

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.

Azaelyus
Posts: 13
Joined: Tue Oct 24, 2017 7:38 pm

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

Postby Azaelyus » Thu Oct 26, 2017 6:12 pm

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?

vseven
Posts: 21
Joined: Wed Aug 30, 2017 3:22 am

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

Postby vseven » Fri Oct 27, 2017 12:28 pm

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

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

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

Postby ESP_Dazz » Tue Oct 31, 2017 6:45 am

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"

vseven
Posts: 21
Joined: Wed Aug 30, 2017 3:22 am

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

Postby vseven » Tue Oct 31, 2017 2:44 pm

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?

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

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

Postby ESP_krzychb » Tue Oct 31, 2017 3:47 pm

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

hgptamn
Posts: 26
Joined: Mon Oct 16, 2017 4:47 pm

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

Postby hgptamn » Thu Feb 01, 2018 11:53 am

Getting an official answer from Espressif, they do plan on fixing the factory calibration in the near future
Attachments
Screenshot_1.png
Screenshot_1.png (9.96 KiB) Viewed 23001 times

Who is online

Users browsing this forum: Bing [Bot] and 58 guests