Mike Sheehan

Problem reading cascaded timer values.

Discussion created by Mike Sheehan on Oct 30, 2006
Latest reply on Nov 2, 2006 by Mike Sheehan
I'm using an MC68F8333. I have TMRC0 and TMRC1 set up using the CASCADED timing mode to get 32 bits of resolution. For the most part all appears to be working well but occasionally when I read TMRC0_CNTR register it's value is 0x0000 (going through rollover). And then I read TMRC1_HOLD, and it has not been incremented to account for TMRC0 rollover causing my delta time to be negative.

Here's an example of the error(values from debugger watch window):

requestedDuration = 0x00012012
startTime = 0x905F93B2
currentTime = 0x905F0000 -- TMRC0 = 0x0000, TMRC1 = 0x905F
timeTest = 0xFFFF6C4E (currentTime - startTime)


Thanks for any help you can give.
Here's my setup (it's a bit cryptic):

void initSysTime(void)
{
// stop both counters - TMRC0
TMRC0_CTRL = (unsigned) // Stop all functions
(0 13 | // CM - off
10 9 | // PCS - (IPBus / 4)
0 7 | // SCS
0 6 | // ONCE
0 5 | // LENGTH
0 4 | // DIR - up
0 3 | // Co INIT
0 0 | // OM - toggle OFLAG
0);

// and TMRC1
TMRC1_CTRL = (unsigned) // Stop all functions
(7 13 | // CM - Cascade to C0
4 9 | // PCS - get OFLAG from C0
0 7 | // SCS
0 6 | // ONCE
0 5 | // LENGTH
0 4 | // DIR
0 3 | // Co INIT
0 0 | // OM
0);


TMRC0_SCR = 0; // Reset Status Register
TMRC1_SCR = 0; // Reset Status Register
TMRC0_CNTR = 0; // Reset Counter
TMRC1_CNTR = 0; // Reset Counter
TMRC0_LOAD = 0; // Reset Load Register
TMRC1_LOAD = 0; // Reset Load Register
TMRC0_COMSCR = 0;
TMRC1_COMSCR = 0;

TMRC0_CTRL |= (unsigned) // Enable Counter
(1 13); // Count Rising Edges
}

Outcomes