embassy icon indicating copy to clipboard operation
embassy copied to clipboard

`stm32` PWM complementary pin

Open indietyp opened this issue 3 years ago • 1 comments

I have been trying to use the SimplePwm type of the embassy-stm32 crate, and while mostly successful, I have been trying to use complementary channels for a negated signal of the PWM signal.

While looking at the source code and the existing examples, I could not find a way to use complementary channels. (There do seem to be traits related to them tho, e.g., Channel3ComplementaryPin)

How would I enable complementary pins? Any help would be very much appreciated!

Thank you very much for creating such a fantastic library!

indietyp avatar Oct 25 '22 16:10 indietyp

Hey, this anwser might be a bit late, but you need to create a complementary pin first, like this

let pc5 = ComplementaryPwmPin::new_ch4(p.PC5, OutputType::PushPull);

Then create the pwm like this

        let pwm1 = ComplementaryPwm::new(
            p.TIM1,
            Some(pa8),
            None,
            Some(pa9),
            None,
            None,
            None,
            None,
            Some(pc5),
            hz(50),
            CountingMode::EdgeAlignedUp,
        );

where you always supply CH1, CH1N, CH2, CH2N,... (pa8 is ch1 in this example and pa9 ch2, with pc5 being ch4n)

moritz-geier avatar May 03 '25 14:05 moritz-geier