This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer0 precision in the LPC2103

Hi,
I want to generate a very precise timing using Timer0 on the LPC2103, so I configure it with a MATCH resgister to generate a precisely an Interrupt each 1s(could be 1ms or 10ms), so here is a code that I wrote:

//----------------------------------------------------------------
#include<lpc2103.h>

void Timer0_IRQ_Handler(void) __irq{
IOPIN ^= 0x00000200;    // Toggle LED (BREAKPOINT HERE)

T0IR |= 0x00000001;     // clear Timer0 Match Inerrupt flag
T0TCR = 0x00000001;     // restart Timer0 after Int Execution

VICVectAddr = 0x00000000;
}


int main(void){
// GPIO Config
IODIR = 0x00000200;

// Timer0 config
T0TCR = 0x00000002;     // reset Timer0
T0PR  = 0x00000000;     // Clear prescaler
T0MCR = 0x00000007;     // Intterupt and Reset on MATCH 0 and STOP
T0MR0 = 0x03840000;     // Match  every 1s (1/f=3*19.6608MHz)
T0TCR = 0x00000001;     // start Timer0

VICVectCntl0 =0x00000024;
VICIntEnable= 0x00000010;
VICVectAddr0= (unsigned)Timer0_IRQ_Handler;
        while(1){
        }
}
//----------------------------------------------------------------

PCLK = masterclock =19.6608MHz*3 =58.982400 MHz

So with the configuration T0MR0 = 0x03840000; I get in the simulator the Timming = 1.00002177s at the 1st instruction inside the Int handler means 21.77 uS(probably the duration of istruction generated by the compiler to handle correctly the interruption)

Than I tried to compensation of this timing and I chaged the Match0 config register to:

T0MR0 = 0x0383FAFA; So I got :
T=1.00000003s means about 30nS of errors.

My problem is when I run again the simulator anothertime I got
T=1.99997886 instead of 2.00000006 and next time T=2.99995768 ans so on ..

any one have an idea why I got these troubles and how I can really generate a real precise timing or perhaps it's a simulator problem (keil realview/uVison).
I used the Fast Interrupt instead vectored ones, same things..

Thanks

0