Module stm32h7xx_hal::pwm[][src]

Pulse Width Modulation (PWM)

PWM output is avaliable for the advanced control timers (TIM1, TIM8), the general purpose timers (TIM[2-5], TIM[12-17]) and the Low-power timers (LPTIM[1-5]).

Timers support up to 4 simultaneous PWM output channels

Usage

let gpioa = ..; // Set up and split GPIOA
let pins = (
    gpioa.pa8.into_alternate_af1(),
    gpioa.pa9.into_alternate_af1(),
    gpioa.pa10.into_alternate_af1(),
    gpioa.pa11.into_alternate_af1(),
);

Then call the pwm function on the corresponding timer:

  let device: pac::Peripherals = ..;

  // Put the timer in PWM mode using the specified pins
  // with a frequency of 100 hz.
  let (c0, c1, c2, c3) = device.TIM1.pwm(
      pins,
      100.hz(),
      prec,
      &clocks
  );

  // Set the duty cycle of channel 0 to 50%
  c0.set_duty(c0.get_max_duty() / 2);
  // PWM outputs are disabled by default
  c0.enable()

Structs

C1

Marker struct for PWM channel 1 on Pins trait and Pwm struct

C2

Marker struct for PWM channel 2 on Pins trait and Pwm struct

C3

Marker struct for PWM channel 3 on Pins trait and Pwm struct

C4

Marker struct for PWM channel 4 on Pins trait and Pwm struct

Pwm

Pwm represents one PWM channel; it is created by calling TIM?.pwm(…) and lets you control the channel through the PwmPin trait

Traits

Pins

Pins is a trait that marks which GPIO pins may be used as PWM channels; it should not be directly used. See the device datasheet ‘Pin descriptions’ chapter for which pins can be used with which timer PWM channels (or look at Implementors)

PwmExt

Allows the pwm() method to be added to the peripheral register structs from the device crate