Skip to main content
Explorer
June 5, 2024
Solved

User timer interrupt for capture multiple time

  • June 5, 2024
  • 2 replies
  • 1107 views

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);
 }

 

 

 

 

 

    This topic has been closed for replies.
    Best answer by Techn

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

    2 replies

    ST Employee
    June 5, 2024

    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 

    SBaro.11Author
    Explorer
    June 5, 2024

    Thanks @Sarra.S do you an example somewhere ?

    TechnAnswer
    Graduate II
    June 15, 2024

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