adc_arch.h File Reference

Architecture specific ADC functions for ESP32. More...

Detailed Description

Architecture specific ADC functions for ESP32.

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

Definition in file adc_arch.h.

#include "periph/gpio.h"
#include "periph/adc.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 = 0, ADC_ATTENUATION_3_DB, ADC_ATTENUATION_6_DB, ADC_ATTENUATION_11_DB }
 Attenuations that can be set for ADC lines. More...
 

Functions

int adc_set_attenuation (adc_t line, adc_attenuation_t atten)
 Set the attenuation for the ADC line. More...
 
int adc_vref_to_gpio25 (void)
 Output ADC reference voltage to GPIO25. More...
 

Enumeration Type Documentation

◆ adc_attenuation_t

Attenuations that can be set for ADC lines.

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 33 of file adc_arch.h.

Function Documentation

◆ adc_set_attenuation()

int adc_set_attenuation ( adc_t  line,
adc_attenuation_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_ATTENUATION_0_DB
3 dB 0 ... 1.5V ADC_ATTENUATION_3_DB
6 dB 0 ... 2.2V ADC_ATTENUATION_6_DB
11 dB (default) 0 ... 3.3V ADC_ATTENUATION_11_DB

Please note: The reference voltage Vref can vary from device to device in the range of 1.0V and 1.2V. The Vref of a device can be read with the function adc_vref_to_gpio25 at the pin GPIO 25. The results of the ADC input can then be adjusted accordingly.

Parameters
lineADC line for which the attenuation is set
attenAttenuation, see type definition of *adc_attenuation_t
Returns
0 on success
-1 on invalid ADC line

◆ adc_vref_to_gpio25()

int adc_vref_to_gpio25 ( void  )

Output ADC reference voltage to GPIO25.

Returns
0 on success
-1 on invalid ADC line