From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f8311a3a7edd715 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-19 23:59:35 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!do.de.uu.net!businessnews.de.uu.net!not-for-mail Message-ID: <3A4066E3.6811305B@esg-gmbh.de> Date: Wed, 20 Dec 2000 08:59:31 +0100 From: Martin Gangkofer Organization: ESG - Elektroniksystem- und Logistik- GmbH, Muenchen X-Mailer: Mozilla 4.7 [de] (WinNT; I) X-Accept-Language: de MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Using "delay until" in real-time References: <915jl7$jt5$1@nnrp1.deja.com> <3A3F133E.4C13077C@esg-gmbh.de> <91p98c$49d$1@nnrp1.deja.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 195.124.164.3 X-Trace: 977299174 businessnews.de.uu.net 24058 195.124.164.3 X-Complaints-To: abuse@de.uu.net Xref: supernews.google.com comp.lang.ada:3278 Date: 2000-12-20T08:59:31+01:00 List-Id: Ted Dennison schrieb: > In article <3A3F133E.4C13077C@esg-gmbh.de>, > Martin Gangkofer 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