pub struct PwmInput<TIM, PINS>{ /* 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:
- When a new cycle is started: the duty cycle will be
1.00
- 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<PINS> PwmInput<TIM1, PINS>
impl<PINS> PwmInput<TIM1, PINS>
Sourcepub fn get_period_clocks(&self) -> <TIM1 as General>::Width
pub fn get_period_clocks(&self) -> <TIM1 as General>::Width
Period of PWM signal in terms of clock cycles
Sourcepub fn get_duty_cycle_clocks(&self) -> <TIM1 as General>::Width
pub fn get_duty_cycle_clocks(&self) -> <TIM1 as General>::Width
Duty cycle in terms of clock cycles
Sourcepub fn get_duty_cycle(&self) -> f32
pub fn get_duty_cycle(&self) -> f32
Observed duty cycle as a float in range [0.00, 1.00]
Sourcepub fn is_valid_capture(&self) -> bool
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>
impl<PINS> PwmInput<TIM5, PINS>
Sourcepub fn get_period_clocks(&self) -> <TIM5 as General>::Width
pub fn get_period_clocks(&self) -> <TIM5 as General>::Width
Period of PWM signal in terms of clock cycles
Sourcepub fn get_duty_cycle_clocks(&self) -> <TIM5 as General>::Width
pub fn get_duty_cycle_clocks(&self) -> <TIM5 as General>::Width
Duty cycle in terms of clock cycles
Sourcepub fn get_duty_cycle(&self) -> f32
pub fn get_duty_cycle(&self) -> f32
Observed duty cycle as a float in range [0.00, 1.00]
Sourcepub fn is_valid_capture(&self) -> bool
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>
impl<PINS> PwmInput<TIM9, PINS>
Sourcepub fn get_period_clocks(&self) -> <TIM9 as General>::Width
pub fn get_period_clocks(&self) -> <TIM9 as General>::Width
Period of PWM signal in terms of clock cycles
Sourcepub fn get_duty_cycle_clocks(&self) -> <TIM9 as General>::Width
pub fn get_duty_cycle_clocks(&self) -> <TIM9 as General>::Width
Duty cycle in terms of clock cycles
Sourcepub fn get_duty_cycle(&self) -> f32
pub fn get_duty_cycle(&self) -> f32
Observed duty cycle as a float in range [0.00, 1.00]
Sourcepub fn is_valid_capture(&self) -> bool
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>>§
pub fn configure(&mut self, clocks: &Clocks)
Sourcepub fn listen(&mut self, event: Event)
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.
Sourcepub fn clear_interrupt(&mut self, event: Event)
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.