comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: Using "delay until" in real-time
Date: 12 Dec 2000 12:22:46 -0800
Date: 2000-12-12T12:22:46-08:00	[thread overview]
Message-ID: <yec3dfttmnd.fsf@king.cts.com> (raw)
In-Reply-To: 915jl7$jt5$1@nnrp1.deja.com

Ted Dennison <dennison@telepath.com> writes:
[...]
> 1/60 works out to about 0.016(6-repeating). That can't be accurately
> represented in an IEEE floating-point register. So what we get is
> something like 0.016667 (forgive me if I'm rounding the wrong digit).

I think you're assuming that type Time is a floating-point type;
either that, or you're (inappropriately) using floating-point to store
time values.  It's more likely to be fixed-point.  If you're using
Gnat, Ada.Real_Time.Time and Ada.Real_Time.Time_Span are both derived
from Duration, which is a 64-bit fixed-point type with a Small of
exactly 1.0e-9 (one nanosecond).

The value 1.0/60.0 is still not exactly representable; it's going to
be either 0.166666666 or 0.166666667.

> That rouding error slowly accumulates over time, until after about 52
> seconds our poor Executive task skips a tick. On our system ticks come
> at 240Hz, so that means that once every 52 seconds the executive
> scheduler waits about 20ms instead of 16.6(6-repeating)ms. Of course
> this wreaks havoc in our hard-realtime system.
> 
> So the question is, what's the best way to solve this problem? Here's
> what we came up with so far:
> 
>   o  Use the RTOS' "taskDelay" function to delay the appropriate amount
> of ticks (4).
> 
> I don't like this one, as its a non-Ada solution, and thus renders our
> scheduler non-portable. Its also succeptable to drift if something
> causes an extra tick to pass before we get to the taskDelay.

Is the scheduler intended to be portable?  If the design of the
scheduler depends on the underlying 240Hz clock tick, perhaps you
should just bite the bullet and delay for 4 ticks.

> Since this problem should happen to anyone using "delay until" with an
> iteration rate divisible by 3, and 60, 30, and 15Hz are common rates in
> the industry, I can't be the first person to stumble on this problem.
> How does everyone else handle it?

If you're using Gnat, it will happen to anyone with an iteration rate
that's not a whole number of nanoseconds.  For other compilers, it may
happen with an iteration rate that's not a multiple of a power of 2.0,
depending on how the time types are implemented.  (In either case,
that includes iteration rates divisible by 3.)

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Welcome to the last year of the 20th century.



  parent reply	other threads:[~2000-12-12 20:22 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 [this message]
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
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