Skip to main content
John Winters
Associate II
July 31, 2020
Solved

Using the G431RB mounted on the Nucleo board. Can't port the example code for TIM2 pwm output to TIM1???

  • July 31, 2020
  • 8 replies
  • 1868 views

STM32Cube\Repository\STM32Cube_FW_G4_V1.2.0\Projects\NUCLEO-G431RB\Examples_LL\TIM\TIM_PWMOutput

This project runs fine. However, it uses TIM2. I tried to port to TIM1 so I could be interrupted every 10 periods, rather than have to count them in an isr. I did allthe obvious things. Any tricks? My project outputs nothing. I relocated to PA1 from PA5, and made the required changes. No go. What additional init is required for TIM1 that is missing from TIM2?

This topic has been closed for replies.
Best answer by TDK

SET_BIT(TIM1->BDTR, TIM_BDTR_MOE);

8 replies

TDK
July 31, 2020

> What additional init is required for TIM1 that is missing from TIM2?

For TIM1, the TIMx_BDTR_MOE bit needs set to have a PWM output. Only advanced timers (TIM1/TIM8/TIM20) have this bit.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
July 31, 2020

+1

And TIM2 being 32-bit vs TIM1 16-bit on many STM32

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
John Winters
Associate II
July 31, 2020

If you need to see my version of attempting to port to TIM1, let me know please.

TDK
July 31, 2020

> If you need to see my version of attempting to port to TIM1, let me know please.

Well the MOE bit is the only gotcha. So if it's not that, you have something basic wrong.

"If you feel a post has answered your question, please click ""Accept as Solution""."
John Winters
Associate II
July 31, 2020

Thanks guys. As a long time fan of the Three Stooges (Larry, Curly, and Moe), I should of known!

Once I validate that this is the only Gotcha, I'll update.

These short acronyms get me everytime.

John Winters
Associate II
August 1, 2020

I must be using the wrong include files. Same ones as for TIM2 probably don't work for TIM1? No signs of MOE or TIMx_BDTR

TDK
TDKBest answer
August 1, 2020

SET_BIT(TIM1->BDTR, TIM_BDTR_MOE);

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