From: Martin Gangkofer <mgangkof@esg-gmbh.de>
Subject: Re: Using "delay until" in real-time
Date: Wed, 20 Dec 2000 08:59:31 +0100
Date: 2000-12-20T08:59:31+01:00 [thread overview]
Message-ID: <3A4066E3.6811305B@esg-gmbh.de> (raw)
In-Reply-To: 91p98c$49d$1@nnrp1.deja.com
Ted Dennison schrieb:
> In article <3A3F133E.4C13077C@esg-gmbh.de>,
> Martin Gangkofer <mgangkof@esg-gmbh.de> wrote:
>
> > translate into English like this: "Between the blind, the one-eyed is
> > the king". Well closing one eye I see a solution for your problem ..
>
> I've heard it in English as "In the land of the blind, the one-eyed man
> is king."
>
> (
> > Use integer arithmetics, which is 100% accurate to calculate next
> > time:
> > NextTime = StartTime + ( 1/f ) * n = StartTime + ( n * dx ) /
> > dy;
>
> Something pretty much like that has been suggested. My problem with it
> is that "n" is a counter that has to be monotonically increasing. That
> means that it will eventually hit an archetectural limit. Of course on
> my 32-bit machine at 240Hz that limit won't happen until the machine has
> been running for about 1/3 of a year, but the limit is there.
The solution is to increment the start time:
task body executive is
function "+"( L : Ada.Real_Time.Time; R : Ada.Real_Time.Time_Span )
return Ada.Real_Time.Time renames Ada.Real_Time."+";
Period_Enumerator : constant Some_Integer_Type := 1;
Period_Denominator : constant Some_Integer_Type := 60;
Limit : constant Some_Integer_Type := Some_Integer_Type'Last;
Start_Time : Ada.Real_Time.Time;
Next_Time : Ada.Real_Time.Time;
Cycles_Counter : Some_Integer_Type := 0;
function Increment( Step : in Some_Integer_Type ) return
Ada.Real_Time.Time_Span is
use Ada.Real_Time;
-- use float type to avoid constraint error due to "*"
-- single precision float should be sufficient, error is O( 1/10 )
usec
-- if you need higher precision scheduling (???) take long float
Val : constant Float := Float( Period_Enumerator * Step )
/ Float( Period_Denominator);
begin
return To_Time_Span( Duration( Val ) );
end Increment;
begin
-- startup initialisation, sync, etc.
Start_Time := Ada.Real_Time.Clock;
loop
if ( Cycles_Counter < Limit ) then
Cycles_Counter := Cycles_Counter + 1;
else
Cycles_Counter := 0;
Start_Time := Start_Time + Increment( Limit );
end if;
-- do_your_job;
Next_Time := Start_Time + Increment( Cycles_Counter );
delay until Next_Time;
end loop;
end Executive;
I did'nt compile it, but it should work.
Martin Gangkofer
next prev parent reply other threads:[~2000-12-20 7:59 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-12 16:27 Using "delay until" in real-time Ted Dennison
2000-12-12 18:01 ` Mike Silva
2000-12-12 19:57 ` Ted Dennison
2000-12-12 23:02 ` Mike Silva
2000-12-12 23:49 ` Ted Dennison
2000-12-18 6:26 ` Ray Blaak
2000-12-12 20:00 ` Ken Garlington
2000-12-12 20:40 ` Ted Dennison
2000-12-13 4:02 ` Ken Garlington
2000-12-13 14:29 ` Ted Dennison
2000-12-13 16:53 ` Larry Hazel
2000-12-13 17:41 ` Ted Dennison
2000-12-12 20:22 ` Keith Thompson
2000-12-12 20:54 ` Ted Dennison
2000-12-13 5:35 ` tmoran
2000-12-12 20:23 ` David C. Hoos, Sr.
2000-12-12 21:58 ` Ted Dennison
2000-12-12 23:18 ` Jeff Carter
2000-12-12 21:18 ` JP Thornley
2000-12-12 22:31 ` Ted Dennison
2000-12-13 8:02 ` Brian Orpin
2000-12-13 17:32 ` JP Thornley
2000-12-12 23:09 ` Ted Dennison
2000-12-13 7:43 ` Brian Orpin
2000-12-15 0:27 ` Frank
2000-12-19 7:50 ` Martin Gangkofer
2000-12-20 3:32 ` Ted Dennison
2000-12-20 5:29 ` tmoran
2000-12-20 7:59 ` Martin Gangkofer [this message]
2000-12-20 9:15 ` java servlets JF Harrison
2000-12-20 12:50 ` Using "delay until" in real-time Marin David Condic
2000-12-21 0:08 ` Alejandro R. Mosteo
2000-12-20 3:17 ` Ted Dennison
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox