cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize Timer 1 and Timer 8 on STM32F446RE

Traubensaft
Associate II

Hi,

I'd like to run synchronous PWMs on TIM1 and TIM8 of an STM32F446RE. I use TIM2 to trigger both timers.

My setup:

Master: TIM2

  • MSM bit is set
  • TRGO = Enable bit (CNT_EN)

Slaves: TIM1 and TIM8

  • Slave mode = Reset mode
  • Trigger source = ITR1

I appended my CubeMX configuration and the according excerpts of the documantation I read (AN4013 & F466 reference manual) as screenshots to this post.

To start the timers I use the following code:

HAL_TIM_Base_Start(&htim2);
HAL_TIM_PWM_Start(&htim8, CH_LVL_1);
HAL_TIM_PWM_Start(&htim1, CH_LVL_2);

I want to set the enable bits on TIM1 and TIM8 simultaneaously by the TRGO event of TIM2. The call of HAL_TIM_PWM_Start(...) should only enable the PWM output on the MCUs pins.

If I use the formerly shown procedure, unfortunatly both PWMs (on TIM1 and TIM8) are phase shiftet by 900 ns, so I assume the enable bits on TIM1 and TIM8 are set by software by the function HAL_TIM_PWM_Start(...).

Can you tell me what I am missing?

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

> That's what I am doing.

Do you?

In your initial post you wrote:

>> Slave mode = Reset mode

I wrote

> You should use Trigger slave mode

That's not the same.

Also, you wrote

>> PWMs (on TIM1 and TIM8) are phase shifted by 900 ns

which implies TIM1 and TIM8 PWMs are running; yet now you write

>TIM1 and TIM8 do not get enabled by the TRGO of TIM2

I can't shoot at moving target.

Read the TIM chapters in RM first. Then read out and check/post all the involved timers' registers, just before TIM2 being enabled. Using random Cube or SPL functions won't lead to results.

JW

View solution in original post

5 REPLIES 5

You should use Trigger slave mode in TIM1 ans TIM8. You should set them up first, without enabling their counter (i.e. leave TIMx_CR1.CEN at 0) and only after that enable TIM2.

I don't Cube do don't know what are the exact incantations there.

JW

Traubensaft
Associate II

That's what I am doing. Even if I initiate the PWM output with

TIM_CCxChannelCmd(TIM_LVL_1->Instance, CH_LVL_1, TIM_CCx_ENABLE);
__HAL_TIM_MOE_ENABLE(TIM_LVL_1);

without enabling the counter of the timer it does not work. TIM1 and TIM8 do not get enabled by the TRGO of TIM2, even though they are configured in slave mode and use IRT1 as a trigger source.

> That's what I am doing.

Do you?

In your initial post you wrote:

>> Slave mode = Reset mode

I wrote

> You should use Trigger slave mode

That's not the same.

Also, you wrote

>> PWMs (on TIM1 and TIM8) are phase shifted by 900 ns

which implies TIM1 and TIM8 PWMs are running; yet now you write

>TIM1 and TIM8 do not get enabled by the TRGO of TIM2

I can't shoot at moving target.

Read the TIM chapters in RM first. Then read out and check/post all the involved timers' registers, just before TIM2 being enabled. Using random Cube or SPL functions won't lead to results.

JW

Traubensaft
Associate II

> You should use Trigger slave mode

Ah, I messed this up. "Trigger mode" instead of "Reset mode" works for me. Thank you very much!

>which implies TIM1 and TIM8 PWMs are running; yet now you write

>>TIM1 and TIM8 do not get enabled by the TRGO of TIM2

Yes, they run if I set the CEN bit in software, obviously. I read the documentation and thought "Reset mode" would be the right choice for me, as marked in the PDF above. Thank you, my problem is solved.

> I read the documentation and thought "Reset mode" would be the right choice for me,

Yes, the documentation is not very clear in what exactly the individual options do.

Glad you got it working.

JW