I am using an STM32l4 nucleo to integrate my project. My aim is to toggle a pin after an interrupt occurs with a 5 ms delay. Below is the implementation in my code
void EXTI1_IRQHandler(void) {
if(k==0){
timestamp1 = HAL_GetTick();
k=1;
flagk=true;
}else{k=0;}
HAL_NVIC_ClearPendingIRQ(EXTI1_IRQn);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
}
and inside my main
while(1){
//timestamp1 = fReturnTimestamp1();
Timestamp2=HAL_GetTick();
if((Timestamp2-timestamp1)<margin){
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_SET);
}else{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_RESET);
}
}
The margin is 5ms. The problem I'm encountering is that when I connect an oscilloscope to the toggle pin, the signal isn't stable. There's a random difference of about 1 ms.