hi im using stm32g474vet6 timer2 which is 32bit in input capture mode for finding frequency and width.
i can't able to measure more than 400khz frequency. i want to measure 4mhz to 400khz signal, which is 400khz frequency signal and its width will vary from 10 to 100 percent with respect to time. what should be the prescalar and period value for measuring 4mhz signal in mcu timer.
below is the code attached for frequency calculation:
if(htim == &htim2)
{
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
{
if(capture == 0)
{ PWM_OFF_fault();
t1 = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_1);
capture = 1;
TimeElapsedFor.ALM =1;
}
else
{
t2 = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_1);
if(t2>t1)
{
period = t2-t1;
}
else if (t1>t2)
{
period = (4294967295-t1) + t2;
}
float systemclock = 170000000;
frequency = systemclock/(period*170);
TIM2->CNT =0;
capture = 0;
}
i can't able to measure more than 400khz, can someone suggest any solution