Skip to main content
alun
Visitor II
Jul 28, 2021 3:16 AM UTC
Solved

how long an interrupt handler executes

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.
TDK
TDKBest answer
Jul 28, 2021 3:23 AM UTC

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

1 reply

TDK
TDKBest answer
Jul 28, 2021 3:23 AM UTC

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