Skip to main content
sshan.2
Associate III
January 9, 2023
Question

STM32G431RB Two PWMs with 180 degree phase shift

  • January 9, 2023
  • 13 replies
  • 4074 views

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 ??

This topic has been closed for replies.

13 replies

waclawek.jan
Super User
January 9, 2023

On the 'G4 you could use Asymmetric/Combined mode to arbitrarily phase-shift one or two waveforms, but for this particular application it's probably simpler to use plain PWM and center-aligned (up-down counting) mode.

JW

sshan.2
sshan.2Author
Associate III
January 10, 2023

can you please share the required STM32cube IDE PWM Setting links or documents to test this

Javier1
Principal
January 10, 2023

@Community member​ was refferring to this i believe.

Now you could play with TIM1->CR 1 and TIM->CR2(complement) to get what you wanted.

0693W00000Y7s8nQAB.png

hit me up in https://www.linkedin.com/in/javiermuñoz/
DCh.1
Associate II
January 10, 2023

Interested in this too.

But such configuration outputs signals to separate channels (TIM1_CH and TIM1_CH2N). Can they be coupled to protect outputs from occasional high levels on both leading to short circuit?

In other words is it possible to output 30% duty on two pins, 180 degrees phase-shifted and protected with deadtime insertion using TIM1?

waclawek.jan
Super User
January 10, 2023

I don't use CubeIDE.

Individual timer modes are described in the Timer chapter of Reference manual.

JW​

Javier1
Principal
January 10, 2023

I believe he was referring to cubeMX

hit me up in https://www.linkedin.com/in/javiermuñoz/
waclawek.jan
Super User
January 10, 2023

> In other words is it possible to output 30% duty on two pins, 180 degrees phase-shifted and protected with deadtime insertion using TIM1?

No.

JW

DCh.1
Associate II
January 10, 2023

Thank you for your fast reply.

And what are the closest means to implement this? HRTIM?

waclawek.jan
Super User
January 10, 2023

I don't know HRTIM, but I doubt there's anything like this, i.e. hardware enforcement of mutual exclusivity of outputs.

So the closest means may be to implement it so that you don't make software errors in setting up the two channels. Or adding the "mutual exclusive" hardware externally.

JW

waclawek.jan
Super User
January 10, 2023

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

DCh.1
Associate II
January 10, 2023

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
sshan.2Author
Associate III
January 13, 2023

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
Visitor II
January 18, 2023

I got the same question.