Varun Karthick

Is it possible to create a delay in program only using TCNT timer

Discussion created by Varun Karthick on May 9, 2007
Latest reply on May 10, 2007 by Daniel Lundin
Hi all!!
 
I have tried to use the TCNT timer to create a delay in my program.
 
MCU : 9S12XDP512
Osc.Clock: 8MHz
Bus Clock : 40MHz
 
I called the below function to make a delay by adding the required delay value "ms" to the present TCNT and then compare the TCNT value until it reaches "tCNT".
 
The code works fine. But how can i know that the required delay has been achieved?
void Delay(UINT ms)
{
 tCNT = TCNT;
 tCNT += ms;
 while (tCNT != TCNT)
 ;
}
 
I could not see the free running TCNT register getting incremented in the True time simulator.
 
Any suggestions?
 
embedlov
 

Outcomes