用msp430 f2132芯片,想精确计时到ms级别。
结果测试时间误差很大,计时比实际实际多近1/10,另外还有一个问题,缺省smclk的时钟是1Mhz的吗?
代码如下:
void TimerAInit(void) {
TACTL=TASSEL_2+TACLR+MC_0+ID_0; //选择时钟源为SMCLK,
TACCTL0 = CCIE;
TACCR0=1000; TACTL |= MC_1;
msTime =0; sTime =0; } unsigned short getMsTime() { return msTime; } unsigned short getSTime() { return sTime; }
#pragma vector=TIMER0_A0_VECTOR __interrupt void Timer0Process(void) { msTime++; if(msTime ==1000) { sTime++; msTime=0; } }
main()
{
unsigned short msTmp =0; unsigned short sTmp =0;
WDTCTL = WDTPW + WDTHOLD; _BIS_SR(GIE); TimerAInit(); while(1) { deciMsTmp = getDeciMsTime(); msTmp = getMsTime(); sTmp = getSTime(); };
}
[ 本帖最后由 desertriver 于 2010-11-4 16:02 编辑 ]
|