Struct stm32f4xx_hal::timer::Timer
source · [−]pub struct Timer<TIM> { /* private fields */ }
Expand description
Timer wrapper.
This wrapper can be used both for the system timer (SYST) or the general-purpose timers (TIMx).
Note: If you want to use the timer to sleep a certain amount of time, use
Delay
.
Implementations
sourceimpl Timer<SYST>
impl Timer<SYST>
sourcepub fn counter_hz(self) -> SysCounterHz
pub fn counter_hz(self) -> SysCounterHz
Creates SysCounterHz which takes Hertz as Duration
sourcepub fn counter<const FREQ: u32>(self) -> SysCounter<FREQ>
pub fn counter<const FREQ: u32>(self) -> SysCounter<FREQ>
Creates SysCounter with custom precision (core frequency recommended is known)
sourcepub fn counter_us(self) -> SysCounterUs
pub fn counter_us(self) -> SysCounterUs
Creates SysCounter 1 microsecond precision
sourceimpl Timer<TIM2>
impl Timer<TIM2>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM2, PINS>where
PINS: Pins<TIM2>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM2, PINS>where
PINS: Pins<TIM2>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<TIM3>
impl Timer<TIM3>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM3, PINS>where
PINS: Pins<TIM3>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM3, PINS>where
PINS: Pins<TIM3>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<TIM4>
impl Timer<TIM4>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM4, PINS>where
PINS: Pins<TIM4>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM4, PINS>where
PINS: Pins<TIM4>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<TIM1>
impl Timer<TIM1>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM1, PINS>where
PINS: Pins<TIM1>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM1, PINS>where
PINS: Pins<TIM1>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<TIM5>
impl Timer<TIM5>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM5, PINS>where
PINS: Pins<TIM5>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM5, PINS>where
PINS: Pins<TIM5>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<TIM9>
impl Timer<TIM9>
sourcepub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM9, PINS>where
PINS: Pins<TIM9>,
pub fn pwm_input<PINS>(
self,
best_guess: Hertz,
pins: PINS
) -> PwmInput<TIM9, PINS>where
PINS: Pins<TIM9>,
Configures this timer for PWM input. Accepts the best_guess
frequency of the signal
Note: this should be as close as possible to the frequency of the PWM waveform for best
accuracy.
This device will emit an interrupt on CC1, 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. See the pwm input example for an suitable interrupt handler.
sourceimpl Timer<SYST>
impl Timer<SYST>
sourceimpl<TIM: Instance> Timer<TIM>
impl<TIM: Instance> Timer<TIM>
pub fn configure(&mut self, clocks: &Clocks)
pub fn counter_hz(self) -> CounterHz<TIM>
pub fn release(self) -> TIM
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.