0
votes

I'm using a Nucleo STM32L031. In my application, I want to generate interrupts using Timer and a Compare Value. My problem is: I want to start the timer, then pause it (so the counter value is halt, but not be reset), then start the timer again (from the halt value). And then when it reaches the compared value, it generates an interrupt.

How can I pause the timer without reseting the counter value ? And also I'm not sure whether: HAL_TIM_BASE_Stop_IT() function will pause or reset the counter value?

Thanks. Bien

1

1 Answers

2
votes

There two ways as minimum:

first is set/reset CEN bit in CR1 register, when timer paused this way it can be reconfigured and use (but I can't say this about reconfigure through HAL functions)

htimX.Instance->CR1 &= ~TIM_CR1_CEN; // pause tim
htimX.Instance->CR1 |= TIM_CR1_CEN;  // resume tim

second is gate/ungate tim clock, when timer paused this way it does not clocked, so it cannot be reconfigured, but exist one advance is power saving

__HAL_RCC_TIMx_CLK_ENABLE();  // pause tim
__HAL_RCC_TIMx_CLK_DISABLE(); // resume tim