打印
[AT32F403/403A]

为什么我的采样频率达不到0.1HZ?

[复制链接]
1341|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
单片小菜|  楼主 | 2021-8-3 12:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

/******************************************************************************/
/*            AT32F4xx Peripherals Interrupt Handlers                        */
/******************************************************************************/
/**
  * @brief  This function handles TMR3 global interrupt request.
  * @param  None
  * @retval None
  */
void TMR3_GLOBAL_IRQHandler(void)
{
  if(TMR_GetINTStatus(TMR3, TMR_INT_CC2) == SET)
  {
    /* Clear TMR3 Capture compare interrupt pending bit */
    TMR_ClearITPendingBit(TMR3, TMR_INT_CC2);
    if(CaptureNumber == 0)
    {
      /* Get the Input Capture value */
      IC3ReadValue1 = TMR_GetCapture2(TMR3);
      CaptureNumber = 1;
    }
    else if(CaptureNumber == 1)
    {
      /* Get the Input Capture value */
      IC3ReadValue2 = TMR_GetCapture2(TMR3);
      
      /* Capture computation */
      if (IC3ReadValue2 > IC3ReadValue1)
      {
        Capture = (IC3ReadValue2 - IC3ReadValue1);
      }
      else
      {
        Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
      }
      /* Frequency computation */
      TMR3Freq =  SystemCoreClock /24000.0/ Capture;
      CaptureNumber = 0;
    }
  }
}
void rpm_init(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  
  /* Configure the GPIO ports */
  GPIO_Configuration();

        TMR_TimerBaseInitType TMR_TMReBaseStructure;
       
        /* TMRe base configuration */
  TMR_TimeBaseStructInit(&TMR_TMReBaseStructure);
  TMR_TMReBaseStructure.TMR_Period = 65535;
  TMR_TMReBaseStructure.TMR_DIV = 24000-1;
  TMR_TMReBaseStructure.TMR_ClockDivision = 0;
  TMR_TMReBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;

  TMR_TimeBaseInit(TMR3, &TMR_TMReBaseStructure);
  
  /* TMR3 configuration: Input Capture mode ---------------------
     The external signal is connected to TMR3 CH2 pin (PA.07)  
     The Rising edge is used as active edge,
     The TMR3 CCR2 is used to compute the frequency value
  ------------------------------------------------------------ */

  TMR_ICStructInit(&TMR_ICInitStructure);
  TMR_ICInitStructure.TMR_Channel = TMR_Channel_2;
  TMR_ICInitStructure.TMR_ICPolarity = TMR_ICPolarity_Rising;
  TMR_ICInitStructure.TMR_ICSelection = TMR_ICSelection_DirectTI;
  TMR_ICInitStructure.TMR_ICDIV = TMR_ICDIV_DIV1;
  TMR_ICInitStructure.TMR_ICFilter = 0x0;

  TMR_ICInit(TMR3, &TMR_ICInitStructure);
  
  /* TMR enable counter */
  TMR_Cmd(TMR3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TMR_INTConfig(TMR3, TMR_INT_CC2, ENABLE);


}


使用特权

评论回复
沙发
weifeng90| | 2021-8-4 07:52 | 只看该作者
你确定采样率没问题?

使用特权

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

本版积分规则

认证:资深专家
简介:丰富的嵌入式软硬件开发管理经验; 丰富的项目管理经验并具备敏锐的市场嗅觉; 丰富的产品的供应链资源及工厂管控能力; 具备很强的产品落地经验(从产品企划到产品量产);

107

主题

2307

帖子

9

粉丝