cancel
Showing results for 
Search instead for 
Did you mean: 

Input capture frequency overflow handle

MG1
Associate II

Good afternoon community,
I am trying to capture the frequency which is given by wave-form generator and i am able to capture that,
But issue is i am not able to capture when it is face the underflow condition and it will not working properly.
please suggest which changes need in code. I am sharing all details here for your reference.

Here is callback function 

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

if(is_capture_done == 1)

{

if (input_captures[1] > input_captures[0])

{

capture_difference = input_captures[1] - input_captures[0];

}

else if (input_captures[1] < input_captures[0])

{

capture_difference = ((0XFFFF - input_captures[0]) + input_captures[1]) + 1;

}

// calculate the frequency by capture difference

float refClock = (HAL_RCC_GetPCLK2Freq());

timer2_cnt_freq = refClock / capture_difference;

printf("%lf\n",timer2_cnt_freq);

is_capture_done = 0;

HAL_Delay(1000);

}

}

and main function is

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

if(is_capture_done == 1)

{

if (input_captures[1] > input_captures[0])

{

capture_difference = input_captures[1] - input_captures[0];

}

else if (input_captures[1] < input_captures[0])

{

capture_difference = ((0XFFFF - input_captures[0]) + input_captures[1]) + 1;

}

// calculate the frequency by capture difference

float refClock = (HAL_RCC_GetPCLK2Freq());

timer2_cnt_freq = refClock / capture_difference;

printf("%lf\n",timer2_cnt_freq);

is_capture_done = 0;

HAL_Delay(1000);

}

}

 

4 REPLIES 4
TDK
Guru

Why do you think it's not working exactly? What value are you showing that you think should be different?

What signal are you monitoring and what is its frequency? Note that the timer clock is 2x the APB clock. You will be limited in the frequencies you can capture based on the timer overflow.

If you feel a post has answered your question, please click "Accept as Solution".
MG1
Associate II

Good morning community,
Actually, I type wrong thing. I am facing issue with overflow condition.
 It is working nicely in underflow condition.
So please correct this thing.

else if (input_captures[1] < input_captures[0])

{
      capture_difference = ((0XFFFF - input_captures[0]) + input_captures[1]) + 1;
}
and please suggest also that what happen when both values will same then which value it will consider and how it will work?

Reference is same for this as mentioned above.



You ignored all of my questions. It's hard to debug with no feedback.

If you feel a post has answered your question, please click "Accept as Solution".
MG1
Associate II

Sorry for that I am telling you that,
In particular frequency range it is working finely, but some particular frequency below range it is not working.
Like when first capture value is small than second capture value. So, it is not work in that criteria.
And second thing is that, 
Minimum frequency = Reference clock/Counter period
In our case Reference clock is 25Mhz and counter period is 65535 So, frequency is 381Hz.
Then below the 381Hz it is not given proper response.

In my first query I type "Under flow" instead of "Overflow".
And is this required to handle the overflow condition or there is any particular value of frequency, below that it is not working. Plese guide me.
Hope you getting my question.