cancel
Showing results for 
Search instead for 
Did you mean: 

how long an interrupt handler executes

alun
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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

View solution in original post

1 REPLY 1
TDK
Guru

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