这是TI官方的PWM Input例程,测量TIM3 Channel2输入的频率和占空比,配置了TIM3 Channel2为输入捕获模式,开了主从模式,上升沿开始计数,测频率的部分看懂了,测占空比的部分没看懂
void TIM3_IRQHandler(void)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);
/* Get the Input Capture value */
IC2Value = TIM_GetCapture2(TIM3);
if (IC2Value != 0)
{
/* Duty cycle computation */
DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;
/* Frequency computation */
Frequency = SystemCoreClock / IC2Value;
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
求大神们解释一下占空比是怎么得到的,TIM_GetCapture1(TIM3)得到的值和TIM_GetCapture2(TIM3)有什么关系,谢谢 |