Struct AdcBuilder

Source
pub struct AdcBuilder {
    pub clk_divider: Option<Prescaler>,
    pub sample_clock_cycles: Option<u8>,
    pub accumulation: Accumulation,
    pub vref: Option<Reference>,
}
Expand description

§ADC Configuration Builder

This structure provides configuration of multiple factors which affect the ADC’s sampling characteristics.

The ADC clock is driven by the peripheral clock divided with a divider selected via AdcBuilder::with_clock_divider().

A sample is taken over a number of ADC clock cycles configured by AdcBuilder::with_clock_cycles_per_sample(), and then transmitted to the ADC register 1 clock cycle per bit of resolution - resolution is determined by the accumulation mode selected by AdcBuilder::new().

The ADC can be configured to combine multiple readings in either an average or summed mode (See Accumulation).

The formula for calculating Sample rate (SPS) is shown below, and implemented in a helper method AdcBuilder::calculate_sps():

§For single sample

SPS = (GCLK_ADC / clk_divider) / (sample_clock_cycles + bit_width)

§For multiple samples ‘n’ (Averaging or Summed)

SPS = (GCLK_ADC / clk_divider) / (n * (sample_clock_cycles + 12))

Fields§

§clk_divider: Option<Prescaler>§sample_clock_cycles: Option<u8>§accumulation: Accumulation§vref: Option<Reference>

Implementations§

Source§

impl AdcBuilder

Source

pub fn new(accumulation_method: Accumulation) -> Self

Create a new settings builder

Source

pub fn with_clock_divider(self, div: Prescaler) -> Self

This setting adjusts the ADC clock frequency by dividing the input clock for the ADC.

§Example:
  • Input clock 48MHz, div 32 => ADC Clock is 1.5MHz
Source

pub fn with_vref(self, reference: Reference) -> Self

Sets the ADC reference voltage source

Source

pub fn with_clock_cycles_per_sample(self, num: u8) -> Self

Sets the number of ADC clock cycles taken to sample a single sample. The higher this number, the longer it will take the ADC to sample each sample. Smaller values will make the ADC perform more samples per second, but there may be more noise in each sample leading to erratic values.

§Safety
  • This function clamps input value between 1 and 63, to conform to the ADC registers min and max values.
Source

pub fn calculate_sps(&self, clock_freq: u32) -> Result<u32, BuilderError>

Returns a calculated sample rate based on the settings used

Source

pub fn enable<I: AdcInstance>( self, adc: I::Instance, pm: &mut Pm, clock: &AdcClock, ) -> Result<Adc<I>, BuilderError>

Trait Implementations§

Source§

impl Clone for AdcBuilder

Source§

fn clone(&self) -> AdcBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for AdcBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.