Analog to Digital Converter
Overview
The ESP32 integrates two 12-bit SAR (Successive Approximation Register) ADCs, supporting a total of 18 measurement channels (analog enabled pins).
The ADC driver API supports ADC1 (8 channels, attached to GPIOs 32 - 39), and ADC2 (10 channels, attached to GPIOs 0, 2, 4, 12 - 15 and 25 - 27). However, the usage of ADC2 has some restrictions for the application:
ADC2 is used by the Wi-Fi driver. Therefore the application can only use ADC2 when the Wi-Fi driver has not started.
Some of the ADC2 pins are used as strapping pins (GPIO 0, 2, 15) thus cannot be used freely. Such is the case in the following official Development Kits:
ESP32 DevKitC: GPIO 0 cannot be used due to external auto program circuits.
ESP-WROVER-KIT: GPIO 0, 2, 4 and 15 cannot be used due to external connections for different purposes.
Configuration and Reading ADC
Each ADC unit supports two work modes, ADC-RTC or ADC-DMA mode. ADC-RTC is controlled by the RTC controller and is suitable for low-frequency sampling operations. ADC-DMA is controlled by a digital controller and is suitable for high-frequency continuous sampling actions.
ADC-RTC mode
The ADC should be configured before reading is taken.
For ADC1, configure desired precision and attenuation by calling functions
adc1_config_width()
andadc1_config_channel_atten()
.For ADC2, configure the attenuation by
adc2_config_channel_atten()
. The reading width of ADC2 is configured every time you take the reading.
Attenuation configuration is done per channel, see adc1_channel_t
and adc2_channel_t
, set as a parameter of above functions.
Then it is possible to read ADC conversion result with adc1_get_raw()
and adc2_get_raw()
. Reading width of ADC2 should be set as a parameter of adc2_get_raw()
instead of in the configuration functions.
Comments
Post a Comment