MC9S12DP256B Timer

Started by gregmaaha January 22, 2007
Using an MC9S12DP256B microcontroller, I am attempting to implement a
time delay, during which other processes will still be carried out. I
have a couple of questions regarding this topic:

1) Since TCNT only counts to a certaing value, I was wondering if: When
TCNT reaches its maximum value, is there another register that is
incremented to show that this is the case?

2) Does anyone have any sample code of a decrementing timer?

Any help or guidance that I could get on this subject would be greatly
appreciated. Thank you.
hi,

Most timer drivers don't care about the timer register rollover as long
as the period is less than the value of TCNT. If the periods are longer
than TCNT then you will care (select your timer prescale to prevent
this). My point is that if you set TC0 (for example) to be 0x4000
cycles, simply add 0x4000 to TC0 whenever it interrupts to maintain a
constant rate. Don't worry about any overflow because the addd
instruction will truncate to the value that you want when the timer
register wraps. Now just increment a global tick variable whenever TC0
interrupts to keep track of time passage. If you put a task handler
inside your timer ISR that matches this global count to an array of
timer objects you have the basis of a RTOS. I actually prefer using the
RTI when timing isn't critical because then no reload is required.

-rob

gregmaaha wrote:
> Using an MC9S12DP256B microcontroller, I am attempting to implement a
> time delay, during which other processes will still be carried out. I
> have a couple of questions regarding this topic:
>
> 1) Since TCNT only counts to a certaing value, I was wondering if: When
> TCNT reaches its maximum value, is there another register that is
> incremented to show that this is the case?
>
> 2) Does anyone have any sample code of a decrementing timer?
>
> Any help or guidance that I could get on this subject would be greatly
> appreciated. Thank you.