cancel
Showing results for 
Search instead for 
Did you mean: 

Phase shifted PWM

VasuManiV
Associate II

Hello,

 

Am using STM32L412RBT6 controller to generate PWM for our battery charger product. We need to generate two PWM's and am using TIM1_CH1 and TIM1_CH1N pins to generate 2 PWM's. These are all configured through Timer1. 

 

Here i have a requirement, we want to generate phase shift between these 2 PWM outputs. 

Is it possible?

2 REPLIES 2

> Is it possible?

No.

TIM1_CH1 and TIM1_CH1N are complementary outputs of one timer channel. In other words, TIM1_CH1N  is always 180° in respect to TIM1_CH1.

For phase shifted outputs, you need to use a different channel in Combined PWM mode - and TIM1_CH1 excludes using TIM1_CH2.

JW

> No @waclawek.jan it is not always complementary we can configure as same PWM also.

Yes, if you invert TIM1_CH1N using TIM1_CCER.CC1NP (or, for that matter, CC1P), the two signals are in phase. And, strictly speaking, it's complementary with deadtime insertion, so it's not strictly complementary. However, neither of these will solve your problem.

> How can give phase shift when we different channel like TIM1_CH2?

As I've said, you would need Combined mode, and as that uses a channel pair (CH1&CH2 or CH3&CH4) that excludes using TIM1_CH2 if you've already used TIM1_CH1. Combined mode ANDs (or ORs, both option is available, see description of TIMx_CCMR1.OC1M in RM, values 0b1100 and 0b1101) the outputs of the given channel pair, so you set one channel to PWM mode 1, (no output pin needed for this channel) and set its "pair" channel to Combined mode 2 (ie. which ANDs), and by setting the pulses for both of them so that they overlap, the result is a pulse with arbitrary length and arbitrary phase respective to the timer's period. Refer to Combined PWM mode subchapter in Timer chapter in Reference Manual for the details.

Another option would be to use a different timer which would be delayed through the master-slave connection between the two timers.

JW