cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f407 center aligned PWM with phase shift

Tomislav Matic
Associate II
Posted on June 17, 2018 at 15:29

Hello everyone.

I'm using STM32F407 Black VET6 board. I need to create 6 center-aligned synchronized PWM signals with the same frequency, but every signal needs to have its own DutyCycle and PhaseShift control. Example of 3 signals is given in them image below. I have read

https://community.st.com/0D50X00009XkdmtSAB

 STM32F407 doesnt have asymetric mode, also

https://community.st.com/0D50X00009XkYAiSAN

but every signal should have different duty cycle. In my case all six signals need to be in sync.

Is this possible with STM32F407? Can you point me to the write direction, which timers to use, in what mode...?

Thanks in advance.

0690X0000060BebQAE.png

null
10 REPLIES 10
Posted on June 18, 2018 at 09:59

You can't achieve independent phase and duty change in one timer in 'F407.

Look at arranging timers as master-slave couples to achieve the required phase shift (slave in reset mode). Learn how to do it with two timers, first, to adjust the phase shift. The use e.g. TIM2 as master for TIM1, TIM3, TIM4, TIM5, TIM8, (TIM9). You will not be able to establish the phase shift at the same time, you'll need to do that gradually, one at a time. If this does not suit you, there may be no solution in the STM32 for your requirement.

I wouldn't insist on 'center aligned' - 'center aligned' is just one special case of 'variable duty and phase', and may complicate things further, unnecessarily.

I don't know what's 'black VET6' board.

JW

henry.dick
Senior II
Posted on June 18, 2018 at 12:06

'

Is this possible with STM32F407?'

depending on your desired speed: software can do anything, with enough processing power + time.

Tomislav Matic
Associate II
Posted on June 18, 2018 at 12:31

I will correct myself 'Is this possible with

STM32F407

timers?'
Posted on June 18, 2018 at 12:30

Thank you for a quick response. 'black VET6' board link

http://wiki.stm32duino.com/index.php?title=STM32F407

  Your suggestion is that eg. TIM2 CH1, CH2, CH3, CH4 are masters and TIM2 CCR1, CCR2, CCR3, CCR4 are responsible for phase delay. TIM3 CH1, CH2, CH3, CH4 are slaves and TIM3 CCR1, CCR2, CCR3, CCR4 are responsible for duty.

Because I need 6 PWM a will need to use additional pair of timers eg. TIM4 CH1, CH2 (master) and TIM5 CH1, CH2 (slave).

Am I correct? If yeas, can TIM2 and TIM4 be somehow synced so they start counting at the same time?

Thanks

Posted on June 18, 2018 at 13:11

Absolutely, at low enough speed.

And absolutely not possible, at too high of a speed.

Tomislav Matic
Associate II
Posted on June 18, 2018 at 20:55

I need six variable phase and duty PWMs. Every PWM should have independent phase and duty. All six PWM must be in sync around a reference point (dashed line in the image above).  Frequency is fixed. Max frequency is 24 kHz. Resolution (phase and duty) must be 10 bits or more.

Till now I only worked with PWM mode1. I will read about master-slave and try to generate one PWM signal.

Main point is that I need 12 timers for 6 PWMs. One question remains, can these timers all start at the same time so that I don't have an initial phase delay between the PWMs?

Posted on June 18, 2018 at 19:55

- master-slave connections are per timer, not per channel

- you can't have multiple phase-independent PWMs in several channels of one timer

-as dhenry said it all depends on detailed requirements, so you may want to tell us more about required PWM frequencies and duty range, how often they will need to have duty and phase adjusted

- read the timer chapter in RM

- play with the hardware - try one timer several channels, then try two timers in master/slave

JW

Posted on June 18, 2018 at 22:00

Main point is that I need 12 timers for 6 PWMs.

No, you don't. You need one timer per PWM output.

One question remains, can these timers all start at the same time so that I don't have an initial phase delay between the PWMs?

No, you want them to start with the given phase shift against each other (or against one of them, which is to be the reference). This is where the master-slave connection comes in play, the master outputting the synchronization signal (TRGO) from one of its output channels, adjusted to the required phase shift; the slave being reset by that signal (which is TRGI for the slave).

The problem is, that you can't do that at once, as there's only one TRGO and one TRGI per timer. So you need to do that one slave at a time, i.e. it would take one cycle of the master timer to change relative phase of one slave. This is sure a limitation; but I'd be surprised if this would be a showstopper.

JW

Posted on June 18, 2018 at 22:15

'

Main point is that I need 12 timers for 6 PWMs.'

That is easy to do:

1. Generate 6 pwm pulses.

2. Free run the unused timers so you can pretend to use all 12 timers.