stm8s103f3 pwm 输入捕获 只用tim1 ch1单个寄存器
初始化:TIM1_DeInit();
TIM1_TimeBaseInit(7, TIM1_COUNTERMODE_UP,40000,0);
TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_FALLING,
TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV8, 0x00);
TIM1_ClearFlag(TIM1_FLAG_CC1);
TIM1_CCxCmd(TIM1_CHANNEL_1, ENABLE);
TIM1_ITConfig(TIM1_IT_CC1,ENABLE);
中断:#pragma vector=14
__interrupt void Timer1Capture(void)
{
if(TIM1_SR1 & 0x01)
{
if( TIM1_CCER1 & 0x01)//下降沿产生的中断
{
ICValue1 =TIM1_GetCapture1();
TIM1_CCER1 &=0x01;//改为上升沿捕获
}
else//上升沿产生的中断
{
ICValue2 =TIM1_GetCapture1();
TIM1_CCER1|=0x01;
}
}
if(ICValue2 > ICValue1)
Period = ICValue2-ICValue1;
else if(ICValue2<ICValue1)
Period = 0xffff + ICValue2-ICValue1;
HIGH=Period/8;
}
只能捕获到ICValue1的值,不知道哪里设置错了,求解! |