AnsweredAssumed Answered

ADuC845 Timing Considerations

Question asked by jwanja on Mar 31, 2012
Latest reply on Apr 4, 2012 by MMA

I am having some timing issues when using Timer2 in autoreload mode. I am trying to get intercepts and flip a bit in exact increments of 1ms. My clock is running at the default, 1.572864 MHz. Here is my logic. And I'll provide my code underneath that.


Our clock is running at 635.7829ns, so in order to get a 1ms signal we need about 1572 pulses of the clock frequency. Since the ADuC845 is a standard 8052 microprocessor its Timers operate at the same frequency as the clock, so 1572 pulses = 1572 timer ticks.


66536 (for a full value of the timers) - 1572 = 64964 = 0xFDC4 as the starting value and overflow value of the clock so that only 1572 ticks will be processed before the interrupt.


My issue is that when I run my program I am getting an output square wave with a period of only 0.363668ms...NO WHERE even close to the 1ms range I calculated.


Any ideas on what gives? My code is provided below.


void interrupt (void) interrupt 5
     P0 ^= 0x01;
     TF2 = 0;

     //Enable Timer2 Overflows
     ET2 = 1;
     //Load starting and Overflow Values
     TL2 = 0xC4;
     TH2 = 0xFD;
     RCAP2L = 0xC4;
     RCAP2H = 0xFD;

     //Enable global interrupts
     EA = 1;

     //Configure and begin timer2
     T2CON = 0x04;

     while (1);