2024-06-05 05:29 AM
Hi all,
I'm working with STM32F4 discovery board, and I'd like to know if I can use one timer with interrupt to capture multiple time.
For example I'd like to use TIM16, and be able to check 4 times : 150ms, 250ms, 500ms and 1000ms is it possible? After some researches I think I have to use `CNT` value. But how can I know if the time ellasped is 500ms for example ?
I've already do something like this in my while loop, it's working but I'd like to do thaht in an interrupt
// If enough time has passed (1 second), toggle LED and get new timestamp
if (__HAL_TIM_GET_COUNTER(&htim16) - timer_val >= 10000)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
timer_val = __HAL_TIM_GET_COUNTER(&htim16);
}
Solved! Go to Solution.
2024-06-15 04:25 AM
One suggestion is to have the basic timer with say 10ms , keep one count incremented, when it reach 15, 25,50 etc you can do the necessary action.
Eg if(count%15 ==0) means 150,300,450 etc..
2024-06-05 06:18 AM
Hello @SBaro.11,
Think of using output compare to indicate when a period of time has elapsed to generate interrupts at different time intervals
Enable interrupts and implement ISR for each OC channel
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.
2024-06-05 06:20 AM
Thanks @Sarra.S do you an example somewhere ?
2024-06-15 04:25 AM
One suggestion is to have the basic timer with say 10ms , keep one count incremented, when it reach 15, 25,50 etc you can do the necessary action.
Eg if(count%15 ==0) means 150,300,450 etc..