ADC calibration with VREF

kurtzweber
Posts: 60
Joined: Tue Jan 10, 2017 1:09 pm

ADC calibration with VREF

Postby kurtzweber » Thu Jan 25, 2018 9:01 am

Hi all

I'm trying to follow the instruction on the official documentation to calibrate the ADC:
https://esp-idf.readthedocs.io/en/lates ... s/adc.html

I was able to route the internal VREF to GPIO25 and read the value with a multimeter, it's 1.146V:

Code: Select all

ESP_ERROR_CHECK(adc2_vref_to_gpio(GPIO_NUM_25));
printf("VREF routed to ADC2, pin 25\n");
Then I tried to develop a program which reads the value using ADC2:

Code: Select all

ESP_ERROR_CHECK(adc2_config_channel_atten(ADC2_CHANNEL_8, ADC_ATTEN_DB_2_5));
ESP_ERROR_CHECK(adc2_vref_to_gpio(GPIO_NUM_25));
int adc2_raw_value;
ESP_ERROR_CHECK(adc2_get_raw(ADC2_CHANNEL_8, ADC_WIDTH_12Bit, &adc2_raw_value));
printf("Raw value from ADC2: %d\n", adc2_raw_value);
float voltage = 1.5 * adc2_raw_value / 4095;
printf("Voltage: %.4f\n", voltage);
but the value read is very different from the one I see on the multimeter (1.260V). I tried different attenuation values but the calculated voltage is always different (greater)... I also used 0db attenuation but in that case (as expected) the ADC saturates to 4095.

Am I missing something? Is this the correct way to do what is explained in the doc:
Routing ADC reference voltage to GPIO, so it can be manually measured and entered in function esp_adc_cal_get_characteristics():
I also gave a look to the example provided:
https://github.com/espressif/esp-idf/bl ... ple_main.c

but it doesn't seem to read the vref value if V_REF_TO_GPIO is defined, it only routes the value to the pin:

Code: Select all

#else
    //Get v_ref
    esp_err_t status;
    status = adc2_vref_to_gpio(GPIO_NUM_25);
    if (status == ESP_OK){
        printf("v_ref routed to GPIO\n");
    }else{
        printf("failed to route v_ref\n");
    }
    fflush(stdout);
#endif
Thanks!

WiFive
Posts: 2546
Joined: Tue Dec 01, 2015 7:35 am

Re: ADC calibration with VREF

Postby WiFive » Thu Jan 25, 2018 12:09 pm

Once you read the voltage with a meter then you go here https://esp-idf.readthedocs.io/en/lates ... ted-values

kurtzweber
Posts: 60
Joined: Tue Jan 10, 2017 1:09 pm

Re: ADC calibration with VREF

Postby kurtzweber » Thu Jan 25, 2018 12:17 pm

Hi

thanks for your reply... I was able indeed to use the read value in:
esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, &characteristics);

but this method assumes you measure the voltage for each board you program and adapt the code accordingly... I was looking for a "software-only" method and reading the VREF with ADC2 seemed a good approach... but I cannot get good values.

WiFive
Posts: 2546
Joined: Tue Dec 01, 2015 7:35 am

Re: ADC calibration with VREF

Postby WiFive » Thu Jan 25, 2018 12:21 pm

ADC2 is just as uncalibrated as ADC1. So yes you need an external calibration value per each chip until they start doing it at the factory.

kurtzweber
Posts: 60
Joined: Tue Jan 10, 2017 1:09 pm

Re: ADC calibration with VREF

Postby kurtzweber » Thu Jan 25, 2018 12:54 pm

Undestood, thanks!

User avatar
HelWeb
Posts: 31
Joined: Sat Mar 23, 2019 8:39 am

Re: ADC calibration with VREF

Postby HelWeb » Sat Aug 10, 2019 8:20 pm

Maybe you may want to test:

esp32.com/viewtopic.php?f=19&t=2881&start=30

Posted: Sat Aug 10, 2019 12:30 pm

You may calibrate your own ESP32( the nonlinear 11DB curve) with this program.<br>
All you need is a wire from pin 25 to pin 35 and a normal voltmeter.<br>

Calibration is done automatically.<br>
It produces a LookUpTable[4096] to correct your values like: <br>
CalibratedValue = LookUpTable[Read Value];<br>

I do NOT use a fitted curve but a real LookUpTable with 4096 values !

I get correct values +/- 0.01V compared to the voltmeter. :D
Fast is not fast enough :D

Who is online

Users browsing this forum: No registered users and 17 guests