🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #10810

Re: Timer question

#10810
From: Karl Lehenbauer
Date: Wed, 04 Jan 1989 11:45
37 lines
2540 bytes
I have written code based on Paul Higginbottom's code published in Amiga mail
that uses one of the CIA timers to provide a microsecond-resolution realtime
clock.  What it does is install an interrupt handler that counts the number
of clicks, then it loads in a certain number, I think it's about 47000, and
runs the CIA in continuous mode.  This represents 65536 microseconds (counter 
ticks are 1.397 microseconds).  Anyway, you call this routine, currently 
called ElapsedTime and it returns the elapsed seconds and microseconds since the
interrupt handler was started.  How ElapsedTime works is it reads the counter
registers from the CIA, scales the value up to microseconds, factoring in the 
number of ticks counted by the interrupt routine and returns, as I said, seconds
and microseonds.

I use this in my SMUS player to provide a stable clock.  When I start the song,
I read the elapsed realtime in seconds and microseconds.  Then, each time
I calculate how many microseconds until the next event, I add that to my
kept elapsed time.  That value now represents the realtime when I want the
event to go off.  I then read the current realtime and subtract it from the
calculated realtime of the next event, and I now have arguments for a call to
timer.device that have taken into account time losses due to interrupt 
processing, blitter activity, context switching, etc, while I was running.  

It works.

But I think it needs to be a library, see, because I already have a couple
MIDI programs that need to make use of it.  I was thinking "library" because
it provides a way for tasks to locate the address of the long word that's
being incremented by the interrupt routine.

So I'd like a little feedback on this, and any notes on how to make it a 
library if that's the way to go.  

Email and I'll send you what I already have.  It's not very big.  If a lot
of people ask, I'll post.
-- 
-- uunet!sugar!karl  | "We've been following your progress with considerable 
-- karl@sugar.uu.net |  interest, not to say contempt."  -- Zaphod Beeblebrox IV
-- Usenet BBS (713) 438-5018
Technical Details
Message-ID: <3209@sugar.uu.net>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nuchat!sugar!karl
References: <427@tekn01.chalmers.se> <3210@amiga.UUCP> <3137@sugar.uu.net> <5584@cbmvax.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nuchat!sugar!karl
From: karl@sugar.uu.net (Karl Lehenbauer)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Timer question
Summary: microsecond resolution time of day timer
Message-ID: <3209@sugar.uu.net>
Date: 4 Jan 89 11:45:36 GMT
References: <427@tekn01.chalmers.se> <3210@amiga.UUCP> <3137@sugar.uu.net> <5584@cbmvax.UUCP>
Organization: Sugar Land Unix - Houston, TX
Lines: 37