Delay

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.
Post Reply
Puh

Delay

Post by Puh »

How can i write a delay function?
carbonBased

RE:Delay

Post by carbonBased »

I would say, probably the best way, would be to utilize the timer interrupt or rtc.

Increment a counter by 1 on each tick, in the interrupt.  Your delay method can then grab the current value, and wait for a specific value knowing that, for example, this counter is going to increment 100 times in a second.

Cheers,
Jeff
knicos

RE:Delay

Post by knicos »

You could also create a loop of nop instructions.
All you need to do is lookup how many clock cycles the instruction(s) take and then find out the clock frequency of the cpu. Then simply loop as long as needed. This makes smaller delays than the interrupt ( 100ns ).
Ramanan

RE:Delay

Post by Ramanan »

Hi,
'in' or 'out' instruction cause one microsecond delay in any CPU (some where in the internet i red this). So use this in or out on a port 0x80 to delay. port 0x80 is safe and nothing will happen when u use these instructions on 2 it.
   Do 1000 IN (or OUT, any one) to get the 1 millisecond delay. Do 1000000 IN to get the i second delay.

rgds,
YogaRamanan.T
Robert Lee

RE:Delay

Post by Robert Lee »

You could also wait for the vertical retrace for reasonably long delays (1/60th of a second or longer). The ports to do this are standard on VGA. Look it up.
Post Reply