2014-07-03 11:32 AM
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; } }2014-07-03 05:54 PM
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.2014-07-14 06:31 AM
Where can I found an example?
2014-07-14 07:39 AM
Where can I found an example?
Forum, Firmware Library examples, Google, etc... Here's an example for PWM Input, for a Servo Channel 4 Channel Input Capture (for F0 but applicable across other parts)