Page 1 of 1

[Answered] Understanding ADC attenuation

Posted: Thu Jan 26, 2017 5:44 pm
by kolban
Studying the Analog to Digital conversion drivers, I find an API called "adc1_config_channel_atten" which takes as a parameter one of the following:
  • ADC_ATTEN_0db - 1/1
  • ADC_ATTEN_2_5db - 1/1.34
  • ADC_ATTEN_6db - 1/2
  • ADC_ATTEN_11db - 1/3.6
The word "attenuation" is a new one in my vocabulary. In this context, it seems to mean to me a divisor on the range of input voltages. If we assume that the default range of an ADC input is 0-3.3V then by applying these attenuation's, I can change the range to:
  • ADC_ATTEN_2_5db - 1/1.34 - 0-4.4V
  • ADC_ATTEN_6db - 1/2 - 0-6.6V
  • ADC_ATTEN_11db - 1/3.6 - 0-11.8V
This seems useful ... however, before I write that down in my notes, I'd like to be sure I'm not getting something wrong and mislead any readers. I'd hate for anyone to apply more than 3.3V of input to a pin and damage or ruin the device.

Are we actually saying here that by using higher attenuations, we can apply higher input voltages? I had always assumed that applying more than 3.3V as input to a pin would "fry" the device. Are special precautions needed here? For example, if one is working with a 10V potential input, if one "mis-wired" on their breadboard ... do we damage something? If I make a programming error and specify no attenuation but apply 10V on the ADC input pin, will that damage something?

All thoughts on this area of ADC very welcome.

Re: Understanding ADC attenuation

Posted: Fri Jan 27, 2017 12:50 am
by WiFive
I think with atten 0 the range is actually ~0-1v

Re: Understanding ADC attenuation

Posted: Fri Jan 27, 2017 1:24 am
by kolban
There is a companion thread to this one asking about default voltage ranges.... http://esp32.com/viewtopic.php?f=12&t=1045

Re: Understanding ADC attenuation

Posted: Fri Jan 27, 2017 3:04 am
by WiFive
Input voltage range and measurement range are different. Attenuation affects measurement range. So at 0db you can only measure up to ~1v.

Re: [Answered] Understanding ADC attenuation

Posted: Fri Jun 17, 2022 3:31 pm
by Vitaly
Hi all,
i use the code from the example

/*
* LAB: 10
* Name: ESP32 ADC Calibration
* Author: Khaled Magdy
* For More Info Visit: www.DeepBlueMbedded.com
*/

#include "esp_adc_cal.h"

#define AN_Pot1 37

int AN_Pot1_Result = 0;
float Voltage = 0.0;

void setup()
{
Serial.begin(115200);
}

void loop()
{
AN_Pot1_Result = analogRead(AN_Pot1);
Voltage = readADC_Cal(AN_Pot1_Result);
//Serial.println(Voltage/1000.0); // Print Voltage (in V)
Serial.println(Voltage); // Print Voltage (in mV)
delay(100);
}

uint32_t readADC_Cal(int ADC_Raw)
{
esp_adc_cal_characteristics_t adc_chars;

esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &adc_chars);
return(esp_adc_cal_raw_to_voltage(ADC_Raw, &adc_chars));

With the value ADC_ATTEN_DB_11, the measurement data in the monitor is displayed accurately.
However, when using other attenuation values - ADC_ATTEN_DB_6 - the scale width remains the same. With an input voltage value of 3150mV, the monitor shows 1888mV.
What did I miss?

Re: [Answered] Understanding ADC attenuation

Posted: Wed Jul 24, 2024 4:18 pm
by mtat76
Yes - with attenuation set to ADC_ATTEN_DB_6 the measurable range is 150 mV to 1.75 V as described https://docs.espressif.com/projects/esp ... s/adc.html.