AnsweredAssumed Answered

FreeCntr - I don't understand the period parameter

Question asked by ROBERT PALMER on Feb 22, 2008
Latest reply on Feb 25, 2008 by Processor Expert
Hello,

I am running on a MC9S12C64 at 8Mhz.

I am trying to use a FreeCntr and am having trouble with a couple of items.  First is the "period" parameter in the configuration.  What does it mean?  If i go into the timer configuration, I can manually set the prescaler, which will change how fast the timer counts and therefore, how quickly it overflows.  I have verified this with a scope - if I set the prescaler to 1, the overflow interrupt will occur every 16.384ms.  If I set the prescaler to 2, the overflow interrupt will occur every 32.768ms.  But what is the "period" parameter for - what does it do, why/how do I use it? 

Also once the interrupt is triggered, is there a way to tell if the interrupt is due to a Compare or an Overflow?

What I am attempting to do is use the freeCntr and the Compare function.  I know that my compare interval is always less than the overflow time (e.g. if prescaler is 1, I know the compare interval is always less than 16.3ms).  This allows me to let the compare wrap around when I do the addition:

short val;
GetCounterValue(&val);
compareVal = val + compareInterval;
SetCompare(compareVal);

here, I KNOW that the sum of val and compareInterval might overflow, but that is OK, the total time is still accurate: i.e.,  the interval from 16383 to 9 is 10us, just as the interval from 0 to 10 is 10us, it just so happens that in the former, there was a counter overflow.

The problem is, in the interrupt service routine, how do I ignore the counter overflow interrupt and only handle the Compare interrupt.

Outcomes