为什么我设置的是通道4的上升沿捕获中断,但是现在却是按照定时器的计数频率进中断呢?我感觉是我的通道4采集的是定时器自己的计时的上升沿脉冲,这是怎么一回事啊?
//定时器计时
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); //清空中断
TIM_TimeBaseStructure.TIM_Period = Period; //装初值 ,范围 0--0xffff
TIM_TimeBaseStructure.TIM_Prescaler = Prescaler; //预分频值 72M/72,1uS一次计数
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分割值
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式 0->2000
TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure); //结构体初始化
//输入捕获
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; //通道4 ,如果设置直接映射就是TI1
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //捕获上升沿有效
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//对应的中断映射 IC2映射到TI2上
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //不分频 TI4是TIMx_CH4,因为是直连模式
TIM_ICInitStructure.TIM_ICFilter = 0x0; //不滤波
TIM_ICStructInit(&TIM_ICInitStructure);
// TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Trigger); //计数器在触发(TRGI)的上升沿开始
// TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
TIM_ITConfig(TIM2, TIM_IT_CC4 , ENABLE); //使能输入捕获通道4的中断
TIM_Cmd(TIM2, ENABLE); //使能定时器2
}
void TIM2_IRQHandler(void) //B码每个码元10ms左右
{
if(TIM_GetITStatus(TIM2,TIM_IT_CC4)!=RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
printf("TIM: %d 测试捕获\n",TIM_GetCapture4(TIM2));
}
}
|