delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/31/12:15:06

Message-ID: <F77915E7F086D31197F4009027CC81C921A6A0@probe-2.as-london.acclaim.com>
From: Shawn Hargreaves <SHargreaves AT acclaimstudios DOT co DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: I need to advice on timing...
Date: Mon, 31 Jan 2000 14:43:22 -0000
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii writes:
>> I now need a 10, and a 50 MICROSECOND signal and I'm not 
>> sure if I can.... IS it possible?
>
> You could read the timer counter (it runs at sub-1 microsecond
> resolution).
>
> If that isn't good enough, I think your best bet would be to find a
> loop that takes 50 microseconds to execute, and use that loop when 
> you need to toggle that bit.

The Linux kernel handles this rather well IMHO (many hardware drivers
require support for extremely short time delays). It uses a simple
delay loop that is calibrated at startup (giving a basically arbitrary
measurement called Bogomips), after which any other code can repeat
this same loop, using the Bogomips value to adjust for exactly how long
it will take. A fairly simple concept, but the actual delay loop has
to be written quite carefully to make it perform as consistently as
possible, hence the forced jump instructions at the start (of course 
it can never be 100% precise). The Linux delay loop, from 
arch/i386/lib/delay.c, is:

	void __delay(unsigned long loops)
	{
	        int d0;
	        __asm__ __volatile__(
	                "\tjmp 1f\n"
	                ".align 16\n"
	                "1:\tjmp 2f\n"
	                ".align 16\n"
	                "2:\tdecl %0\n\tjns 2b"
	                :"=&a" (d0)
	                :"0" (loops));
	}

The calibration measurements are doine in init/main.c, but would 
probably need rewriting to work on DOS.

Alternatively if you are willing to restrict yourself to a Pentium
or better CPU, the RTDSC instruction can be used to read a timing
count directly from the processor. This is dependent on the clock
speed, though, so would again need to be calibrated before use.


	Shawn Hargreaves.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019