cancel
Showing results for 
Search instead for 
Did you mean: 

Using timers as perodic software event trigger

Aknologia
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

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

 

View solution in original post

4 REPLIES 4
TDK
Guru

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

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

 

SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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