TIM1输入捕获为什么进不了中断?
1个回答
展开全部
TIM_DeInit(TIM1); //将外设TIM1寄存器重设为默认值
/*设置时间基准*/
TIM_TimeBaseStructure.TIM_Prescaler=0; //时钟频率的预分频值
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=7200-1; //自动重装载寄存器周期值
TIM_TimeBaseStructure.TIM_ClockDivision=0x0;//时钟分割值
TIM_TimeBaseStructure.TIM_RepetitionCounter=0x0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure); //初始化TIM1的时间基数数据
TIM_ICInitStructure.TIM_Channel= TIM_Channel_1;//选择通道2
TIM_ICInitStructure.TIM_ICPolarity= TIM_ICPolarity_Rising;//上升沿
TIM_ICInitStructure.TIM_ICSelection= TIM_ICSelection_IndirectTI;//通道方向选择
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;/*每次检测到捕获输入就触发一次捕获 */
TIM_ICInitStructure.TIM_ICFilter=0x00;/* 对分频率没有影响 选择输入比较滤波器*/
TIM_PWMIConfig(TIM1, &TIM_ICInitStructure); //根据参数配置TIM外设信息
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); //选择IC1为始终触发源
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);//TIM从模式:触发信号的上升沿重新初始化计数器和触发寄存器的更新事件
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE); //打开中断
TIM_Cmd(TIM1,ENABLE);}
/*设置时间基准*/
TIM_TimeBaseStructure.TIM_Prescaler=0; //时钟频率的预分频值
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=7200-1; //自动重装载寄存器周期值
TIM_TimeBaseStructure.TIM_ClockDivision=0x0;//时钟分割值
TIM_TimeBaseStructure.TIM_RepetitionCounter=0x0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure); //初始化TIM1的时间基数数据
TIM_ICInitStructure.TIM_Channel= TIM_Channel_1;//选择通道2
TIM_ICInitStructure.TIM_ICPolarity= TIM_ICPolarity_Rising;//上升沿
TIM_ICInitStructure.TIM_ICSelection= TIM_ICSelection_IndirectTI;//通道方向选择
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;/*每次检测到捕获输入就触发一次捕获 */
TIM_ICInitStructure.TIM_ICFilter=0x00;/* 对分频率没有影响 选择输入比较滤波器*/
TIM_PWMIConfig(TIM1, &TIM_ICInitStructure); //根据参数配置TIM外设信息
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); //选择IC1为始终触发源
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);//TIM从模式:触发信号的上升沿重新初始化计数器和触发寄存器的更新事件
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE); //打开中断
TIM_Cmd(TIM1,ENABLE);}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询