esp32-s2 adc configuration and attenuation
Posted: Thu Jul 08, 2021 6:20 pm
Hi there,
I'm having a bit of an issue grasping the attenuation of the ADC. According to the documentation the voltage range is dependent on the attenuation and "By setting higher attenuation it is possible to read higher voltages." https://docs.espressif.com/projects/esp ... dc_atten_t
Although doing some tests with the latest esp-idf (4.4/master branch), I'm really not seeing any differences changing the attenuation. Regardless of the configured attenuation (from 0db to 11db) I get a reading from 0 to 8191 in the voltage range 0 -- ~2.5v. Even at 0db attenuation I get a reading for 1.0v--2.5V and at 11db attenuation is can't read anything above ~2.5v (but still down to 0v)
My setup is very simple, I've got a potentiometer as a voltage divider connect to channel 0 on an esp32-s2.
Reading the documentation I would expect the ADC reading to saturate when the voltage is above the range of the attenuation (e.g 2v at 0db attenuation to be either 8191 or a fixed value once the voltage is too high for that attenuation).
Anything obvious i'm missing here? Is it just that if the voltage read isn't in the suggested range for the attenuation then it won't be accurate? If so is it simply a matter of shifting attenuation at certain thresholds?
Thanks"
I'm having a bit of an issue grasping the attenuation of the ADC. According to the documentation the voltage range is dependent on the attenuation and "By setting higher attenuation it is possible to read higher voltages." https://docs.espressif.com/projects/esp ... dc_atten_t
Although doing some tests with the latest esp-idf (4.4/master branch), I'm really not seeing any differences changing the attenuation. Regardless of the configured attenuation (from 0db to 11db) I get a reading from 0 to 8191 in the voltage range 0 -- ~2.5v. Even at 0db attenuation I get a reading for 1.0v--2.5V and at 11db attenuation is can't read anything above ~2.5v (but still down to 0v)
My setup is very simple, I've got a potentiometer as a voltage divider connect to channel 0 on an esp32-s2.
Reading the documentation I would expect the ADC reading to saturate when the voltage is above the range of the attenuation (e.g 2v at 0db attenuation to be either 8191 or a fixed value once the voltage is too high for that attenuation).
Anything obvious i'm missing here? Is it just that if the voltage read isn't in the suggested range for the attenuation then it won't be accurate? If so is it simply a matter of shifting attenuation at certain thresholds?
Thanks"
Code: Select all
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <soc/adc_channel.h>
#include <soc/rtc.h>
#include <driver/adc.h>
#include <esp_adc_cal.h>
#include <esp_log.h>
static const char* TAG = "test";
void app_main() {
adc1_config_width(ADC_WIDTH_BIT_13);
adc1_config_channel_atten(ADC1_GPIO1_CHANNEL, ADC_ATTEN_11db);
for (;;) {
int raw = adc1_get_raw(ADC1_GPIO1_CHANNEL);
ESP_LOGI(TAG, "%d", raw);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}