Struct PwmInput

Source
pub struct PwmInput<TIM, PINS>
where TIM: Instance + WithPwm, PINS: Pins<TIM>,
{ /* 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;
use stm32f4xx_hal::timer::Timer;
use stm32f4xx_hal::pwm_input::PwmInput;
use stm32f4xx_hal::gpio::gpioc::PC6;
use stm32f4xx_hal::gpio::Alternate;

type Monitor = PwmInput<TIM8, PC6<Alternate<3>>>;

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, PINS> PwmInput<TIM, PINS>
where TIM: Instance + WithPwm, PINS: Pins<TIM>,

Source

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

Source§

impl<PINS> PwmInput<TIM1, PINS>
where PINS: Pins<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<PINS> PwmInput<TIM5, PINS>
where PINS: Pins<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<PINS> PwmInput<TIM9, PINS>
where PINS: Pins<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).

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

Source

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

Source

pub fn listen(&mut self, event: Event)

Starts listening for an event

Note, you will also have to enable the TIM2 interrupt in the NVIC to start receiving events.

Source

pub fn clear_interrupt(&mut self, event: Event)

Clears interrupt associated with event.

If the interrupt is not cleared, it will immediately retrigger after the ISR has finished.

Source

pub fn unlisten(&mut self, event: Event)

Stops listening for an event

Source

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

Trait Implementations§

Source§

impl<TIM, PINS> Deref for PwmInput<TIM, PINS>
where TIM: Instance + WithPwm, PINS: Pins<TIM>,

Source§

type Target = Timer<TIM>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<TIM, PINS> DerefMut for PwmInput<TIM, PINS>
where TIM: Instance + WithPwm, PINS: Pins<TIM>,

Source§

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

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<TIM, PINS> Freeze for PwmInput<TIM, PINS>
where PINS: Freeze, TIM: Freeze,

§

impl<TIM, PINS> RefUnwindSafe for PwmInput<TIM, PINS>
where PINS: RefUnwindSafe, TIM: RefUnwindSafe,

§

impl<TIM, PINS> Send for PwmInput<TIM, PINS>
where PINS: Send, TIM: Send,

§

impl<TIM, PINS> Sync for PwmInput<TIM, PINS>
where PINS: Sync, TIM: Sync,

§

impl<TIM, PINS> Unpin for PwmInput<TIM, PINS>
where PINS: Unpin, TIM: Unpin,

§

impl<TIM, PINS> UnwindSafe for PwmInput<TIM, PINS>
where PINS: 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.