void TIM2_IRQHandler(void)
{
/* Clear TIM2 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
/* Get the Input Capture value */
IC2Value = TIM_GetCapture2(TIM2);
IC1Value = TIM_GetCapture1(TIM2);
if (IC1Value != 0)
{
/* Duty cycle computation */
DutyCycle = ((TIM_GetCapture2(TIM2)) * 100) / IC1Value;
/* Frequency computation */
FrequencyTab[Fre_Count++]=10000/ 2 / IC1Value;
if(Fre_Count >= 10)
{
for(i=1;i<10;i++)
{
sum=sum+FrequencyTab;
}
Frequency=sum/10;
Fre_Count=0;
}
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
源码如上,采集的频率有波动,想加一个求平均值的算法,怎么也搞不好,请高手帮忙分一下问题出现在哪了?
一周热门 更多>