Calculate time.
2006-03-14 by teddyroskvist
How do i calculate the time?
I have the example you can see herunder.
In the interrupt routine the TOMR0 is set to 149999 because it
should be 10mSec.
But how do i calculate the number? if i need a another time.
-------------------------------------------------------------------
void tc0 (void) __irq
{
T0MR0 = 149999; // 10mSec = 150.000-1 counts
T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
if ((IO1SET & 0xff000000) == 0xFF000000)
IO1CLR = 0xFF000000;
else
IO1SET = 0xFF000000;
}
/* Setup the Timer Counter 0 Interrupt */
void init_timer (void)
{
T0MR0 = 149999; // 10mSec = 150.000-1 counts
T0MCR = 3; // Interrupt and Reset on MR0
T0TCR = 1; // Timer0 Enable
VICVectAddr0 = (unsigned long)tc0;// set interrupt vector in 0
VICVectCntl0 = 0x20 | 4; // use it for Timer 0 Interrupt
VICIntEnable = 0x00000010; // Enable Timer0 Interrupt
}
int main (void)
{
unsigned int i;
IO1DIR = 0xFFff0000;
init_timer();
while(1)
{
IO1SET = 0x00FFffff;
for (i = 0 ; i < 1000000 ; i++ ){}
IO1CLR = 0x00FFffff;
for (i = 0 ; i < 1000000 ; i++ ){}
};
return 0;
}