[net.micro.cbm] Flaky TOD Alarm Interrupts

GMW@psuvm.BITNET (05/20/85)

    I'm trying to get my 64 to provide tracking control for a telescope.
One of the requirements is a sidereal time clock.  I figured I could
set the Time of Day clock alarm in CIA #1 to wake me up n seconds from
now, add the appropriate constant to the current sidereal time (kept as a
running sum), and reset the alarm for another n seconds so the process
repeats ad. nauseum, where n depends on the time resolution I'll need (as
yet to be determined).  Having never worked with the TOD clock, I wrote a
short assembler routine to test it out.  This simply 1) sets the time to
0:00:00.0, 2) establishes a new IRQ vector, and 3) twiddles its thumbs
forever.  The new interrupt handler reads the current TOD, adds 1/2 sec.
to it, and resets the alarm with that value.  It works, but only for so
long (anywhere from 5 minutes to 2 hours); then it seems to miss an IRQ
and hangs.  I have placed CHROUT's at strategic locations in the code
to see where the trouble occurs, and all indications are that the TOD
interrupt is occasionally being ignored.  The clock keeps running, and
the "thumb twiddling" main loop keeps twiddling, but the alarm isn't
being heard.  Anyone know if this is a(nother) hardware bug, or am I
missing some critical piece of info that would make it work?
George Weaver

GMW at psuvm.bitnet
...!allegra!psuvax1!gmw@psuvm.bitnet
     

doug@terak.UUCP (Doug Pardee) (05/22/85)

I have never seen anything definitive from Commodore/MOS Technology,
but I believe that the Time-Of-Day feature is "not supported" in the
CIA chips.  My guess is that MOS Technology had to "steal" some gates
from TOD in order to fix problems in other sections of the CIA.

Consider that the C-64 kernal goes to an awful lot of trouble to avoid
using the TOD.  The resulting software TOD is much less reliable than
the CIA TOD should be.  Conclusion:  the hardware TOD is actually less
reliable than the software version.

The TOD features are not mentioned anywhere in the official Commodore
64 Programmer's Guide, except in the reproduction of the CIA's data
sheet.

Various problems have been noticed in the CIA's TOD.  Mine, for example,
both run at about 2.4 times the correct rate (those seconds really
click off!).

If we presume that in your case the CIA TOD *is* reliable, I can think
of two areas where there might be trouble.  First, remember that the
registers are in BCD.  They count 0-1-2-3-4-5-6-7-8-9-16-17-18-19...
And the "hours" register has a flag in bit 7 for PM, so it counts
0-1-2-3-4-5-6-7-8-9-16-17-128-129-...-136-137-144-145

Another problem area would be interfering interrupts.  You should turn
off the 60-Hz "jiffy" timer while playing with the TOD interrupts.  But
remember that this will also disable your keyboard.

Good luck!
-- 
Doug Pardee -- Terak Corp. -- !{ihnp4,seismo,decvax}!noao!terak!doug
               ^^^^^--- soon to be CalComp

dpa@warwick.UUCP (David Angier) (05/23/85)

Summary:
Expires:
Sender:
Followup-To:
Distribution:
Keywords:
Xpath: warwick snow snow ubu

If I understand this correctly you would be wiser to use a timer
in one of the CIA's.  Timer 1 is the only one that works correcly,
timer 2 has flaky interrupts also, take the time interval and
multiply by the clock rate (~.9 Megs, see Reference Guide for more
accurate detail) and store it in the counter registers.
Also set the control register to continual running mode, force load
running.
I recommend using CIA 2 to generate NMI's since these won't be ignored.
Also the Interrupt enable register needs to be set (write a $81 to it).

                        Dave (Maths @ Warwick University (UK) )

                            ..!mcvax!ukc!warwick!snow!dpa