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-Thread: 115aec,47cd14062de43094,start X-Google-Thread: 103376,47cd14062de43094,start X-Google-Attributes: gid115aec,gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!border2.nntp.ams.giganews.com!nntp.giganews.com!uio.no!uninett.no!news.net.uni-c.dk!newsfeed.sunet.se!news01.sunet.se!news.umu.se!not-for-mail From: Paul Colin Gloster Newsgroups: comp.realtime,comp.lang.ada Subject: next_period = start + n*period; versus next_period = next_period+period; Date: 26 Oct 2004 18:20:25 +0200 Organization: News UmU SE Sender: pauglo-04@ryp76.ryp.umu.se Message-ID: NNTP-Posting-Host: ryp76.ryp.umu.se Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: hudsucker.umdac.umu.se 1098807652 15549 130.239.11.76 (26 Oct 2004 16:20:52 GMT) X-Complaints-To: newsmaster@umu.se NNTP-Posting-Date: Tue, 26 Oct 2004 16:20:52 +0000 (UTC) Xref: g2news1.google.com comp.realtime:517 comp.lang.ada:5724 Date: 2004-10-26T18:20:25+02:00 List-Id: For cyclic processes, at least in Ada literature such as Section Two 9.3 of "Ada 95 Rationale: The Language, The Standard Libraries", WWW.AdaIC.org/standards/95rat/RAThtml/rat95-p2-9.html#3 and page 23 (Adobe Acrobat page 27) of Alan Burns, Brian Dobbing, Tullio Vardanega, "Guide for the use of the Ada Ravenscar Profile in high integrity systems., University of York Technical Report YCS-2003-348, January 2003, HTTP://WWW.CS.York.ac.UK/ftpdir/reports/YCS-2003-348.pdf which is the same as the reprint in "Ada Letters", June 2004, it is recommended to use relative timeouts based on addition for the periods such as: with System; --with is like #include with Ada.Real_Time; use type Ada.Real_Time.Time; package body Additionbased_Example is task type Cyclic(Pri : System.Priority; Cycle_Time : Positive) is pragma Priority(Pri); end Cyclic; task body Cyclic is Next_Period : Ada.Real_Time.Time; Period : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Microseconds(Cycle_Time); begin -- Initialization code Next_Period := Ada.Real_Time.Clock + Period; --Ada.Real_Time.Clock --returns the current time\. loop delay until Next_Period; -- wait one whole period before executing -- Non-suspending periodic response code -- ... Next_Period := Next_Period + Period; end loop; end Cyclic; end Additionbased_Example; however someone I am acquainted with swears by multiplication as in delay until Next_Period; where Next_Period := Start + Iteration*Period; instead, and demonstrated an example where it is more accurate. The following MATLAB excerpt illustrates this: ">> step=0.0001834567890123; >> next=0;, for k=1:1000000, next=next+step;, end; >> next next = 183.4568 >> step*1000000 ans = 183.4568 >> next-step*1000000 ans = 2.8158e-009 >> %I.e. non-zero." So, why do the documents referenced above use an approach more susceptible to rounding errors? The Ada 95 rationale examples were specifically given in the context of being more accurate than another approach (having the Ada 83 delay keyword and a relative time). David Brach's paper "User experiences with the Aonix ObjectAda RAVEN Ravenscar Profile implementation" in "Ada Letters" December 2002 (apparently a reprint from the proceedings of the 11th international workshop on Real-time Ada) has an alternative way of specifying the times but it is still addition-based and for the purposes of this discussion it seems to be equivalent to Next_Period := Ada.Real_Time.Clock + Period;.