Skip to main content
Aknologia
Associate
March 7, 2024
Solved

Using timers as perodic software event trigger

Hello!! I'm a total newbie, so sorry for any mistakes, and I would like to ask for simple explanations as well.

As title states, I would like to use a timer chosen from TIMx, not as an output on a pin, but rather for software only usage, to do an action periodically, instead of using a delay that would halt the rest of execution.

I know which bus the timer is on, what is its frequency. I think I understand how to bring it down using prescaler and ARR. But from other settings in "Pinout & Configuration" tab- what should the channel be set as? Should anything else be changed from default in "Configuration"? Or in other tabs?

And also, how should code look like? Which function (or maybe something else?) would be useful for such application?

I am using CubeIDE version 1.10.1.

This topic has been closed for replies.
KnarfB
KnarfBBest answer
Super User
March 8, 2024

Here is a generic tutorial https://www.digikey.ca/en/maker/projects/getting-started-with-stm32-timers-and-timer-interrupts/d08e6493cefa486fb1e79c43c0b08cc6

As @TDK  said, you don't need to avtivate any channel or pin for that.

hth

KnarfB

 

4 replies

TDK
March 7, 2024

Set the prescaler and reload value to get the period you want. Enable the timer update interrupt. No channels need to be configured. Implement the HAL_TIM_PeriodElapsedCallback callback in your code. Start the timer in your code with HAL_TIM_Base_Start_IT, and HAL_TIM_PeriodElapsedCallback will be called once per timer period.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KnarfB
KnarfBBest answer
Super User
March 8, 2024

Here is a generic tutorial https://www.digikey.ca/en/maker/projects/getting-started-with-stm32-timers-and-timer-interrupts/d08e6493cefa486fb1e79c43c0b08cc6

As @TDK  said, you don't need to avtivate any channel or pin for that.

hth

KnarfB

 

Aknologia
AknologiaAuthor
Associate
March 9, 2024

all three answers have helped me, but this one answered one more problem i had. thank you all!

mƎALLEm
ST Technical Moderator
March 8, 2024

Hello,

This is an example for your reference running on a STM32F4 platform:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324xG_EVAL/Examples/TIM/TIM_TimeBase.

The example consists of toggling a LED when TIM interrupt is fired. 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.