[comp.sys.mac.programmer] TicksCount use Time Manager or VIA

ari@eleazar.dartmouth.edu (Ari Halberstadt) (06/12/91)

In article <1991Jun11.092513.14329@cs.uri.edu> reynhout@cs.uri.edu (Andrew Reynhout) writes:
>In article <5721@hemuli.tik.vtt.fi> aku@tik.vtt.fi (Arto Kujala) writes:
>>Is there a way to get more accurate time than function TickCount
>>gives?
>   Unfortunately, you'd need discrete hardware to do this.  The Mac gets its
>clock signals from the 60Hz AC input.  Of course, it would be very *simple*
>hardware...perhaps there is something out there.
>   Hmm.  In europe, where the freq of the AC is 50Hz, does TickCount() have a
>1/50sec resolution?

The old 60hz clock cycle was due to the vertical retrace during which
the electron gun in the CRT is reset. This period provides a window of
apparent inactivity (nothing is being drawn) during which simple interrupts,
such as incrementing the Ticks low memory global variable, can occur.
Notice that while the 60hz interrupt has been preserved for compatibility
with old software, it isn't necessarily tied to the video refresh rate.
This is important for animation which should be synchronized with the display
hardware; various techniques have been documented (I think) explaining
how to do this on screens with an alternate refresh rate such as 75hz.
There is no connection between the line frequency and the clock rate.
 
The CPU, in fact all clocked operations in a Macintosh, are driven
by a much more accurate oscillator. The original macs ran at a clock
frequency of ~7.8Mhz using the VIA timer chip. Newer macs use a different
method (not a VIA chip, I think) to achieve clock rates of up to 33Mhz.
The THINK C profiler includes code which accesses the VIA timer, so I assume
all macs retain access to the VIA timer to maintain compatability with
old software. This means that it is fairly straightforward to get resolutions
of ~1 microsecond.

The Time Manager provides an excellent interface to a clock with a resolution
of 1 microsecond. The Time Manager is documented in Inside Macintosh IV-VI.
Volume VI adds some very important functionality, so read it first. A simple
method to use the time manager would be to install a task to be executed
every N microseconds, where N is the desired resolution. Each time the
task is executed some variable is incremented, in a manner analogous to
the "Ticks" low memory global. Notice that IM-VI provides a facility to
adjust the delay till the next time the task is called, resulting in very
accurate timing. Time Manager tasks must be kept very simple since they
are called at interrupt time and should not call other operating system
routines (the mac's OS is not reentrant).

The Time Manager is pretty much guaranteed to be supported by Apple but the
same can not be said of the VIA chip.

d88-jwa@byse.nada.kth.se (Jon W{tte) (06/12/91)

> ari@eleazar.dartmouth.edu (Ari Halberstadt) writes:

   frequency of ~7.8Mhz using the VIA timer chip. Newer macs use a different
   method (not a VIA chip, I think) to achieve clock rates of up to 33Mhz.

   accurate timing. Time Manager tasks must be kept very simple since they
   are called at interrupt time and should not call other operating system
   routines (the mac's OS is not reentrant).

You also have to worry about the A5 world stuff - remember to have
your Time Manager task use the RIGHT A5 if you use globals. Better
yet, pass a pointer to the data to the interrupt routine.

--
						Jon W{tte
						h+@nada.kth.se
						- Speed !

d88-jwa@byse.nada.kth.se (Jon W{tte) (06/12/91)

> ari@eleazar.dartmouth.edu (Ari Halberstadt) writes:

   frequency of ~7.8Mhz using the VIA timer chip. Newer macs use a different
   method (not a VIA chip, I think) to achieve clock rates of up to 33Mhz.
								    ^^

Should read 40.

Yes, I LOVE picking nits, and I have _nothing_ better to do.


--
						Jon W{tte
						h+@nada.kth.se
						- Speed !