home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 262.lha / ciatimer / README < prev    next >
Text File  |  1989-07-02  |  4KB  |  92 lines

  1. Second Release of Amiga microsecond-resolution realtime timing routines (0.1)
  2. -----------------------------------------------------------------------------
  3.  
  4.     By providing a solid, high-accuracy realtime clock, this code
  5.     provides a way for timer-releated code that needs to run at
  6.     specific realtimes, like a SMUS player, MIDI sequencer, etc,
  7.     to compensate for delays in their execution caused by interrupts,
  8.     cycle stealing by the blitter, etc.
  9.  
  10.     What you do is keep track of when in realtime you next want to 
  11.     run (by adding time intervals to a time returned by ElapsedTime
  12.     when you start, then when you're ready to set up your timer.device
  13.     MICROHZ delay timer, call ElapsedTime and calculate the difference 
  14.     in seconds and microseconds as your arguments for your timer.device
  15.     request.
  16.  
  17.     The routine ElapsedTime gets the time by getting the number of
  18.     55873 microsecond ticks that the handler has seen and retrieving
  19.     the 0-40000 number of 1.396825 microsecond tisks from the CIA timer
  20.     registers, scaling them to 1.000 microsecond ticks and returning
  21.     the shifted-and-or'ed result.
  22.  
  23.     By using the CIA timer in "continuous" mode, delays in the execution
  24.     of various routines don't impact the elapsed time timer we maintain.
  25.  
  26.     Note that what we really want is an improved timer.device where a
  27.     flag in the timer request could say  "schedule me at this microsecond-
  28.     resolution time of day seconds and microseconds" instead of only
  29.     "schedule me in this many seconds and microseconds."
  30.  
  31.     When the CIA interrupt handler is installed, other tasks need a
  32.     way to get the count maintained by the timer routine, too.
  33.  
  34.     This release of the code supports multiple readers:
  35.  
  36.     There is a sample main routine at the end of this program, run the
  37.     program in a window to start this guy as a timer.  Control-C within
  38.     the window to get it to exit.
  39.  
  40.     Run the ciafinder program from the CLI in another window and it will
  41.     locate the interrupt data for the timer interrupt maintained by the
  42.     ciatimer task and give you the elapsed time for your time calculation
  43.     in this way.
  44.  
  45.     At the end of the ciafinder program are a couple of routines, commented
  46.     out, that I use inside my SMUS player to determine the next time I want
  47.     to run in realtime, using the elapsed timer timer to calculate the
  48.     delay time for the call to the timer device -- this factors out any
  49.     delays caused by interrupts, DMA cycle stealing, and other delays in
  50.     the execution of the routine needing to run at precise intervals.
  51.  
  52.  
  53. Revisions
  54. ---------
  55.  
  56. Robert R. Burns (kodiak@amiga.UUCP) pointed out that the hardware manual
  57. is incorrect with respect to CIA usage.  Here is the correct usage he
  58. provided:
  59.  
  60.     CIAA (int 2)
  61.     timerA      keyboard handshake
  62.     timerB      uSec timer.device
  63.     TOD         60Hz timer.device
  64.     CIAB (int 6)
  65.     timerA      Commodore serial communication, usually not used
  66.     timerB      not used
  67.     TOD         graphics.library beam counter
  68.  
  69. ciatimer now uses CIAB, timer B
  70.  
  71. Brian P. Dickson (bpd@dretor.dciem.dnd.ca) identified a problem whereby
  72. the number I was using for the length of a tick, 1.397 microseconds,
  73. is actually 1.396825 microseconds.  
  74.  
  75. Although the difference between the two values is less than two nanoseconds,
  76. this error is accumulated every microsecond, causing the timer to run about
  77. 1.7 milliseconds behind per second, or 0.17%, not much, but it's fixable
  78. so I adopted his changes which were to change the time ratio from
  79. 46911 timer ticks producing 65536 microseconds to 40000 timer ticks producing
  80. 55873 microseconds.
  81.  
  82. C. Harald Koch (chk@dretor.dciem.dnd.ca, utzoo!dciem!dretor!chk)
  83. reported a bug where a flag used for interrupt control registers
  84. was accidentally used for CIA timer control which happened to
  85. work with timer A and fail with timer B.  The fix is to use the
  86. correct flag, CIACRAF_START.
  87.  
  88.  
  89. Regards,
  90. Karl Lehenbauer @ The Hacker's Haven, Missouri City, Texas
  91. (Internet: karl@sugar.hackercorp.com, Usenet: uunet!sugar!karl, BIX: kelehen)
  92.