Skip to main content
John Hite
Associate III
April 29, 2022
Question

STM32F4 Timer count reset

  • April 29, 2022
  • 3 replies
  • 1469 views

htim5 has been running and I need to zero the count (CNT?).

Do I need to stop, de init, init, then start?

Also it seems HAL_TIM_OC_Init() is being used with HAL_TIM_Base_Start_IT(() on the same timer, TIM5. It is used to to generate interrupts with a period of 0xFFFF FFFF. Is this correct?

htim5.Instance = TIM5;
 htim5.Init.Prescaler = 83;
 htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim5.Init.Period = 0xffffffff;
 htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 // htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 if (HAL_TIM_OC_Init(&htim5) != HAL_OK)
 {
 Error_Handler();
 }
HAL_TIM_Base_Start_IT(&htim5);

Thanks

This topic has been closed for replies.

3 replies

TDK
April 29, 2022

CNT can be modified with the timer still running.

TIM5->CNT = 0;

You need a call to HAL_TIM_Base_Init to initialize, not HAL_TIM_OC_Init, if you want interrupts from the update signal, which is the typical method.

"If you feel a post has answered your question, please click ""Accept as Solution""."
John Hite
John HiteAuthor
Associate III
April 29, 2022

Next time I try to read CNT the watchdog IRQ fires off. Probably a side effect tho.

TDK
April 29, 2022

Reading CNT will not cause a watchdog event to occur. Must be another reason.

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