ADC application parameter Introduction for ESP32

The purpose of this blog post is to explain ESP32 ADC parameter usage and FAQ.

1 Introduction

According to the 《ESP32 Datasheet》 and “Analog to Digital Converter (ADC)” guide, the ESP32 integrates two 12-bit SAR ADCs and supports measurements on 18 channels (analog-enabled pins). Next, the application parameters of ADC will be interpreted.

2 ADC parameters interpretation

2.1 ADC Capture Width

The ESP32 ADC has a maximum resolution of 12 bits, which is 2^12 = 4096. The corresponding procedures are as follows:

adc_bits_width_t width = ADC_WIDTH_BIT_12;
typedef enum {
    ADC_WIDTH_BIT_9  = 0, /*!< ADC capture width is 9Bit. Only ESP32 is supported. */
    ADC_WIDTH_BIT_10 = 1, /*!< ADC capture width is 10Bit. Only ESP32 is supported. */
    ADC_WIDTH_BIT_11 = 2, /*!< ADC capture width is 11Bit. Only ESP32 is supported. */
    ADC_WIDTH_BIT_12 = 3, /*!< ADC capture width is 12Bit. Only ESP32 is supported. */
#if !CONFIG_IDF_TARGET_ESP32
    ADC_WIDTH_BIT_13 = 4, /*!< ADC capture width is 13Bit. Only ESP32-S2 is supported. */
#endif
    ADC_WIDTH_MAX,
} adc_bits_width_t;

Note: Two analog-to-digital converters are ADC1 and ADC2. 12 bit is the maximum resolution of ADC .And the resolution of ADC can be support multi-configured to 12 bit, 11 bit, 10 bit, 9 bit . Please refer to 《ESP32 Technical Reference Manual》 .

2.2 ADC Channel

The ESP32 has 18 channels and can measure analog signals from 18 pins. For respectively:

  • ADC1:8 channels,GPIO32~GPIO39
  • ADC2:10 channels,GPIO0、GPIO2、GPIO4、GPIO12-GPIO15、GPIO25-GPIO27

Please note the following points during ADC application:

  • When the ADC1 is powered on, the digital input of GPIO36 and GPIO39 will be pulled down by about 80 ns.When using Channel0 (GPIO36) and Channel3 (GPIO39) of ADC1, do not connect anything else to these two pins and do not change their configuration, otherwise it may affect the low frequency signal measurements.
  • Since GPIO0, GPIO2 and GPIO15 are Strapping pins, they cannot be used freely.
  • Since the Wi-Fi driver already uses ADC2. Therefore, ADC2 can only be used when the Wi-Fi driver is not started. But ADC2 can be used in the same time with Bluetooth.

2.3 ADC Features

According to the “SAR ADC Outline of Function” from 《ESP32 Technical Reference Manual》 , the following features can be summarized:

在这里插入图片描述

  • Two SAR ADCs, with simultaneous sampling and conversion
  • Up to five SAR ADC controllers(RTC ADC1 CTRL、RTC ADC2 CTRL、DIG ADC1 CTRL、DIG ADC2 CTRL,及 PWDET CTRL) for different purposesd. Support for different application scenarios (e.g. high performance, low power or PWDET / PKDET).
  • Up to 18 analog input pads.
  • 1 channel for internal voltage vdd33, 2 for pa_pkdet (Only ADC2 controller Support)
  • 12-bit, 11-bit, 10-bit, 9-bit configurable resolution.
  • DMA support (ADC1 controller support)
  • Multiple channel-scanning modes(ADC1 and ADC2 controller all support)
  • Operation during deep sleep(ADC1 and ADC2 controller all support)
  • Controlled by a ULP coprocessor(ADC1 and ADC2 controller all support)

There are five ADC controllers in ESP32: RTC ADC1 CTRL, RTC ADC2 CTRL, DIG ADC1 CTRL, DIG ADC2 CTRL and PWDET CTRL. The differences between them are summarized in Table 143.
在这里插入图片描述

Meanwhile, DNL and INL are also important about ADC characteristics as follows:
在这里插入图片描述

2.4 ADC Work Mode

