/******************************************************************************/
/* 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);
}
|