cancel
Showing results for 
Search instead for 
Did you mean: 

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

John Winters
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

SET_BIT(TIM1->BDTR, TIM_BDTR_MOE);

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

View solution in original post

8 REPLIES 8
TDK
Guru

> 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".

+1

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

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
John Winters
Associate III

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

TDK
Guru

> 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 III

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 III

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
Guru

SET_BIT(TIM1->BDTR, TIM_BDTR_MOE);

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

Definitely defined in the CMSIS include file:

https://github.com/STMicroelectronics/STM32CubeG4/blob/3e5243a22addb3cd323dba491eaf43c85ff448f3/Drivers/CMSIS/Device/ST/STM32G4xx/Include/stm32g431xx.h

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