There are two working modes of ADC for ESP32:

  • ADC Single Read mode:Both of the ADC units support single read mode, which is suitable for low-frequency sampling operations. Sampling frequency is required to be 1 kHz.
  • ADC Continuous (DMA) mode:Suitable for high frequency continuous sampling,The frequency in M kHz,You can refer to the I2S_ADC_DAC example.

2.5 ADC Attenuation configuration

The ADC reading range can be determined by configuring ADC attenuation parameter, and the attenuation parameter configuration of ADC is carried out by ADC channels. Specifically, the parameter ‘ADC_atten_t’ needs to be configured. This attenuation parameter configuration has 4 grades as follows:

  • ADC_ATTEN_DB_0 = 0:Full range voltage is 1100 mV
  • ADC_ATTEN_DB_2_5 = 1:Full range voltage is 1500 mV
  • ADC_ATTEN_DB_6 = 2:Full range voltage is 2200 mV
  • ADC_ATTEN_DB_11 = 3:Full range voltage is 3900 mV

The recommended measurement voltage range corresponding to different attenuation parameters is as follows:
在这里插入图片描述

  • For maximum measurement accuracy, please measure the voltage using an ADC within these recommended ranges.
  • The default ADC reference voltage(It is also “Full range voltage”) is 1100 mV.
  • To read a higher voltage (The ESP32 chip pins maximum voltage usually is 3.3V), it is required to set the ADC attenuation parameter of this channel to > 0 dB.
  • With the 11 dB attenuation parameter, the maximum measured voltage is limited by VDD_A (The analog power supply is 2.3V ~ 3.6V, since ESP32 power supply is generally 3.3V, i.e., VDD_A is also 3.3V at maximum), rather than the full range voltage.

Note: The readings of the ADC pins that are not connected to any signal are random.

2.6 ADC Calibration mode

The ESP32 has the following 3 calibration modes:

  • Two Point ModeTwo Point values represent each of the ADCs’ readings at 150 mV and 850 mV. To obtain more accurate calibration results these values should be measured by user and burned into eFuse BLOCK3.

  • eFuse Vref ModeeFuse Vref represents the true ADC reference voltage. This value is measured and burned into eFuse BLOCK0 during factory calibration. It is the default ADC calibration mode.

  • Default Vref ModeDefault Vref is an estimate of the ADC reference voltage provided by the user as a parameter during characterization. If Two Point or eFuse Vref values are unavailable, Default Vref will be used.The corresponding parameters are defined as #define DEFAULT_VREF 1100 .

The corresponding structures of the above 3 ADC calibration modes are as follows:

typedef enum {
    ESP_ADC_CAL_VAL_EFUSE_VREF = 0,         /**< Characterization based on reference voltage stored in eFuse*/
    ESP_ADC_CAL_VAL_EFUSE_TP = 1,           /**< Characterization based on Two Point values stored in eFuse*/
    ESP_ADC_CAL_VAL_DEFAULT_VREF = 2,       /**< Characterization based on default reference voltage*/
    ESP_ADC_CAL_VAL_MAX
} esp_adc_cal_value_t;

3 ADC Frequently asked Questions

The default ADC attenuation parameter is 0dB,please use the ADC calibration API and measure voltages in these recommended ranges (default is 100 mV to 950 mV) to get the maximum ADC measurement accuracy . When the ADC reads a large voltage, please modify the attenuation parameter configuration of the ADC.Partial voltage measurement is recommended when the measured voltage exceeds 3.3V. Please refer to ADC Attenuation Parameters Configuration .


  • What is the single channel sampling frequency of ADC1?

The sampling frequency requirement of ADC1 single channel is 1KHz,please refer to adc_digi_config_t I=introductions.


  • How to erase (modify) factory burned eFuse Vref reference voltage while writing custom “two point calibration” reference voltage?

The default ADC eFuse_vref cannot be erased, but you don’t have to use it. You can disable the menuconfig -> Component config -> ADC Calibration -> Use eFuse Vref config. As follow: 在这里插入图片描述
Note: The eFuse Vref and the “two-point calibration” ADC reference voltage can coexist.If both calibration modes are enabled in menuconfig -> Component config -> ADC Calibration config, eFuse Vref and ADC reference voltage of “two-point calibration” are written into eFuse at the same time, and the reference voltage of “two-point calibration” will be used by default.


  • How to write the “two point calibration” value into Efuse Block3?

