2026-03-25 3:57 AM - last edited on 2026-03-25 4:00 AM by Andrew Neil
I am using the STM32H753VGT6 microcontroller and need to generate two PWM signals with the same frequency and duty cycle, with a 90-degree phase shift between them, using a single timer. Is this possible? If yes, how can it be achieved?
2026-03-25 4:37 AM
This can not be done.
2026-03-25 4:44 AM
If you know, where the channels have to switch on and off (and calculate this correct),
can be done on advanced timer TIM1 + 8 , with setting : Combined PWM mode .
2026-03-25 5:36 AM
Combined PWM mode will let you have 2 PWM channels with arbitrary duty cycle and offset. They need to be the same frequency.
If ARR = 999, then CCR1 = 0, CCR2 = 100 and CCR3=250, CCR4=350 would be 10% duty cycle, 90 degree offset on channels 1 and 3. All timers with 4 channels can do this.
2026-03-25 10:35 AM
How will this work if > 75 duty cycle and 90 degree offset is requested?
2026-03-25 6:30 PM - edited 2026-03-25 6:32 PM
@Uwe Bonnes You can still do it but there would be a potential discontinuity when you switch settings. Change the polarity of the channel and set CCRx in reversed order.
If you wait for the right cycle within the PWM you could do it without a discontinuity, maybe.
2026-03-30 7:52 AM
Hello @Bhavani
with a single timer, I don't think there is a clean way to generate two PWM signals that simultaneously keep exactly the same frequency, exactly the same duty cycle, and a constant 90° phase shift. You can force an initial 90° shift with something like this
__HAL_TIM_SET_COUNTER(&htim1, 0);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
while (__HAL_TIM_GET_COUNTER(&htim1) < 250) { }
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
, but from the next period onward both channels are driven by the same counter and same compare value, so they naturally re‑align in phase. To maintain a permanent 90° shift you must either use two synchronized timers (which allows same duty and frequency) or stay with one timer but accept that the two channels will have different duty cycles.
BR
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2026-03-31 1:58 AM
Just for my general knowledge , what means 90° phase shift ? does it mean the period of the second channel starts at the middle of the period of the first one ?
2026-03-31 5:15 AM - edited 2026-03-31 5:15 AM
it means the second channel starts 25% of the period after the first channel starts. The rising edges are 25% of a period width apart.
Still think this is perfectly doable with a single timer. OP seems to have disappeared.
2026-03-31 6:05 AM
ok , doable :
- a simple tough : split the period in 4 ones , starting and ending at each rising or falling edge of both channels ; filling each of the 4 periods with 0 or 100% duty (the principle is that one can do everything with STM32 timers)
- I don't remember if one can "buffer" the polarity , ie. a polarity inversion only takes effect at the start of a period (like buffered period or duty cycles) . In that case one can split the period in 2 ones , set the periods and the duties according the need , invert or restore the second channel ...