internal timer

M

Thread Starter

manmohan singh

hi everybody,

does anyone know how to use timers which are inbuilt in personal computers. what are the addresses? actually i know the range that from 0040H to 0043H are used by the timer but don't know what memory location is for what and how to use them. kindly help me in this matter.

thanks

manmohan singh
 
J

Johan Bengtsson

In what OS?
most modern operating systems won't be happy if you mess with the timer yourself (some won't even allow it)

For what purpose?
most modern operating systems let you get the time from the os, usually expressable as both YYYY-MM-DD-hh:mm:ss.ss (or equivalent) and in ms since system startup (expressed as a 32 bit integer that will wrap around after some 49 odd days or so)

If you want time of day you ask the os of that, if you want to measure time differences you ask for ms since start before and after the event
you want to measure and computes the difference (note the wrap around but if the code is carefully written it doesn't matter)

In C/C++ and windows (95 or later) this would be written as:

DWORD timeBefore,timeAfter,timeElapsed;

timeBefore=timeGetTime();
//the event you want to measure
timeAfter=timeGetTime();
timeElapsed=timeAfter-timeBefore;

If you want to wait for some time most modern OS have a Sleep(time) or equivalent function, the "problem" with that one is that you have no guarantee that it returns in exactly the specified time, but on the other hand don't you have any guarantees for that anyway if the os is
multitasking.


If you want to keep doing something until a certain time have elapsed you effectively use the above code:

DWORD timeBefore,timeAfter,timeElapsed;

timeBefore=timeGetTime();
do
{
//do one piece of your work

timeAfter=timeGetTime();
timeElapsed=timeAfter-timeBefore;
}
until (timeElapsed>1000);
//substitute 1000 for the amount of time you want to wait (in ms)

or the short version:

DWORD timeBefore,timeAfter,timeElapsed;

timeBefore=timeGetTime();
do
{
//do one piece of your work
}
until (timeGetTime()-timeBefore>1000);
//substitute 1000 for the amount of time you want to wait (in ms)



/Johan Bengtsson

----------------------------------------
P&L, Innovation in training
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
 
Top