Struct PwmInput

Source
pub struct PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,
{ /* private fields */ }
Expand description

Represents a TIMer configured as a PWM input. This peripheral will emit an interrupt on CC2 events, which occurs at two times in this mode:

  1. When a new cycle is started: the duty cycle will be 1.00
  2. When the period is captured. the duty cycle will be an observable value.

An example interrupt handler is provided:

use stm32f4xx_hal::{pac::TIM8, pwm_input::PwmInput};

type Monitor = PwmInput<TIM8>;

fn tim8_cc2(monitor: &Monitor) {
    let duty_clocks = monitor.get_duty_cycle_clocks();
    let period_clocks = monitor.get_period_clocks();
    // check if this interrupt was caused by a capture at the wrong CC2,
    // peripheral limitation.
    if !monitor.is_valid_capture() {
        return;
    }
    let duty = monitor.get_duty_cycle();
}

Implementations§

Source§

impl<TIM> PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

Source

pub fn release(self) -> Timer<TIM>

Source§

impl PwmInput<TIM1>

Source

pub fn get_period_clocks(&self) -> <TIM1 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM1 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM2>

Source

pub fn get_period_clocks(&self) -> <TIM2 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM2 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM3>

Source

pub fn get_period_clocks(&self) -> <TIM3 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM3 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM4>

Source

pub fn get_period_clocks(&self) -> <TIM4 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM4 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM5>

Source

pub fn get_period_clocks(&self) -> <TIM5 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM5 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM8>

Source

pub fn get_period_clocks(&self) -> <TIM8 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM8 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM9>

Source

pub fn get_period_clocks(&self) -> <TIM9 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM9 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Source§

impl PwmInput<TIM12>

Source

pub fn get_period_clocks(&self) -> <TIM12 as General>::Width

Period of PWM signal in terms of clock cycles

Source

pub fn get_duty_cycle_clocks(&self) -> <TIM12 as General>::Width

Duty cycle in terms of clock cycles

Source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

Source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Methods from Deref<Target = Timer<TIM>>§

Source

pub fn configure(&mut self, clocks: &Clocks)

Source

pub fn set_master_mode(&mut self, mode: TIM::Mms)

Trait Implementations§

Source§

impl<TIM> Deref for PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

Source§

type Target = Timer<TIM>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<TIM> DerefMut for PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<TIM> Freeze for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: Freeze, TIM: Freeze,

§

impl<TIM> RefUnwindSafe for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: RefUnwindSafe, TIM: RefUnwindSafe,

§

impl<TIM> Send for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: Send, TIM: Send,

§

impl<TIM> Sync for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: Sync, TIM: Sync,

§

impl<TIM> Unpin for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: Unpin, TIM: Unpin,

§

impl<TIM> UnwindSafe for PwmInput<TIM>
where <TIM as TimCPin<0>>::Ch<PushPull>: UnwindSafe, TIM: UnwindSafe,

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.