ADC values less than half of expected

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

ADC values less than half of expected

Postby glrtheil » Mon Mar 18, 2024 10:32 pm

I've got a project we're working on where we are implementing a hardware ID process, using the ADC and a GPIO for a vref. This is an ESP32_WROOM_32UE on ESP-IDF 4.3.7

Essentially we have a voltage divider that is on SENSOR_VP (GPIO36/ADC1_CHANNEL_0) and GPIO_13
Image

The code is pretty straightforward. Sets the vref GPIO, attenuation, then gets a reading from ADC1 CH0.

Code: Select all

    adc2_vref_to_gpio(GPIO_NUM_13);

    adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0);

    adc1_config_width(ADC_WIDTH_BIT_12);
    while (1)
    {
        int raw_val = adc1_get_raw(ADC1_CHANNEL_0);
        printf("ADC value: %d\n", raw_val);
        vTaskDelay(pdMS_TO_TICKS(500));
    }
The voltage on GPIO13 is 1.029v. The voltage on GPIO36 is 90mV. The expected value is around 358 ((90/1029) * 4095 = 358), however I'm only getting about 90.
Image

When I short GPIO13 to GPIO36, to give it the full reference voltage, I expect to see 4095, but it ends up as this:
Image

Any idea why these numbers are so far off what's expected?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: ADC values less than half of expected

Postby ESP_Sprite » Tue Mar 19, 2024 4:04 am

The ADC is not very linear in that region on our original ESP32; also the internal reference voltage varies a bit from chip to chip. Try to use the calibration driver, that should compensate for the reference voltage and partly for the nonlinearity, but you may be better off also changing the resistor divider so the value is more in the middle of the ADC range.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ADC values less than half of expected

Postby chegewara » Tue Mar 19, 2024 4:16 am

Reference voltage 1029mV does not mean you will get 4095 measuring 1029mV on ADC pin.
With this line you get 4095 when you connect 3.3V (assuming ideal conditions)

Code: Select all

adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0); <---- ADC_ATTEN_DB_0

Who is online

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