单片小菜 发表于 2021-8-3 12:00

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


/******************************************************************************/
/*            AT32F4xx Peripherals Interrupt Handlers                        */
/******************************************************************************/
/**
* @briefThis function handles TMR3 global interrupt request.
* @paramNone
* @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

你确定采样率没问题?
页: [1]
查看完整版本: 为什么我的采样频率达不到0.1HZ?