我用stm8s105C6T6芯片,用到TIM1_CH1的输入捕获功能,初始化如下:
TIM1_DeInit();
TIM1_TimeBaseInit(49, TIM1_COUNTERMODE_DOWN, 65535,0);
TIM1_ICInit( TIM1_CHANNEL_1, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI , TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig( TIM1_IT_CC1, ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC1);
TIM1_Cmd(ENABLE);
想在中断中改变为上升沿捕获,代码如下,测试发现和没有在中断中改变是一样的。好像在中断中改变输入捕获极性没起作用。不知道是什么原因?
TIM1_ClearITPendingBit(TIM1_IT_CC1);
ICValue1 = TIM1_GetCapture1();
if(ICValue1 > ICValue2)
period = ICValue1 - ICValue2;
else
period = 0xffff - ICValue2 + ICValue1;
if(enter_time == 0){
TIM1->CCER1 &= (u8)(~TIM1_CCER1_CC1P);//改为上升沿
enter_time = 1;
}
else{
TIM1->CCER1 |= TIM1_CCER1_CC1P;//改为下降沿
enter_time = 0;
}
ICValue2 = ICValue1; |