[Answered] Understanding ADC attenuation

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered] Understanding ADC attenuation

Postby kolban » Thu Jan 26, 2017 5:44 pm

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.
Last edited by kolban on Sat Jan 28, 2017 6:06 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

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

Re: Understanding ADC attenuation

Postby WiFive » Fri Jan 27, 2017 12:50 am

I think with atten 0 the range is actually ~0-1v

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Understanding ADC attenuation

Postby kolban » Fri Jan 27, 2017 1:24 am

There is a companion thread to this one asking about default voltage ranges.... http://esp32.com/viewtopic.php?f=12&t=1045
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

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

Re: Understanding ADC attenuation

Postby WiFive » Fri Jan 27, 2017 3:04 am

Input voltage range and measurement range are different. Attenuation affects measurement range. So at 0db you can only measure up to ~1v.

Vitaly
Posts: 4
Joined: Wed Feb 23, 2022 1:52 pm

Re: [Answered] Understanding ADC attenuation

Postby Vitaly » Fri Jun 17, 2022 3:31 pm

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?

mtat76
Posts: 1
Joined: Wed Jul 24, 2024 4:15 pm

Re: [Answered] Understanding ADC attenuation

Postby mtat76 » Wed Jul 24, 2024 4:18 pm

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.

Who is online

Users browsing this forum: No registered users and 38 guests