Skip to main content
Shlomi Weiner
Associate II
June 22, 2017
Question

Measuring frequency and duty cycle of two independent signals.

  • June 22, 2017
  • 0 replies
  • 427 views
Posted on June 22, 2017 at 09:37

Hello all,

I am using two different timers(TIM2 and TIM3) in order two measure frequency and duty cycle of two independent signals.

As the example guides, i used the  HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) function to make those measurements, but I succeeded  to get a measurement only for one signal.

What I have to change/add to this function in order to make those two measurements  in the same time.

Thanks.

Here is the full function:

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

 

  if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)

  {

    /* Get the Input Capture value */

    uwIC2Value = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);

    if (uwIC2Value != 0)

    {

      /* Duty cycle computation */

      uwDutyCycle = ((HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1)) * 100) / uwIC2Value;

      /* uwFrequency computation

      TIM1 counter clock = (RCC_Clocks.HCLK_Frequency) */

      uwFrequency = (HAL_RCC_GetHCLKFreq()/2)  / uwIC2Value;

    }

    else

    {

      uwDutyCycle = 0;

      uwFrequency = 0;

    }

  }

}
    This topic has been closed for replies.