Mail Archives: djgpp/1999/08/15/11:42:13
On Sat, 14 Aug 1999, Simon Redwood wrote:
> I am new to using djgpp under dos, being a unix programmer. I am having
> trouble with delays.
>
> Can I rely on usleep to give me accurate timings.
>
> Giving usleep a value of 10000-12500 produces the same delay, whereas 13000
> gives the same as 20000, where I am going wrong.
This is all expected behavior: usleep has a 55-msec granularity. (This
is unfortunately not stressed in the docs; v2.03 fixes that.) The system
clock on the PC ticks 18.2 times a second, so this is what you get.
> I would like to put a delay into a loop of about 1/100 sec. how is the best
> way to acheive this
Write your own wait loop that calls uclock. This function has
840-nanosecond resolution.
> I am also looking to work with microprocessors where I will need accurate
> timings of nanoseconds, how can this be best acheived.
One way is to use the machine instruction that reads the counter register
of the Pentium and later CPUs.
- Raw text -