cancel
Showing results for 
Search instead for 
Did you mean: 

PWM with phase shift on STM32 F410 using CUBEMX

RJha.1
Associate II

Hi I want to generate two PWM having phase shift between them. I am using stm32f410 and cubemx as platform. Could anyone please help.

1 ACCEPTED SOLUTION

Accepted Solutions

For 50% duty, simply set both channels to Output Compare / Toggle mode, and set the respective CCRx registers to values apart the required phase shift.

Note, that Toggle means one edge per timer period, so you need to set time period to half of the required PWM period.

This probably can be clicked on CubeMX, maybe only the CCRx registered would need to be set manually.

JW

View solution in original post

17 REPLIES 17

For this, in 'F4, you normally need two timers, in master-slave configuration to ensure they run synchronously.

In newer families, some timers have asynchronous and combined modes, which can achieve such phase shift within one timer.

JW

RJha.1
Associate II

You are right but in my Microcontroller I don’t have asynchronous PWM instead I have PWM mode 1 and PWM mode 2. Any alternative?

Generally, two timers, in master-slave configuration.

What *exactly* are your requirements?

JW

I am developing a single phase inverter for which I want to generate four PWMs for four switches. Configuration of four switches are such that two switches constitute one leg so basically there are two legs. I want PWM of one leg to be shifted wrt first leg and also PWM of switch of same leg should be complementary and having dead time.

TDK
Guru

I'm pretty sure it can be done on one timer. Set the pin to toggle on match and adjust the difference between CCRx values to control the phase shift. You'll need to be careful about when you change values to prevent the polarity from swapping.

Of course that's only if 50% duty cycle works.

If you feel a post has answered your question, please click "Accept as Solution".

Complementary channels with deadtime are in TIM1. In 'F410 that's probably it; it's not the best STM32 model for this sort of signals.

Unless you are satisfied with the 50% duty cycle as TDK suggested, which can be pulled out using toggle mode of the output compare, probably the only option is to have a "rolling" DMA-to-CCRx of one channel to provide the phase-shifted signal.

JW

RJha.1
Associate II

I found this where CUBEmx is configured for phase shift as well as for dead time.

https://www.programmersought.com/article/42744314104/

And I am writing (part below) in the user code begin 2. But I am getting no signal as output except noses. Any suggestions?

 HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2);

 HAL_TIMEx_OCN_Start(&htim1, TIM_CHANNEL_2);

 HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3);

 HAL_TIMEx_OCN_Start(&htim1, TIM_CHANNEL_3);

Read our and check the timer and related GPIO registers content.

Read the timer chapter and write to timer registers directly. Clicking in CubeMX and using HAL usually won't allow anything much beyond the examples, so you'd probably need to get there at the end of the day anyway.

JW

RJha.1
Associate II

Any suggestions regarding the steps and configuring the registers?