cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Timer count reset

John Hite
Associate III

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

3 REPLIES 3
TDK
Guru

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

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

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