cancel
Showing results for 
Search instead for 
Did you mean: 

2 PWMs in-sync with each other and 180 degrees our of sync

Ricko
Associate II

Hi,

I am new to STM32 and am using a STM32L452RET6 and need to have two PWM signals so that they can be configured via software to sometimes work in perfect sync (i.e. as if they are the same pin output) and some other times to work 180 out of sync (i.e. when one is low the other is high).

 

I am currently using PA0 to generate the first PWM. Which pins can I use to setup the second PWM so it works as mentioned above?

 

If for some reason it is preferred to use another pair of pins, can you please suggest which ones).

 

Thank you 😊

3 REPLIES 3
Sarra.S
ST Employee

Hello @Ricko

Since you're using PA0 for the first PWM, typically you're using TIM2_CH1, however, to have complementary outputs (which allow for easy configuration of out-of-phase signals), you would ideally use an advanced timer like TIM1.

if you want to use TIM1, you could use PA8 for TIM1_CH1 and PA7 for TIM1_CH1N for complementary outputs.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

> when one is low the other is high

Use two channels of the same TIM, for one channel use PWM1 mode and for the other PWM2 mode.

Alternatively, you can change signal polarity using TIMx_CCER.CCxP bits.

JW

Thank you both @Sarra.S and @waclawek.jan