This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F6723使用3K(或其他频率)的方波作为Timer的时钟源时,每隔1s(15s)读取TAxR的值来计算频率,计算的结果总比真实值少0.5%

Other Parts Discussed in Thread: MSP430F6723

硬件平台: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;  

 }