PWM with phase shift on STM32 F410 using CUBEMX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 7:15 AM
Hi I want to generate two PWM having phase shift between them. I am using stm32f410 and cubemx as platform. Could anyone please help.
Solved! Go to Solution.
- Labels:
-
STM32CubeMX
-
STM32F4 Series
-
TIM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-09 3:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 7:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 7:40 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 8:13 AM
Generally, two timers, in master-slave configuration.
What *exactly* are your requirements?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 8:31 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 10:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 2:15 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 8:41 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-08 10:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-09 2:16 AM
Any suggestions regarding the steps and configuring the registers?
