comp.lang.ada
 help / color / mirror / Atom feed
* need ada timer routine
@ 2001-09-04 15:18 mop
  2001-09-04 20:03 ` James Rogers
  2001-09-04 20:24 ` Ted Dennison
  0 siblings, 2 replies; 4+ messages in thread
From: mop @ 2001-09-04 15:18 UTC (permalink / raw)




i need a routine to pass serial data at a 20 hertz rate

For my Visual C I did "m_timer = SetTimer(1, 50, NULL);"  This now calls a
built in API OnTimer(UINT nIDEvent) every 50 millisec.   Need something like
this in Ada.





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

* Re: need ada timer routine
  2001-09-04 15:18 need ada timer routine mop
@ 2001-09-04 20:03 ` James Rogers
  2001-09-04 21:51   ` tmoran
  2001-09-04 20:24 ` Ted Dennison
  1 sibling, 1 reply; 4+ messages in thread
From: James Rogers @ 2001-09-04 20:03 UTC (permalink / raw)


Is your C routine a background process? If not you are likely to
encounter a gradual loop skew as the timer must wait for the called
function to complete.

If you want to reliably send data every 50 milliseconds you want
to use a task with a "delay until" statement in a loop.

The following example comes right out of the Ada Language Reference
Manual.

In your case the identifier "Period" would be defined as:

Period : constant Duration := 0.050;

declare
       use Ada.Calendar;
       Next_Time : Time := Clock + Period;
                          -- Period is a global constant of type
Duration
    begin
       loop               -- repeated every Period seconds
          delay until Next_Time;
          ... -- perform some actions
          Next_Time := Next_Time + Period;
       end loop;
    end;

Jim Rogers
Colorado Springs, Colorado USA

mop wrote:
> 
> i need a routine to pass serial data at a 20 hertz rate
> 
> For my Visual C I did "m_timer = SetTimer(1, 50, NULL);"  This now calls a
> built in API OnTimer(UINT nIDEvent) every 50 millisec.   Need something like
> this in Ada.



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

* Re: need ada timer routine
  2001-09-04 15:18 need ada timer routine mop
  2001-09-04 20:03 ` James Rogers
@ 2001-09-04 20:24 ` Ted Dennison
  1 sibling, 0 replies; 4+ messages in thread
From: Ted Dennison @ 2001-09-04 20:24 UTC (permalink / raw)


In article <9n2rbg$4qj$1@zeus.orl.lmco.com>, mop says...
>i need a routine to pass serial data at a 20 hertz rate
>
>For my Visual C I did "m_timer = SetTimer(1, 50, NULL);"  This now calls a
>built in API OnTimer(UINT nIDEvent) every 50 millisec.   Need something like
>this in Ada.

The Right Way to do this kind of thing in Ada is to create a task that gets the
time, then repeatedly adds 50 ms to it and does a "delay until" on the result.

Out of curiosity, is this for a class at UCF? I got my master's from there, but
they didn't do a lot of Ada at the time. I tried to convince one prof to move
his OS course from concurrent C to Ada (the only platform Concurrent C supported
was an obsolete SunOS box kept for just that purpose), but I don't think I had
much success.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: need ada timer routine
  2001-09-04 20:03 ` James Rogers
@ 2001-09-04 21:51   ` tmoran
  0 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 2001-09-04 21:51 UTC (permalink / raw)


> If you want to reliably send data every 50 milliseconds you want
> to use a task with a "delay until" statement in a loop.
  Assuming of course that the OS and the compiler's RTS and the hardware
talk accurately about 50 ms.  For instance, in old DOS/Windows stuff the
clock only ticked every 55 ms so that was the shortest possible delay on
simpleminded systems. You might want to compile and run my "time the
clock" routine (www.adapower.com) on your system to see just what's what.
  If necessary, you can always get weird and do things like plaing a
50 ms sound file and depending essentially on the interrupt at the end
to wake your routine.

> > For my Visual C I did "m_timer = SetTimer(1, 50, NULL);"  This now calls a
> > built in API OnTimer(UINT nIDEvent) every 50 millisec.   Need something like
  The same thing of course applies here.  Just because a parameter is
specified as "milliseconds" doesn't necessarily mean the OS actually
pays attention.



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

end of thread, other threads:[~2001-09-04 21:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-04 15:18 need ada timer routine mop
2001-09-04 20:03 ` James Rogers
2001-09-04 21:51   ` tmoran
2001-09-04 20:24 ` Ted Dennison

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