cancel
Showing results for 
Search instead for 
Did you mean: 

User timer interrupt for capture multiple time

SBaro.11
Associate III

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

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Techn
Senior III

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

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

View solution in original post

3 REPLIES 3
Sarra.S
ST Employee

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.

Thanks @Sarra.S do you an example somewhere ?

Techn
Senior III

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

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