2024-03-07 01:51 PM
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.
Solved! Go to Solution.
2024-03-07 04:03 PM
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
2024-03-07 03:56 PM
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.
2024-03-07 04:03 PM
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
2024-03-08 06:33 AM
Hello,
This is an example for your reference running on a STM32F4 platform:
The example consists of toggling a LED when TIM interrupt is fired.
2024-03-09 06:19 AM
all three answers have helped me, but this one answered one more problem i had. thank you all!