cancel
Showing results for 
Search instead for 
Did you mean: 

4 inputs pwm on TIM4

cchechio
Associate II
Posted on July 03, 2014 at 20:32

How change this function to read frequency and dutycycle of 4 different pwm signals?

void TIM4_IRQHandler(void){

    

  RCC_ClocksTypeDef RCC_Clocks;

  RCC_GetClocksFreq(&RCC_Clocks);

  /* Clear TIM4 Capture compare interrupt pending bit */

  TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);

  /* Get the Input Capture value */

  IC2Value = TIM_GetCapture2(TIM4);  

  if (IC2Value != 0)

  {

    /* Duty cycle computation */

    DutyCycleB7 = (TIM_GetCapture1(TIM4) * 100) / IC2Value;

    /* Frequency computation 

       TIM4 counter clock = (RCC_Clocks.HCLK_Frequency)/2 */

    FrequencyB7 = ((RCC_Clocks.HCLK_Frequency)/2 /(IC2Value));    

  }

  else

  {

    DutyCycleB7 = 0;

    FrequencyB7 = 0;

  }

  }
3 REPLIES 3
Posted on July 04, 2014 at 02:54

As far as I'm aware you can only measure a single PWM signal in PWM Input mode, as it uses TWO channels, and resets the ONLY counter.

To measure 4 Servo PWM signals you could probably use Input Capture mode, catching both edges, and recording the current and prior latched content to figure period and duty. For 50 Hz this isn't much of a problem, hundreds on KHz on multiple channels, probably not so much.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cchechio
Associate II
Posted on July 14, 2014 at 15:31

Where can I found an example?