Board index » delphi » how to write delay procedure which will delay const short period under Win95

how to write delay procedure which will delay const short period under Win95

Hi folks,

I am writing a program to sample some data from I/O ports, therefore,I
need to call a delay procedure when I am sampling the data. The
following is the one I wrote.

But beecaue I am running the program under win95, I find that the delay
procedure won't delay a constant period, i.e. it will change everytimr
when I call it. (I know that is because the Win95 is a multitasking OS)

My problem is that is it possible to write a delay function that will
delay a constant short period during the time I am sampling data from
I/O port???

Any help is appriciated!!

Y.S. Huang

procedure Delay
var
 x:LongInt;
 Delay_Count:LongInt;
begin
 Delay_Count:=40;
 x:=0;
   for x:=0 to Delay_Count do
     begin
        For i:=0 to 1000 do
           asm nop; end;
     end;
end;

 

Re:how to write delay procedure which will delay const short period under Win95


Quote
??? wrote:

> Hi folks,

> I am writing a program to sample some data from I/O ports, therefore,I
> need to call a delay procedure when I am sampling the data. The
> following is the one I wrote.

> But beecaue I am running the program under win95, I find that the delay
> procedure won't delay a constant period, i.e. it will change everytimr
> when I call it. (I know that is because the Win95 is a multitasking OS)

> My problem is that is it possible to write a delay function that will
> delay a constant short period during the time I am sampling data from
> I/O port???

> Any help is appriciated!!

> Y.S. Huang

> procedure Delay
> var
>  x:LongInt;
>  Delay_Count:LongInt;
> begin
>  Delay_Count:=40;
>  x:=0;
>    for x:=0 to Delay_Count do
>      begin
>         For i:=0 to 1000 do
>            asm nop; end;
>      end;
> end;

By the way my email is

y...@pidc.gov.tw

Re:how to write delay procedure which will delay const short period under Win95


Quote
??? wrote:

> Hi folks,

> I am writing a program to sample some data from I/O ports, therefore,I
> need to call a delay procedure when I am sampling the data. The
> following is the one I wrote.

> But beecaue I am running the program under win95, I find that the delay
> procedure won't delay a constant period, i.e. it will change everytimr
> when I call it. (I know that is because the Win95 is a multitasking OS)

> My problem is that is it possible to write a delay function that will
> delay a constant short period during the time I am sampling data from
> I/O port???

> Any help is appriciated!!

> Y.S. Huang

> procedure Delay
> var
>  x:LongInt;
>  Delay_Count:LongInt;
> begin
>  Delay_Count:=40;
>  x:=0;
>    for x:=0 to Delay_Count do
>      begin
>         For i:=0 to 1000 do
>            asm nop; end;
>      end;
> end;

One more thing - try to find out if there's "sleep" in windows

Re:how to write delay procedure which will delay const short period under Win95


In <328ACB51.2...@pidc.gov.tw>, ??? <y...@pidc.gov.tw> writes:

Quote
>Hi folks,

>I am writing a program to sample some data from I/O ports, therefore,I
>need to call a delay procedure when I am sampling the data. The
>following is the one I wrote.

>But beecaue I am running the program under win95, I find that the delay
>procedure won't delay a constant period, i.e. it will change everytimr
>when I call it. (I know that is because the Win95 is a multitasking OS)

>My problem is that is it possible to write a delay function that will
>delay a constant short period during the time I am sampling data from
>I/O port???

>Any help is appriciated!!

>Y.S. Huang

>procedure Delay
>var
> x:LongInt;
> Delay_Count:LongInt;
>begin
> Delay_Count:=40;
> x:=0;
>   for x:=0 to Delay_Count do
>     begin
>        For i:=0 to 1000 do
>           asm nop; end;
>     end;
>end;

Hi,
Your problem seems to be quite similar to the mine. It seems you need a delay for
a very short time (nop at a pentium 100 needs 1 clock=10ns -> your loop needs about
10 microseconds). Probably the task switches of windows make your loop much
longer but not constant at all. One way (not the best) is to fix the speed of the
loop with the i/o-clock, this means 8MHz if you call an address corresponding to
the ISA-bus or 33MHz for an address of the PCI-bus. Your loop could be:
asm
         mov dx,$378
         mov cx, Time
  @M1: in al,dx
         out dx,al
         loop @M1
end;
It works not perfectly, but better than nops. If your update interval is bigger than
2ms than you may write a timer-interrupt procedure, which is definitively more
precise than sleep(2).
I have another idea, but perhaps you may try the above before, and contact me
by e-mail or this news-group.

Regards,
steffen

Re:how to write delay procedure which will delay const short period under Win95


A+n+a+, (is this your name ?)

i >I am writing a program to sample some data from I/O ports, therefore,I
i >need to call a delay procedure when I am sampling the data. The
i >following is the one I wrote.
i >
i >But beecaue I am running the program under win95, I find that the delay
i >procedure won't delay a constant period, i.e. it will change everytimr
i >when I call it. (I know that is because the Win95 is a multitasking OS)
i >
i >My problem is that is it possible to write a delay function that will
i >delay a constant short period during the time I am sampling data from
i >I/O port???
i >

    Well, if I were you I would use Window's API help to do that. I mean,
    depending on the length of your delay you should use a timer
    ( = TTimer = WM_TIMER message) to ensure that you'll hava a almost
    smoth time interval. Therefore, I'd use if my delay were greather than
    70 ms, and I'd use GetTickCount () to 'calculate' the amount of time
    that has come (instead of a sum of WM_TIMER * iTimeRequested).

    I hope this helps you and you don't get angry with my poor english.

    Inte,
    Chico.  <= = Don't forget I'm a proudy brazilian.

Other Threads