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

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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).

Period of PWM signal in terms of clock cycles

Duty cycle in terms of clock cycles

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

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>>

Starts listening for an event

Stops listening for an event

Starts listening for an event

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

Clears interrupt associated with event.

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

Stops listening for an event

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.