cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431RB Two PWMs with 180 degree phase shift

sshan.2
Associate II

I have configured the TIM1 with PWM CH1 and CH1N, with 62.KHz frequency .

I am getting the 180 degree phase shift for 50 % duty cycle .If i vary duty cycle to 30 % then CH1 =30% and CH1N will be 70 % and it is inverted .I need same duty cycle with 180 degree Phase on two PWM ports .

please can some one answer this how to achieve this ??

13 REPLIES 13

On second thought... you probably could use the tim in center-aligned mode (up-down), use CH1 to generate one waveform as normal PWM, and use CH2 in Combined OR mode while inverting it by setting TIMx_CCER.CC2P.

Read the Combined mode subchapter in TIM chapter in RM, and the description of it within description of TIMx_CCMR.OCxM field. Then experiment, best on a Nucleo or similar, while observing the outputs using LA or oscilloscope.

JW

But CH1 and CH2 are not "mutual exclusive" in hardware too. Or am I missing something?

I thought about setting constant 50% duty in complementary mode (CH1 and CH1N) and instead of decreasing the duty cycle, increasing the dead time (and vise versa). In such a way the output exclusiveness is enforced by DTG, but it feels like a dirty hack.

sshan.2
Associate II

Thanks every one . I am able to generate the Two PWMs with Phase shift of 180 degree with equal duty cycles on CH1 and CH2

1.Selected TIM1 Channel1 -PWM Generation CH1 and Channel2-PWM Generation Channel CH2

2.Selected The Clock 170 MHz and Counter Mode ->Center Aligned Mode1 and Counter period =2720

3.In the PWM generation Channel 1-> pulse =Duty cycle value

4.In the PWM generation Channel 2-> pulse =Counter period - Duty cycle value and CH Polarity LOW

I made above settings and getting the PWM pulses and if any corrections or any other methods please let me know

Thanks

JDayt.1
Associate

I got the same question.