A real-time clock is incorporated in the CIA, providing a timekeeping device more conducive to human needs than the microsecond precision of the interval timers. Time is kept in the American 12-hour AM/PM format. The TOD clock consists of four read/write registers: hours (with bit 7 acting as the AM/PM flag), minutes, seconds and tenths of a second. All registers read out in
BCD format, thus simplifying the encoding/decoding process. Reading from the registers will always return the time of day. In order to avoid a carry error while fetching the time, reading the hours register will immediately halt register updating, with no effect on internal timekeeping accuracy. Once the tenths register has been read, updating will resume. It is possible to read any register other than the hours register "on the fly," making the use of a running TOD clock as a timer a practical application. If the hours register is read, however, it is essential to subsequently read the tenths register. Otherwise, all TOD registers will remain "frozen." Setting the time involves writing the appropriate BCD values into the registers. A write access to the hours register will completely halt the clock. The clock will not start again until a value has been written into the tenths register. Owing to the order in which the registers appear in the system's
memory map, a simple loop is all that is required to write the registers in the correct order. It is permissible to write to only the tenths register to "nudge" the clock into action, in which following a hardware reset, the clock will start at 1:00:00.0. In addition to its timekeeping features, the TOD can be configured to act as an
alarm clock, by arranging for it to generate an
interrupt request at any desired time. Due to a bug in many 6526s (see also errata below), the alarm IRQ would not always occur when the seconds component of the alarm time is exactly zero. The
workaround is to set the alarm's tenths value to 0.1 seconds. The TOD clock's internal circuitry is designed to be driven by either a 50 or 60 Hz
sine wave signal. As used in the C-64 and C-128(D), the computer's power supply supplied such a signal from the mains, resulting in a stable timekeeper with little long-term drift. The ability to work with both power line frequencies allowed a single version of the 6526 to be used in computers operated in countries with either 50 or 60 Hz power. It is important to note that contrary to the popular belief,
NTSC or
PAL video standards are not directly linked to mains power frequency. Additionally, some computers did not derive their TOD clock frequency from the mains power source. For example, both
NTSC and
PAL variants of
Commodore SX-64 use 60 Hz TOD clock supplied by a dedicated crystal.
KERNAL operating system in
Commodore 64 for example will determine the video standard during system startup, but tries neither to identify the supplied TOD clock frequency nor to initialise the CIAs correctly on 50 Hz driven machines. Thus, it is the responsibility of any application software that wants to use either CIA's TOD function to determine the supplied frequency and set the CIA(s) flag accordingly itself. Failure to do so may cause the clock to deviate quickly from the correct time. The 8520 revision of the CIA, as used in the
Amiga and the
Commodore 1581 disk drive, modified the time-of-day clock to be a 24-bit binary counter, replacing the
BCD format of the 6526. Other behavior was similar, however. ==Versions==