风驰老大,我要用tim1捕获PWM波每个上升沿、下降沿得出高电平,请问捕获函数中能直接这么写么?
u16 Get_IC_PWMH(void)
{
//清空输入捕捉值
TIM1->CCR3H=0;//PC1
TIM1->CCR3L=0;
TIM1->CCR4H=0;//PC2
TIM1->CCR4L=0;
//通道1--PC6捕捉
while(!TIM1_GetFlagStatus(TIM1_FLAG_CC3));//等待RISING捕获标志位置位
ICValue1 = TIM1_GetCapture3();//得到第一次RISING捕捉计数值
TIM1_ClearFlag(TIM1_FLAG_CC3);//清空标志位
//通道2--PC7捕捉
while(!TIM1_GetFlagStatus(TIM1_FLAG_CC4));//等待FALLING捕获标志位置位
ICValue2 = TIM1_GetCapture4();//得到第二次FALLING捕捉计数值
TIM1_ClearFlag(TIM1_FLAG_CC4);//清空标志位
//必须考虑是否溢出
if(ICValue2 > ICValue1)
Period = ICValue2 - ICValue1;
else if(ICValue2 < ICValue1)
Period = 0xffff - ICValue1 + ICValue2;
//PWM-Hightime值us
PWM_HPeriod = Period/(16*1);
} |