You can refer to the following three documents:


For example: To write the ADC calibration value as a binary file and then burn it to the 12th bytes of eFuse BLK3, running the following command in the terminal:

espefuse.py -p /dev/ttyUSB0 burn_block_data --offset 12 BLK3 ADC_new2.bin
espefuse.py -p /dev/ttyUSB0 burn_efuse BLK3_PART_RESERVE 1

  • After modify the DEFAULT_VREF parameter of the esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_12Bit, DEFAULT_VREF, adc_chars) API, It is found that the measurement accuracy of ADC is not significantly improved.

The DEFAULT_VREF parameter is the ADC reference voltage provided during characterization. The default value is 1100 mV and customization modify is not allowed.If the two-point calibration value or eFuse Vref is not available, the Default Vref will be used.The factory default reference voltage for the ADC is eFuse Vref, it is stored in eFuse BLOCK0.

【Note】

  • Setting this parameter as a reference voltage is valid only when ESP32’s eFuse Vref and "two-point calibration" values are not available.
  • If eFuse_vref is not burned into the eFuse or the Default ADC calibration mode is disable in menuconfig, than the Default Vref can be used.
  • When the eFuse_vref has been burned into the eFuse, use software modification of this parameter does not change the default ADC reference voltage. Please refer to “ADC Guide”.

  • Can the measurement accuracy of the ADC be improved by modifying the eFuse Vref value? Or is there any other way to improve the accuracy of the ADC’s voltage acquisition?

The maximum sampling accuracy of the ADC is 12 bits by default, that is 2^12 =4096.Higher ADC sampling accuracy cannot be achieved .The ADC sampling error can be reduced to “improve the ADC accuracy”.As follows:

  • You can modify the ADC reference voltage by changing the type of the esp_adc_cal_value_t calibration value.
  • The measurement accuracy is improved by burning the Vref of the ADC in eFuse as a two-point calibration value. Please refer to Calibration Values

  • When the ADC pins is suspended, the default read voltage is 284 mV, but the actual measurement of the ADC input port voltage is only tens of mV. Why?

When the ADC pins is suspended, read the ADC value is inaccurate (That will read 0 to 3.3V random value).It is recommended to pull up or pull down the ADC pins.


  • When using an ADC input voltage of 0-200 mV, why does the ADC read the value all of 284 mV?

The attenuation parameter used for ADC is 0 dB default , and the recommended measurement voltage range for ADC is 100 mV~950 mV. In practice. it is recommended that the minimum measured voltage be no less than 300 mV.


  • What is the measurement error of the ADC between ESP32 modules ? What is the effective measurement range?

By default, there are ±6% differences in measured results between chips. ESP-IDF provides couple of calibration methods for ADC1. Results after calibration using eFuse Vref value are shown in the follow Table . For higher accuracy, users may apply other calibration methods provided in ESP-IDF, or implement their own.

在这里插入图片描述


  • How to verify whether Efuse Vref reference voltage has been burned into the Efuse?

You can run the following command to query data using “esptool” :

espefuse.py --port /dev/ttyUSB0 adc_info

If there is have an eFuse Vref, the result returned is as follows:

ADC VRef calibration: 1093 mV

If there is no eFuse Vref, the result returned is as follows:

ADC VRef calibration: None (1100 mV nominal)

If a two-point calibration parameter is burned, the result returned is similar as follows:

ADC VRef calibration: 1149 mV
ADC readings stored in efuse BLK3:
ADC1 Low reading  (150 mV): 306
ADC1 High reading (850 mV): 3153
ADC2 Low reading  (150 mV): 389
ADC2 High reading (850 mV): 3206

In ADC single read mode, it will first check whether the ADC reference voltage value has been burned into the eFuse.


  • What is the maximum sampling rate of ADC DMA mode for ESP32?

The ESP32’s ADC DMA mode only supports Dig ADC (ADC Digital Signal Controller), so ADC DMA only supports analog-to-digital signal applications. Take the I2S_ADC_DAC as an example, the maximum sampling rate of the ADC DMA mode depends on the sampling rate of the I2S.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值