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.GPIO1, 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-C3 has an ADC2 in silicon, but it is not exposed due to hardware errata in its digital controller. GPIO5 is therefore not an ADC pin on ESP32-C3.
- The ESP32-S31 has no calibration scheme: calibration eFuses and curve fitting coefficients are not available for this chip.
- 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§
- Attenuation
- The approximate attenuation of the ADC pin.
- Error
unstable - Errors that can occur while using the ADC.
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 ADCs that support curve fitting.
- AdcHas
Line Cal unstable - Marker trait for ADC units which support line fitting.
- Instance
unstable - Enables asynchronous access.