home *** CD-ROM | disk | FTP | other *** search
- Second Release of Amiga microsecond-resolution realtime timing routines (0.1)
- -----------------------------------------------------------------------------
-
- By providing a solid, high-accuracy realtime clock, this code
- provides a way for timer-releated code that needs to run at
- specific realtimes, like a SMUS player, MIDI sequencer, etc,
- to compensate for delays in their execution caused by interrupts,
- cycle stealing by the blitter, etc.
-
- What you do is keep track of when in realtime you next want to
- run (by adding time intervals to a time returned by ElapsedTime
- when you start, then when you're ready to set up your timer.device
- MICROHZ delay timer, call ElapsedTime and calculate the difference
- in seconds and microseconds as your arguments for your timer.device
- request.
-
- The routine ElapsedTime gets the time by getting the number of
- 55873 microsecond ticks that the handler has seen and retrieving
- the 0-40000 number of 1.396825 microsecond tisks from the CIA timer
- registers, scaling them to 1.000 microsecond ticks and returning
- the shifted-and-or'ed result.
-
- By using the CIA timer in "continuous" mode, delays in the execution
- of various routines don't impact the elapsed time timer we maintain.
-
- Note that what we really want is an improved timer.device where a
- flag in the timer request could say "schedule me at this microsecond-
- resolution time of day seconds and microseconds" instead of only
- "schedule me in this many seconds and microseconds."
-
- When the CIA interrupt handler is installed, other tasks need a
- way to get the count maintained by the timer routine, too.
-
- This release of the code supports multiple readers:
-
- There is a sample main routine at the end of this program, run the
- program in a window to start this guy as a timer. Control-C within
- the window to get it to exit.
-
- Run the ciafinder program from the CLI in another window and it will
- locate the interrupt data for the timer interrupt maintained by the
- ciatimer task and give you the elapsed time for your time calculation
- in this way.
-
- At the end of the ciafinder program are a couple of routines, commented
- out, that I use inside my SMUS player to determine the next time I want
- to run in realtime, using the elapsed timer timer to calculate the
- delay time for the call to the timer device -- this factors out any
- delays caused by interrupts, DMA cycle stealing, and other delays in
- the execution of the routine needing to run at precise intervals.
-
-
- Revisions
- ---------
-
- Robert R. Burns (kodiak@amiga.UUCP) pointed out that the hardware manual
- is incorrect with respect to CIA usage. Here is the correct usage he
- provided:
-
- CIAA (int 2)
- timerA keyboard handshake
- timerB uSec timer.device
- TOD 60Hz timer.device
- CIAB (int 6)
- timerA Commodore serial communication, usually not used
- timerB not used
- TOD graphics.library beam counter
-
- ciatimer now uses CIAB, timer B
-
- Brian P. Dickson (bpd@dretor.dciem.dnd.ca) identified a problem whereby
- the number I was using for the length of a tick, 1.397 microseconds,
- is actually 1.396825 microseconds.
-
- Although the difference between the two values is less than two nanoseconds,
- this error is accumulated every microsecond, causing the timer to run about
- 1.7 milliseconds behind per second, or 0.17%, not much, but it's fixable
- so I adopted his changes which were to change the time ratio from
- 46911 timer ticks producing 65536 microseconds to 40000 timer ticks producing
- 55873 microseconds.
-
- C. Harald Koch (chk@dretor.dciem.dnd.ca, utzoo!dciem!dretor!chk)
- reported a bug where a flag used for interrupt control registers
- was accidentally used for CIA timer control which happened to
- work with timer A and fail with timer B. The fix is to use the
- correct flag, CIACRAF_START.
-
-
- Regards,
- Karl Lehenbauer @ The Hacker's Haven, Missouri City, Texas
- (Internet: karl@sugar.hackercorp.com, Usenet: uunet!sugar!karl, BIX: kelehen)
-