STM32高级定时器1 输入捕获不进入中断

2019-12-27 18:57发布

这个是代码      请教下是什么问题:

int  IC2Value=0,DutyCycle=0,Frequency=0;

void Time_cinfig()
{
  TIM_ICInitTypeDef  TIM_ICInitStructure;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);  

  TIM_TimeBaseStructure.TIM_Period = 1000;
  TIM_TimeBaseStructure.TIM_Prescaler = 71;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);        

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;
  TIM_PWMIConfig(TIM1, &TIM_ICInitStructure);

  TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);
   
  TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);

  TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);

  TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);

  TIM_Cmd(TIM1, ENABLE);
}

void NVIC_Config()
{
  NVIC_InitTypeDef  NVIC_InitStructure;

  NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void TIM1_CC_IRQHandler(void)
{  
   TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);               
   IC2Value = TIM_GetCapture2(TIM1);
   if (IC2Value != 0)
  {
    DutyCycle = (TIM_GetCapture1(TIM1) * 100) / IC2Value;
    Frequency = 1000000 / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }
                                
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
亽亼
1楼-- · 2019-12-27 23:53
 精彩回答 2  元偷偷看……
雨丶轻尘
2楼-- · 2019-12-28 02:56
亽亼 发表于 2016-1-3 17:36
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);
不合适吧

那应该配置成什么样的      TIM_SelectInputTrigger(TIM1, TIM_TS_TI2FP2);     这样吗    貌似也不行呀
suebillt
3楼-- · 2019-12-28 06:12
http://www.amobbs.com/thread-5640468-1-1.html
我做的看看对你有没有帮助,ed?上升或者下降沿
蜗牛蜗牛
4楼-- · 2019-12-28 09:30
同样的问题你解决了没有?

一周热门 更多>