Expand description
§Analog to Digital Converter (ADC)
§Overview
The ADC is integrated on the chip, and is capable of measuring analog signals from specific analog I/O pins. One or more ADC units are available, depending on the device being used.
§Configuration
The ADC can be configured to measure analog signals from specific pins. The configuration includes the resolution of the ADC, the attenuation of the input signal, and the pins to be measured.
Some targets also support ADC calibration via different schemes like basic calibration, curve fitting or linear interpolation. The calibration schemes can be used to improve the accuracy of the ADC readings.
§Examples
§Read an analog signal from a pin
let mut adc1_config = AdcConfig::new();
let mut pin = adc1_config.enable_pin(peripherals.GPIO0, Attenuation::_11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
let mut delay = Delay::new();
loop {
let pin_value = nb::block!(adc1.read_oneshot(&mut pin))?;
delay.delay_millis(1500);
}§Implementation State
- ADC calibration is not implemented for all targets.
- The ESP32-S31 has no calibration scheme. ESP-IDF does not define the calibration eFuses or the curve fitting coefficients for this chip yet.
- The ESP32-S31 SAR ADC has one attenuation setting, so the attenuation given to
AdcConfig::enable_pinhas no effect. - The ESP32-S31 SAR is differential and its result is the weighted sum of 17 redundant
comparator bits. Readings run from 0 to
FULL_SCALE(4393), and an input tied to ground reads aboutZERO_DIFF_CODE(2198), so a single-ended measurement only uses the codes above that point.
Structs§
- Adc
unstable - Analog-to-Digital Converter peripheral driver.
- AdcCal
Basic unstable - Basic ADC calibration scheme
- AdcCal
Curve unstable - Curve fitting ADC calibration scheme
- AdcCal
Line unstable - Line fitting ADC calibration scheme
- AdcConfig
- Configuration for the ADC.
- AdcPin
- An I/O pin which can be read using the ADC.
Enums§
- AdcCal
Source - Calibration source of the ADC.
- Attenuation
- The approximate attenuation of the ADC pin.
Traits§
- AdcCal
Scheme - A trait abstracting over calibration methods.
- AdcChannel
- A helper trait to get the ADC channel of a compatible GPIO pin.
- AdcHas
Curve Cal unstable - Marker trait for ADC which support curve fitting
- AdcHas
Line Cal unstable - Marker trait for ADC units which support line fitting.
- Instance
unstable - Enable asynchronous access.