Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
void TimerWait(int ticks)
{
//Vars
int WaitTime = Timer + ticks;
//Kijk of we niet te ver gaan
if (WaitTime >= 1000)
{
WaitTime -= 1000;
}
//Wait
while (Timer < WaitTime);
}
I dont know why it hangs its just so n00b but can anybody tell me why?[/code]
Tjaalie wrote:I dont know why it hangs its just so n00b but can anybody tell me why?
It probably hangs because of that loop at the end. The code you gave us does not contain anything that causes that loop to end. What is Time? Is it a global variable updated on an interrupt?
Last edited by rexlunae on Mon Mar 21, 2005 12:00 am, edited 1 time in total.
So can you tell me whats wrong with the loop?
The i know the HanleTimer function get called cause when i put an print function in it it prints the text many times so its works. What do i do wrong?
Anton wrote:Do you have optimization turned on? If you do turn it off.
Also make the variable Timer volatile
All that should be necessary is declaring it volatile. Turning off optimizations should not be necessary. I wonder what the interrupt flag is set to when he enters the loop though. If it is not allowing interrupts, the Timer variable won't get changed.
Tjaalie wrote:thanx i only had to volatile it but what does
volatile do. can any body explain that why its working
now and not without it?
"volatile" effectively tells the compiler that the memory location may be changed without the compiler's knowledge, so it won't try to use a cached value in a register but instead always retrieve it from memory.
That Timer function is far from being reliable. Lets say you have a 1mhz CPU and another one with 2 billion teraflops....(OK i'm exagerating)... Which one will go out of the loop first?...
I recommend to rely on IRQ 0 , I believe it's the only reliable timer you have on a x86 system.