AnsweredAssumed Answered

Configure Timer Input Capture

Question asked by Fede Rico on Nov 10, 2017
Latest reply on May 13, 2018 by waclawek.jan

Hello,

 

I'm trying to measure the frequency of a PWM signal ( 600 Hz) with the Input Capture functionality with an STM32F103.

 

I do these steps:

  • Configure the Tim4 as Input Capture. 
    • Timer Clock 64 MHz;
    • Prescaler = 0; 
    • Period = 65535.

 

This is the callback invoked when a rising edge is detected:

void HAL_TIM_IC_CaptureCallback( TIM_HandleTypeDef *htim )
{
uint16_t capturedValue;
uint16_t delta;

if( (htim == htim4) && (htim->Channel == TIM_CHANNEL_4 )
channelId = PWM_IC_CHANNEL_FLOW_METER;

/* Get CCR register for the specific Timer and Channel */
capturedValue = HAL_TIM_ReadCapturedValue( htim4, TIM_CHANNEL_4 );

if( capturedValue > lastCapturedValue )
/* Compute the input signal frequency */
delta = capturedValue - lastCapturedValue;
else /* Timer counter overflow */
delta = ( 0xFFFF - lastCapturedValue ) + capturedValue;

/* Compute the input signal frequency */
inputFrequencyHz = ( 64000000 / delta );

/* Update the last captured value */
lastCapturedValue = capturedValue;
}

 

Unfortunately I cannot detect the input frequency.

 

Is my configuration correct? My main concern is how to compute the right timer frequency in relation to input signal frequency

 

Thanks for the help! 

Outcomes