2022-07-04 07:11 AM
Hello guys, i am using the code below (input capture mode, timer 3) because i need measure the high and low pulses, but i am not sure how to know which edge generate the interrupt, i have configured the timer with both edges, but in the interrupt code i need to know what edge is running...
any idea?¿
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim){
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1){
if (Is_First_Captured==0) // if the first rising edge is not captured
{
IC_Val1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); // read the first value
Is_First_Captured = 1; // set the first captured as true
}else{
IC_Val2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); // read the second value
if (IC_Val2 > IC_Val1)
{
Difference = IC_Val2-IC_Val1;
}
else if (IC_Val1 > IC_Val2)
{
Difference = (0xffffffff - IC_Val1) + IC_Val2;
}
__HAL_TIM_SET_COUNTER(htim, 0);
Is_First_Captured = 0;
}
}
2022-07-04 01:06 PM
Read the current input state of the given pin in the ISR.
JW
2022-07-05 01:55 AM
There you go! thanks broh!