Skip to main content
RComa.1
Associate II
July 4, 2022
Question

Detect what kinda edge currently is...

  • July 4, 2022
  • 2 replies
  • 984 views

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

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
July 4, 2022

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

JW

RComa.1
RComa.1Author
Associate II
July 5, 2022

There you go! thanks broh!