TIM1输入捕获为什么进不了中断?

2019-07-21 08:53发布

原子大哥,请教一下,我在用TIM1的PWM输入捕获功能测周期和占空比的时候,进入不了定时器中断函数处理函数,这是什么原因啊? 其中PWM脉冲是由TIM3产生的10kHz脉冲。
程序如下:
void Capture(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 TIM_ICInitTypeDef TIM_ICInitStructure;

 GPIO_InitStructure.GPIO_Pin= GPIO_Pin_8;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_Init(GPIOA,&GPIO_InitStructure);
 GPIO_ResetBits(GPIOA, GPIO_Pin_8);

 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);
}


void TIM1_IRQHandler(void)
{  printf("进入TIM1_IRQHandler ");
 TIM_ClearFlag(TIM1, TIM_IT_CC1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
25条回答
Luluyao
1楼-- · 2019-07-22 12:46
 精彩回答 2  元偷偷看……
Luluyao
2楼-- · 2019-07-22 16:35

void PPM_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 TIM_ICInitTypeDef TIM_ICInitStructure;
 NVIC_InitTypeDef NVIC_InitStructure; 

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

 GPIO_InitStructure.GPIO_Pin= GPIO_Pin_8;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_Init(GPIOA,&GPIO_InitStructure);
 GPIO_ResetBits(GPIOA, GPIO_Pin_8);

 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);     //????
 
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;  //TIM1?? 
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //?????0? 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //????3? 
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ????? 
NVIC_Init(&NVIC_InitStructure);  //??NVIC_InitStruct???????????NVIC??? 
  TIM_Cmd(TIM1,ENABLE);
TIM1->SR=0;     TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);  

}

/////////////////////////////////////////////////////////
void TIM1_CC_IRQHander(void)

   if(TIM_GetITStatus(TIM1,TIM_IT_CC1)!= RESET)
   {  
     TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);                
  } 

}
Geroge
3楼-- · 2019-07-22 20:17
回复【15楼】Luluyao:
---------------------------------
解决了吗?我也遇到相应的问题
Luluyao
4楼-- · 2019-07-23 00:40
回复【16楼】Geroge:
---------------------------------
放弃吧
Geroge
5楼-- · 2019-07-23 01:28
回复【17楼】Luluyao:
---------------------------------
???怎么说
jiutianshenjian
6楼-- · 2019-07-23 02:28
 精彩回答 2  元偷偷看……

一周热门 更多>