我在固件库里找到了输入捕获的例子,中断里面是读取前后两次脉冲到来时CCR的值,因为捕获的脉冲宽度大于计数周期0xFFFF,所以,可能出现的情况是后一个值比前一个值小,这种情况计数就出错了,不知道怎么读取溢出标志啊。
if(capture_number_1==0)
{
/* Get the Input Capture value */
ic4_readvalue1_1 = TIM_GetCapture1(TIM4);
capture_number_1 = 1;
}
else if(capture_number_1 == 1)
{
/* Get the Input Capture value */
ic4_readvalue2_1 = TIM_GetCapture1(TIM4);
/* Capture computation */
if (ic4_readvalue2_1 > ic4_readvalue1_1)
{
CAPTURE_1 = (ic4_readvalue2_1 - ic4_readvalue1_1) - 1;
}
else
{
CAPTURE_1 = ((0xFFFF - ic4_readvalue1_1) + ic4_readvalue2_1) - 1;
}
这样算的话,当发生了一次溢出,且ic4_readvalue2_1 > ic4_readvalue1_1的时候就会出错了。请香主帮忙啊 |