ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
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...
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
Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
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.
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?
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!!!!
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?
Not sure what you mean for wiring, the voltage goes to a analog input pin and the ground to a standard ground pin.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!!!!
As for reading its just a analogRead of the pin.
Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
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?
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 ... Sw8HBZHt5eAzaelyus 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?
Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
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 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 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
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()
Code: Select all
esp_adc_cal_raw_to_voltage()
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?
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?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.
- 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?
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#p11351vseven 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?
Re: ESP32 ADC Non-linear Issues - How do I fix / change Attenuation or width?
Getting an official answer from Espressif, they do plan on fixing the factory calibration in the near future
- Attachments
-
- Screenshot_1.png (9.96 KiB) Viewed 23011 times
Who is online
Users browsing this forum: No registered users and 42 guests