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.
{ TimerInit(1000); unsigned long start = 0; unsigned long end = 0; int k = 0; start = TimerValueGet(TIMER1_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); while(k < 300000) { k++; } end = TimerValueGet(TIMER1_BASE, TIMER_A); TimerDisable(TIMER1_BASE, TIMER_A); end = (end - start) / 60000; } void TimerIntHandler(void) { //Clear the timer interrupt. TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); } void TimerInit(unsigned long timeInterval) { TimerCnt = 0; HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5; SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); IntMasterEnable(); TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_OS); TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 1000 * timeInterval); IntEnable(INT_TIMER1A); TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); IntRegister(INT_TIMER1A, TimerIntHandler); } This is the code I try to get the time consume of the while loop. The breakpoint is set on the last line. I set the M3 core clock in 60MHz, and the ‘end’ finally was 480. It means the while loop takes about 480ms. The loop takes seven assemble instructions showed in disassembly windows. In theory it should only takes 7 * 300,000 / 60M ~= 0.035(in sec), which is nearly one tenth of actually. I increased the loop times from the 300,000 to 30,000,000, (set the parameters timeInterval larger in case entering into the interrupt when time out) the result is 48359ms, which is nearly the same as the actual time lapse of the computer system time. Based on above, I suppose the timer gave the right value. But I don’t know why the loop takes so long time? PS: Why there is no line feed after I post my question?