cancel
Showing results for 
Search instead for 
Did you mean: 

Phase Shifting PWM2 from PWM1 on Same Timer

Rogers.Gary
Senior II

Is it possible to do this? I need to shift PWM2 by 180 degrees from PWM1. On a test board I am doing this with two timers, with the second timer picking up the count from the first and adding period/2. The current board will not allow this.

I hope it is possible with a single timer and PWM1/PWM2...any suggestions on how this could be accomplished?

Thanks for your help.

7 REPLIES 7

ST's TIM design has a single counting (phase) element

PWM2 should be anti-phase with PWM1. You can expand the low portion of PWM2 by pushing out the CCR value

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rogers.Gary
Senior II

hi, thanks for the reply. An objective is to generate a specific number of pulses. In the TIM2 interrupt, I can count the pulses and then disable the timer. However, PWM2 remains high after that. How can it be reset at that point?

Also - ccan you explain what "expanding the low portion of the CCR value" (register) would do? And would this be achieved by directly writing it?

Rogers.Gary
Senior II

LL_TIM_CC_DisableChannel kills the output, so that is now OK. Could you still clarify what you meant by expanding the low portion of the CCR value. Thanks!

You didn't care to tell us which STM32 are you using.

Newer STM32 like the 'L4 or 'F7 come with timers which (some of them) have so called assymetric and combined pwm modes. These are designed to allow you to generate phase shifted waveform, at the cost of using 2 channels for one output.

JW

PWM1 -------\__________________
PWM2 _______/------------------
            ^CCRx == CNT

In PWM1 the CCRx value determines the length of the HIGH signal, in PWM2 it is the length of the LOW signal

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rogers.Gary
Senior II

it's the STM32L476. So far using LL drivers I think this seems to be working out. Using TIM3, I can generate PWM1/PWM2, with PWM2 phase shifted ever so slightly by the differential of the duty cycle. And I can generate the exact number of cycles as well. Thanks!

Ah, thanks. That should be enough to work with.