cancel
Showing results for 
Search instead for 
Did you mean: 

input capture mode

Srinath_03
Associate II

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
 
2 REPLIES 2
Saket_Om
ST Employee

Hello @Srinath_03 

Could you please share your timer settings?

Please use the option "Insert/Edit code sample " to insert your code. See the screenshot below.

Saket_Om_0-1733478786010.png

 

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
Srinath_03
Associate II

as im input frequency is around 400khz i cant able to find the width of the signal , 

timer clock 170mhz

prescalar 0

period full 32bit value 

detecting both the edges 

using dma but im disabling the interuppt 

in my case i want the dma buffer to store the values first rising edge and next falling edge , but sometimes its coming opposite coming some times 

please find the below code and images of configuration

 

if (HAL_TIM_IC_Start_DMA(&htim2, TIM_CHANNEL_2, (uint32_t *)capture_dma_1, 6) != HAL_OK) {

Error_Handler();

}

 

since im using three channels of three signals