[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: killing time in 6502 assembly
Andre Fachat said,
"The most correct way would be to determine the clock frequency
of the machine (by testing whether it is an NTSC or PAL machine)
and then compute the exact number of cycles for the amount of time
to wait and set a CIA timer with it.".
For short term accuracy, that is correct. But for long term accuracy, the
crystal oscillator is not nearly so good as the TOD clocks (in countries where
the power-line frequency is adjusted to make electric clocks read Coordinated
Universal Time). A typical crystal has a tolerance of 500 parts per million
(ppm), amd a temperature stability of 50 ppm over the specified temperature
range. But even if the total figure were only 25 ppm (a likely situation), a
timer that used that frequency would have an error of over 13 minutes/year.
The short term accuracy of the power-line frequency can be poor, if heavy loads
are suddenly put onto the dynamos. But long term, the power-line is the next
best thing to an atomic clock.
But using a 1 MHz (approx.) crystal for timing, still gives an uncertainty
of one count; that is inherent in all counters. Of course, 1 us is better than
20 ms (PAL frame rate). And I might mention to Patrick that an interrupt
routine is not needed to use VIC as a timer. Just read VIC register $12, and
loop until you read, say, $80. Then
increment your counter, wait about 70 clock cycles (to get off the current
scanning line), and go back into the loop.
--
When backing up your hard drive, shift into reverse gear S M O O T H L Y.
John