comp.lang.ada
 help / color / mirror / Atom feed
* next_period = start + n*period; versus next_period = next_period+period;
@ 2004-10-26 16:20 Paul Colin Gloster
  2004-10-26 17:16 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Colin Gloster @ 2004-10-26 16:20 UTC (permalink / raw)


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;.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-10-28 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-26 16:20 next_period = start + n*period; versus next_period = next_period+period; Paul Colin Gloster
2004-10-26 17:16 ` Florian Weimer
2004-10-27  7:35   ` Dmitry A. Kazakov
2004-10-27 13:46     ` Mark H Johnson
2004-10-27 14:41       ` Dmitry A. Kazakov
2004-10-28 13:37         ` Mark H Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox