TIM2,采用timing模式,不能进入中断

2019-03-23 19:19发布

TIM2的输入比较,为什么模式选择 timing就进不了中断 如题,我的程序如下: 当 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;时,不能进入中断,但是如果改成其他模式就可以
  void TIM2_Configuration(void)

 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;       TIM_OCInitTypeDef TIM_OCInitStructure;
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 ,ENABLE);    
 
 TIM_TimeBaseStructure.TIM_Period = 65535;     TIM_TimeBaseStructure.TIM_Prescaler = 0;        TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);
 TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate);     
   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;   
 TIM_OCInitStructure.TIM_Pulse = 32768;                  
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC2Init(TIM2, & TIM_OCInitStructure);
 TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable);      TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 16384;
 //TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC3Init(TIM2, & TIM_OCInitStructure);
 TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable);   //不使能预装载寄存器
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 8192;
 //TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC4Init(TIM2, & TIM_OCInitStructure);
 TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable);   //不使能预装载寄存器     TIM_ITConfig(TIM2,TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4,ENABLE);     /* TIM2 enable counter */
    TIM_Cmd(TIM2, ENABLE);//开启时钟 TIM2的输入比较,为什么模式选择 timing就进不了中断 如题,我的程序如下: 当 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;时,不能进入中断,但是如果改成其他模式就可以
  void TIM2_Configuration(void)

 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;       TIM_OCInitTypeDef TIM_OCInitStructure;
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 ,ENABLE);    
 
 TIM_TimeBaseStructure.TIM_Period = 65535;     TIM_TimeBaseStructure.TIM_Prescaler = 0;        TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);
 TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate);     
   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;   
 TIM_OCInitStructure.TIM_Pulse = 32768;                  
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC2Init(TIM2, & TIM_OCInitStructure);
 TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable);      TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 16384;
 //TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC3Init(TIM2, & TIM_OCInitStructure);
 TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable);   //不使能预装载寄存器
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 8192;
 //TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OC4Init(TIM2, & TIM_OCInitStructure);
 TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable);   //不使能预装载寄存器     TIM_ITConfig(TIM2,TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4,ENABLE);     /* TIM2 enable counter */
    TIM_Cmd(TIM2, ENABLE);//开启时钟我在用TIM2做输出比较时,也就是按照keil 安装目录下的ST的timebase例子实验,发现不能进入中断,可是如果把模式改为PWM1或Toggle就可以进入 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。