打印

WPM 输入捕获问题,本人理解是否有误,请大家指点

[复制链接]
1759|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lanseshuijing|  楼主 | 2013-9-7 22:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/* TIM4 configuration: PWM Input mode ------------------------
     The external signal is connected to TIM4 CH2 pin (PB.07), //选择ch2口输入
     The Rising edge is used as active edge,
     The TIM4 CCR2 is used to compute the frequency value //捕获周期
     The TIM4 CCR1 is used to compute the duty cycle value//捕获占空比
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿捕获,  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//设置端口ch1 ch2 ch3 ch4分别对应寄
                                                                                                    //存器      ccr1 ccr2 ccr3 ccr4
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿捕获ch2通道对应寄存器ccr2 捕获上升沿的值,所以另一个ccr1对应就是下降沿捕获,如果对应寄存器配置相反的话捕获关系就相反了?我这样理解正确吗
沙发
airwill| | 2013-9-8 07:42 | 只看该作者
由于用主从模式, 一个捕获周期, 一个捕获高电平(低电平)时间.

使用特权

评论回复
板凳
lanseshuijing|  楼主 | 2013-9-8 08:59 | 只看该作者
airwill 发表于 2013-9-8 07:42
由于用主从模式, 一个捕获周期, 一个捕获高电平(低电平)时间.

怎样确定哪个一个寄存器捕获 周期 哪一个捕获高低电平?

使用特权

评论回复
地板
lanseshuijing|  楼主 | 2013-9-8 10:11 | 只看该作者
我已经找到问题答案了,其实这些操作都在配置函数里体现了如果你参数里选择了T1 作为输入,同样也在里面设置了TI2与他相反的设置 代码如下:
void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
{
  uint16_t icoppositepolarity = TIM_ICPolarity_Rising;
  uint16_t icoppositeselection = TIM_ICSelection_DirectTI;

  /* Check the parameters */
  assert_param(IS_TIM_LIST2_PERIPH(TIMx));

  /* Select the Opposite Input Polarity */
  if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)
  {
    icoppositepolarity = TIM_ICPolarity_Falling;
  }
  else
  {
    icoppositepolarity = TIM_ICPolarity_Rising;
  }
  /* Select the Opposite Input */
  if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)
  {
    icoppositeselection = TIM_ICSelection_IndirectTI;
  }
  else
  {
    icoppositeselection = TIM_ICSelection_DirectTI;
  }
  if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
               TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    /* TI2 Configuration */
    TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  }
  else
  {
    /* TI2 Configuration */
    TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
               TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    /* TI1 Configuration */
    TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  }
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

93

主题

749

帖子

4

粉丝