cancel
Showing results for 
Search instead for 
Did you mean: 

Detect what kinda edge currently is...

RComa.1
Associate II

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;
		}
 
	}

2 REPLIES 2

Read the current input state of the given pin in the ISR.

JW

There you go! thanks broh!