PWM in multiple GPIO ports with phase angle shift

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am

PWM in multiple GPIO ports with phase angle shift

Post by palanivel »

Hi Matrix team,
Currently, I try to make a simulation board using STM32F4 series ARM processor for one of my testing projects. I would like to generate the PWM in 6 GPIO ports,
Port 1 = 0 deg Phase angle
Port 2 = Just invert of Port 1 signal
Port 3 = 120 deg Phase angle
Port 4 = Just invert of Port 3 signal
Port 5 = 240 deg Phase angle
Port 6 = Just invert of Port 5 signal

I use 6 timers to generate the PWM. I try to generate the PWM in two different ports, But port's start's at same time and no any phase difference. Can you please guide how to generate the PWM in diffent Phase angle and how to invert the PWM with respect to other port.

Please support.

Regards,
Palani
Attachments
PWM.fcfx
(10.01 KiB) Downloaded 176 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM in multiple GPIO ports with phase angle shift

Post by Benj »

Hello,

Leigh may be able to think of some better ideas but this might help to get you there.

In this example I start PWM1, 2 and 3 with 5ms delay in between and this is very close to the 120 degree phase shift you requested. There may be a way to get more accurate but this should give you a ballpark starting point.

To do the inverted output the chip may have a way of doing this for you, but could you instead use an external inverting buffer IC?
PWM.fcfx
(11.92 KiB) Downloaded 179 times

Another way might be to ditch PWM altogether and use a timer interrupt to do software PWM, this wil give you a lot more control.
Timer_PWM.fcfx
(16.23 KiB) Downloaded 207 times

palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am

Re: PWM in multiple GPIO ports with phase angle shift

Post by palanivel »

Hi Ben,
Thanks. Your code working fine with 3.333 msec delay between each PWM Enable block. But initially, it is OK. but after some time the Phase shift got changed due to the nS variation (333.3 ns in second delay. but I can't put the same in delay) between the PWM to PWM signal. Is there any other method to set the phase angle? PLease advice.

Attached code is working fine. This code can generate PWM in 6 Independent GPIO. Is there any solution for inverting PWM? External circuit (Invert through Not gate) is not feasible for us. Please advice.

Also is there any external C code to enable the SM32F4x MCU's internal RTC?

Palani
Attachments
PWM.fcfx
(16.52 KiB) Downloaded 192 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: PWM in multiple GPIO ports with phase angle shift

Post by LeighM »

Also is there any external C code to enable the SM32F4x MCU's internal RTC?
We currently support the RTC in the F303
I will see if I can get some time to add support for F446

palanivel
Posts: 11
Joined: Thu Jun 14, 2018 8:54 am

Re: PWM in multiple GPIO ports with phase angle shift

Post by palanivel »

Hi Leigh,
It will be good if you add RTC for F407 series and F447 Series. Thanks.

Palani

Post Reply