硬件平台:MSP430F6723(80个引脚的)
代码如下:
#define TICKS_PER_SEC 1000u
#define SMCLK_CLK 8000000L
#define TIM_CAP_BASE TA3_BASE //TA3_BASE
#define TIM_CAP_CCR_REG_X TIMER_A_CAPTURECOMPARE_REGISTER_1
#define TIM_CAP_GPIO_PORT GPIO_PORT_P3
#define TIM_CAP_PIN GPIO_PIN2
void TIM_CapConfig(void)
{
GPIO_setAsPeripheralModuleFunctionInputPin( TIM_CAP_GPIO_PORT, TIM_CAP_PIN ); TIMER_A_configureContinuousMode( TIM_CAP_BASE, TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK, TIMER_A_CLOCKSOURCE_DIVIDER_1, TIMER_A_TAIE_INTERRUPT_ENABLE, TIMER_A_DO_CLEAR ); TIMER_A_clearTimerInterruptFlag(TIM_CAP_BASE);
TIMER_A_enableInterrupt(TIM_CAP_BASE);
TIMER_A_startCounter(TIM_CAP_BASE,TIMER_A_CONTINUOUS_MODE);
}
timCnt++;
if(timCnt == 15 * TICKS_PER_SEC)
{ timCnt = 0;
//capVal = TIMER_A_getCounterValue(TIM_CAP_BASE);
capVal = HWREG16(TIM_CAP_BASE + OFS_TAxR);
HWREG16(TIM_CAP_BASE + OFS_TAxR) = 0;
}
else
{
return;
}