[net.micro.amiga] Finally!! a millisecond timer

fdfishman@watcgl.UUCP (Flynn D. Fishman) (08/09/86)

Well after many long and grueling hours in front of my terminal and
over my Amiga Manuals, I am happy to announce that we have
finally gotten a 1 millisecond timer to work (yah!!!)

Since I know there is some interest in this, please bear with my
ramblings, but I hope by telling my story, millions like me may
not have to go through the anguish we did :-)

BACKGROUND

We have been trying to get a 1 millisecond grain timer for use
with the Amiga.  This timer is needed for perception experiments.

We have tried several things, such as using the System timers,
(but we could not get anything better than 16 milliseconds) or we
tried using the y-raster however, this caused quite a few
headaches.

We finally got a working timer using the 8520 timing chips

There are two 8520's in the Amiga, each with two timers.
  8520A-a is used for Serial Communications
  8520A-b is a Video beam follower, used for synchronising the
               Blitter to the Video beam
  8520B-a is used by the keyboard
  8520B-b is used continuously when Exec is in operation for task
               switching

It is than clear that the 8520B is clearly out as an option in
most cases (although on our case we could probably have gotten
away with it if we disabled the keyboard and multitasking. I am
open to suggestion on how to do the displaying and if this is
indeed feasible).
However, since we were definitely not doing any Serial
communications or blitter animation the 8520A was free for us.

The timers can be used in several different ways.  You can use
the timers as a one shot deal counting a set time period
or have it continuously count this time span.
Also, you can decide where the timer sends or receives its pulses
from.

In our code we directed Timer A to continuously count 1
millisecond and send its underflow pulses to Timer B which would
than increment, and would thusly be give the final result.

SOME COMMENTS

When you use TimerA beware that you can not use the disk drive,
since it also uses the TimerA for timing.  Therefore remember to
set the timer back.

When doing animation you can not use ChipA, but if you can do
with out the keyboard, and disable the Execs you could probably
use ChipB (comments anyone)

Something that could be noted as a hint, when doing accurate
timing on the Amiga, with graphics, the subject's perspective of
the object may vary depending on where the y-raster is when the
images is displayed.  This can be fixed by revealing the image(s)
at a constant y-raster time.  by waiting to the top of the frame
or just use the command WaitTOF();

I would like to thank, Richard D. Wright from the University of
Western Ontario, whose high * 256 in his paper, made me realize
that each register value was a char and not a SHORT. (p.s.. if you
read the values as a short the system crashes)

PLEASE: I would appreciate any comments on what is presented here
and on any other methods of timing.  Thanks very much

SOURCE.

Well they say a picture is worth a thousand words, so instead of
going into finate detail, I present you with the source code.

If there are any questions please feel free to ask me, and I will try to
elaborate.  Most of this information is in the Hardware Manual,
Appendix F.  And although hard to follow at times, with a working
code, it shouldn't be that bad.

-----------------------------------------------------------------------
gettimedelay(button)
SHORT *button;
  {
    unsigned char *timera_low, *timera_high, *control_registera;
    unsigned char *timerb_low, *timerb_high, *control_registerb;
    int timer b, high, low;


/*************************************************************
 *     Set all of the registers (?) to there memory location *
 *************************************************************/
   
    timera_low = 0xbfe401;
    timera_high= 0xbfe501;
    control_registera = 0xbfee01;

    timerb_low = 0xbfe601;
    timerb_high = 0xbfe701;
    control_registerb = 0xbfef01;

/* Set the control registers to allow for writes */

    *control_registera = 0x00;
    *control_registerb = 0x00;

/* Set timer a to count a millisecond */

    *timera_low = 0xcc;
    *timera_high = 0x02;

/* Set Timer b to zero */

    *timerb_low = 0xff;
    *timerb_high = 0xff;

/*****************************************************
 *     Turn on the timer                             *
 *****************************************************/

    *control_registerb = 0x41;
    *control_registera = 0x01;

/*
      .
      .
      .  do your stuff.
      .
*/

/* Turn the timer off and reset I/O  */

    *control_registera = 0x00;
    *control_registerb = 0x08;

  /***************************************************
   *        Get the time                             *
   ***************************************************/

    high = 256 - *timerb_high;
    low  = 256 - *timerb_low;

    timer b = (high << 8) + low;
    return(timer b);
}

This method although not Amigish, should not do any damage or
interfere with the multitasking of the machine, since you could
put a wait mouse for what ever at the part that says do your own
thing.
-- 

      FDFISHMAN (Flynn D. Fishman) @ WATCGL

UUCP  :	...!{decvax|ihnp4|clyde|allegra|utzoo}!watmath!watcgl!fdfishman   
ARPA  :	fdfishman%watcgl%waterloo.csnet@csnet-relay.arpa 
CSNET :	fdfishman%watcgl@waterloo.csnet
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This Cutsie saying space left intentionally left blank until such a time as
   1) The above mentioned user can think of a cutsie saying
   2) The above mentioned user with the aid of some friends can think of a 
      cutsie saying.
or 3) Sufficient time has passed such that plagerism of someone else's cutsie
      saying would not be noticed by many.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=