Question
Issue in Input capture for overflow condition.
- February 8, 2024
- 2 replies
- 1550 views
Good morning community,
I am capturing the frequency using waveform generator in STM32.
Board: STM32F401RE Nucleo.
It is working at underflow condition.
Condition is,
Reference clock is 25MHz and counter period is 65535. So, minimum frequency is 382Hz and below 381Hz it is not working.
It is not working as per my overflow condition.
Here is my reference code:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim1)
{
if (! is_capture_done)
{
if (count == 1)
{
input_captures[0] = __HAL_TIM_GET_COMPARE(htim1, TIM_CHANNEL_1);
count=0;
}
else
{
input_captures[1] = __HAL_TIM_GET_COMPARE(htim1, TIM_CHANNEL_1);
count = 1;
is_capture_done = 1;
}
}
}
And main function code 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);
}
}
I am telling that elseif part can handle the overflow condition? If not, then how can I handle it? And what is minimum frequency that can be handle by controller?
Here I am sharing my project for your reference.
