Skip to main content
alun
Visitor II
July 28, 2021
Solved

how long an interrupt handler executes

  • July 28, 2021
  • 1 reply
  • 734 views

i want to measure the time an interrupt handler costs.

1. set a specified pin low at the beginning of the interrupt handler and high at the end of the interrupt handler like this:

void EXTI4_IRQHandler(void)
{
 /* USER CODE BEGIN EXTI4_IRQn 0 */
 HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
 
 /* USER CODE END EXTI4_IRQn 0 */
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
 /* USER CODE BEGIN EXTI4_IRQn 1 */
 
// ...
 // codes omitted
// ...	
 
 HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);	
}

​2. measure the signal at the pin by an oscilloscope.

then the duration the signal keeps low is the time an interrupt costs.

is ​it possible to measure the duration in units of us?

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

Yep, that will work. You'll miss some overhead due to the ISR entry/exit and the HAL_GPIO_WritePin calls.

Another option would be to enable and use the debug DWT->CYCCNT timer which ticks at the system clock rate.

1 reply

TDK
TDKBest answer
Super User
July 28, 2021

Yep, that will work. You'll miss some overhead due to the ISR entry/exit and the HAL_GPIO_WritePin calls.

Another option would be to enable and use the debug DWT->CYCCNT timer which ticks at the system clock rate.

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