cancel
Showing results for 
Search instead for 
Did you mean: 

How to phase shift two complementary PWM signal based on some internal TIMER event?

GenuineDeveloper
Associate III

I am using STM32F051R8T6. My application is to drive a full bridge configuration, for which I require two pair of complementary PWM signals with dead time insertion. So far I have been able to achieve this using two channles of a timer( CH1-CH1N and CH2-CH2N of TIM1). Now, I need to control the output by turning ON & OFF the full bridge configuration based on the ON time & OFF time respectively of another PWM signal generated by an independent timer (say, TIM2_CH2). To achieve this, I need to phase shift(by 180 degree) one set of complementary signals(CH1 & CH1N) during each ON time and OFF time of the independent PWM signal generated by Timer2. I s there any way by which the polarity of CH1 and CH1N of timer 1 can be configured, such that it changes in response to some internal timer events? Or are there any alternative techinques to achieve this?

Please refer the image for reference.

0690X00000AsNaKQAV.jpg

1 ACCEPTED SOLUTION

Accepted Solutions

Then don't invert the waveform using TIMx_CCER.CC1P/CC1NP, but changing it in TIMx_CCMR1 from PWM1 to PWM2, and vice versa.

JW

View solution in original post

8 REPLIES 8

There's probably no hardware/automated way to do this internally in an STM32. You can in interrupt from TIM2 change the polarity of one of the complementary outputs in TIMx_CCER.

JW

So I should set TIM2 to generate an interrupt after a set time. How to change polarity of a running PWM channel and its complementary channel in an ISR?

You need to change polarity of only one of them, for example for CH1:

TIM1->CCER = TIM1->CCER ^ TIM_CCER_CC1P

As an advanced feature, you could use the Communtation feature, which is not very well described in the manuals. You would set an appropriate channel from TIM2 as TRGO and in TIM1_SMCR.TS you would set TIM2 as TRGI. In TIM1.CR2 set both CCPC and CCUS. You still will need to change TIM1_CCER.CC1P (or CC1NP) in an interrupt, but it would not get immediately active, but only after the next TRGO-TRGI rising edge.

JW

Thank you. I am able to change the polarity now, but the problem is I had introduced dead time in the complementary signals, and now after changing the polarity the dead time is also affected, since, after every polarity change the OFF time becomes ON time or vice versa. Ideally the ON time should always be smaller than the OFF time. How do I restrict this change? Or am I doing something wrong here by changing the polarity?

Maybe you should then, instead of changing polarity of one of the outputs, simply change both outputs from AF to Out in their respective GPIO_MODER, with resective ODR being set to the same (perhaps OFF) level.

JW

GenuineDeveloper
Associate III

But I think I am looking for phase shifted PWM, can I achieve this using STM32F051R8T6 device(i did not find any reference in the reference manual)? Is there any other way to implement a phase shift in pwm?

Then don't invert the waveform using TIMx_CCER.CC1P/CC1NP, but changing it in TIMx_CCMR1 from PWM1 to PWM2, and vice versa.

JW

GenuineDeveloper
Associate III

Thank you. How did changing from PWM1 to PWM2 create a phase shift of 180?