Loading...
Searching...
No Matches
adc_arch.h File Reference

Architecture specific ADC definitions and functions for ESP32. More...

Detailed Description

Architecture specific ADC definitions and functions for ESP32.

All ESP32x SoCs have two SAR ADC units each. However, these have functionalities as well as specific properties that vary between the ESP32x SoC and therefore require different handling for each ESP32x SoC. This is already taken into account in the high-level API of the ESP-IDF. To avoid having to reimplement these specifics and the different handling, the high-level API of the ESP-IDF is used directly for the ADC peripherals.

Author
Gunar Schorcht gunar.nosp@m.@sch.nosp@m.orcht.nosp@m..net

Definition in file adc_arch.h.

#include "periph/adc.h"
#include "periph/gpio.h"
#include "driver/adc.h"
#include "hal/adc_types.h"
+ Include dependency graph for adc_arch.h:

Go to the source code of this file.

Enumerations

enum  adc_attenuation_t { ADC_ATTENUATION_0_DB = ADC_ATTEN_DB_0 , ADC_ATTENUATION_3_DB = ADC_ATTEN_DB_2_5 , ADC_ATTENUATION_6_DB = ADC_ATTEN_DB_6 , ADC_ATTENUATION_11_DB = ADC_ATTEN_DB_11 }
 Attenuations that can be set for ADC lines. More...
 

Functions

int adc_set_attenuation (adc_t line, adc_atten_t atten)
 Set the attenuation for the ADC line.
 
int adc_line_vref_to_gpio (adc_t line, gpio_t gpio)
 Output reference voltage of a ADC line to GPIO n.
 

Enumeration Type Documentation

◆ adc_attenuation_t

Attenuations that can be set for ADC lines.

Event though ESP-IDF type adc_atten_t and ADC_ATTEN_DB_* are used now, the adc_attenuation_t type with constants ADC_ATTENUATION_*_DB are kept for compatibility.

Enumerator
ADC_ATTENUATION_0_DB 

full-range is about 1.1 V (Vref)

ADC_ATTENUATION_3_DB 

full-range is about 1.5 V

ADC_ATTENUATION_6_DB 

full-range is about 2.2 V

ADC_ATTENUATION_11_DB 

full-range is about 3.3 V

Definition at line 47 of file adc_arch.h.

Function Documentation

◆ adc_line_vref_to_gpio()

int adc_line_vref_to_gpio ( adc_t  line,
gpio_t  gpio 
)

Output reference voltage of a ADC line to GPIO n.

The Vref of the ADC unit of the given ADC line is routed to a GPIO pin n. This allows to measure the Vref used by the ADC unit to adjusted the results of the conversions accordingly.

Note
  • The given GPIO must be a valid ADC channel of ADC2 unit.
  • For ESP32 and ESP32C3, the given ADC line has to be a channel of ADC2 unit.
Parameters
lineADC line for which Vref of its ADC unit is routed to the GPIO
gpioGPIO to which Vref is routed (ADC2 channel GPIOs only)
Returns
0 on success
-1 on error

◆ adc_set_attenuation()

int adc_set_attenuation ( adc_t  line,
adc_atten_t  atten 
)

Set the attenuation for the ADC line.

Default attenuation is 11 dB.

For each ADC line, an attenuation of the input signal can be defined separately. This results in different full ranges of the measurable voltage at the input. The attenuation can be set to 0 dB, 3 dB, 6 dB and 11 dB, with 11 dB being the standard attenuation. Since an ADC input is measured against a reference voltage Vref of 1.1 V, approximately the following measurement ranges are given when using a corresponding attenuation:

Attenuation Voltage Range Symbol
0 dB 0 ... 1.1V (Vref) ADC_ATTEN_DB_0
2.5 dB 0 ... 1.5V ADC_ATTEN_DB_2_5
6 dB 0 ... 2.2V ADC_ATTEN_DB_6
11 dB (default) 0 ... 3.3V ADC_ATTEN_DB_11
Note
: The reference voltage Vref can vary from ADC unit to ADC unit in the range of 1.0V and 1.2V. The Vref of a unit can be routed with function adc_vref_to_gpio to a GPIO pin.
Parameters
lineADC line for which the attenuation is set
attenAttenuation, see type definition of *adc_attenuation_t
Returns
0 on success
-1 on error