Module adc

Source
Available on crate feature unstable only.
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 analog_pin = peripherals.GPIO2;
let mut adc1_config = AdcConfig::new();
let mut pin = adc1_config.enable_pin(
    analog_pin,
    Attenuation::_11dB,
);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);

let mut delay = Delay::new();

loop {
    let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();

    delay.delay_millis(1500);
}

§Implementation State

Structs§

Adc
Analog-to-Digital Converter peripheral driver.
AdcCalBasic
Basic ADC calibration scheme
AdcCalCurve
Curve fitting ADC calibration scheme
AdcCalLine
Line fitting ADC calibration scheme
AdcConfig
Configuration for the ADC.
AdcPin
An I/O pin which can be read using the ADC.

Enums§

AdcCalSource
Calibration source of the ADC.
Attenuation
The attenuation of the ADC pin.
Resolution
The sampling/readout resolution of the ADC.

Traits§

AdcCalScheme
A trait abstracting over calibration methods.
AdcChannel
A helper trait to get the ADC channel of a compatible GPIO pin.
AdcHasCurveCal
Marker trait for ADC which support curve fitting
AdcHasLineCal
Marker trait for ADC units which support line fitting