Page 1 of 1

ADC values less than half of expected

Posted: Mon Mar 18, 2024 10:32 pm
by glrtheil
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?

Re: ADC values less than half of expected

Posted: Tue Mar 19, 2024 4:04 am
by ESP_Sprite
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.

Re: ADC values less than half of expected

Posted: Tue Mar 19, 2024 4:16 am
by chegewara
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