Problem reading cascaded timer values.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem reading cascaded timer values.

862 Views
Summer07
Contributor I
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
}
Labels (1)
0 Kudos
1 Reply

343 Views
Summer07
Contributor I
Let me answer my own post....

I had to load the compare registers for C0 with max count. Refer to the paragraph 16.4.1 (specifically the third paragraph of 16.4.1) of the User's Manual:

TMRC0_CMP1 = (unsigned)0xFFFF;
TMRC0_CMPLD1 = (unsigned)0xFFFF;

And all is well...
0 Kudos