Input capture frequency overflow handle
- February 6, 2024
- 3 replies
- 2192 views
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);
}
}
