Jump to content

MOS Technology CIA

From Wikipedia, the free encyclopedia
Pin configuration of the 6526 CIA
Early 6526 CIA were still in costly ceramic package with gold contacts. Later versions were produced in cheaper plastic package.
CIA MOS 6526A in plastic package
MOS 8520A in anAmiga 1000

The6526/8520 Complex Interface Adapter(CIA) was anintegrated circuitmade byMOS Technology.It served as anI/O portcontroller for the6502family of microprocessors, providing forparallelandserialI/O capabilities as well astimersand a Time-of-Day (TOD) clock. The device's most prominent use was in theCommodore 64andCommodore 128(D),each of which included two CIA chips. TheCommodore 1570andCommodore 1571floppy disk drives contained one CIA each. Furthermore, theAmigahome computersand theCommodore 1581floppy disk drive employed a modified variant of the CIA circuit called 8520. 8520 is functionally equivalent to the 6526 except for the simplifiedTODcircuitry. Predecessor to CIA wasPIA.

Parallel I/O

[edit]

The CIA had two8-bitbidirectional parallel I/O ports. Each port had a corresponding Data Direction Register, which allowed each data line to be individually set to input or output mode. A read of these ports always returned the status of the individual lines, regardless of the data direction that had been set.

Serial I/O

[edit]

An internal bidirectional 8-bitshift registerenabled the CIA to handleserial I/O.The chip could accept serial input clocked from an external source, and could send serial output clocked with one of the built-in programmable timers. Aninterruptwas generated whenever an 8-bit serial transfer had completed. It was possible to implement a simple "network"by connecting the shift register and clock outputs of several computers together. The maximum bitrate is 500 kbit/s for the 2 MHz version.

The CIA incorporates a fix to a bug in the serial-shift register in the earlier6522 VIA.The CIA was originally intended to allow fast communication with a disk drive, but in the end couldn't be used because of a desire to keep disk drive compatibility with theVIC-20;in practice the firmware of1541drive had to be made even slower than its VIC-20 predecessor to workaround a behaviour of the C64'svideo processor,that, when drawing the screen, turned off theCPUfor 40 microseconds every 512 microseconds and in that timeslice can't listen to the bus, risking to miss some bit.[1] [2]

Interval timers

[edit]

Two programmable interval timers were available, each with sub-microsecondprecision. Each timer consisted of a16-bitread-onlypresettabledown counterand a corresponding 16-bitwrite-onlylatch.Whenever a timer was started, the timer's latch was automatically copied into its counter, and the counter would then decrement with each clock cycle until underflow, at which aninterruptwould be generated if the CIA was configured to do so.

The timer could run in either "one-shot" mode, halting after underflowing, or "continuous" mode, reloading the latch value and starting the timer cycle anew. In addition to generating interrupts, the timer output could also be gated to the second I/O port.

As configured in theCommodore 64andCommodore 128,the CIA's timing was controlled by the Ø2 system clock, nominally oneMHz.This meant that the timers decremented at approximately one microsecond intervals, the exact time period being determined by whether the system used theNTSCorPALvideo standard. In the C-128,clock stretchingwas employed so the CIA's timing was unaffected by whether the system was running in SLOW or FAST mode.

It was possible to generate relatively long timing intervals by programming timer B to count timer A underflows. If both timers were loaded with the maximum interval value of 65,535, a timing interval of one hour, 11 minutes, 34 seconds would result.

Time-of-Day (TOD) Clock

[edit]

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 inBCDformat, 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'smemory 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 analarm clock,by arranging for it to generate aninterrupt requestat 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. Theworkaroundis 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 Hzsine wavesignal. 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,NTSCorPALvideo 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, bothNTSCandPALvariants ofCommodore SX-64use 60 Hz TOD clock supplied by a dedicated crystal.KERNALoperating system inCommodore 64for 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 theAmigaand theCommodore 1581disk drive, modified the time-of-day clock to be a 24-bit binary counter, replacing theBCDformat of the 6526. Other behavior was similar, however.

Versions

[edit]

The CIA was available in 1MHz(6526), 2 MHz (6526A) and 3 MHz (6526B) versions. The package was aJEDEC-standard 40-pinceramicorplasticDIP.The 8520 CIA, with its modified time-of-day clock, was used in theAmigacomputers.

Commodore embedded reduced (just 4 registers) CIA-like logic for the cost reducedCommodore 1571inside the C128DCR (SeeCommodore 128) in a gate array called 5710 which also contains other functions. The 5710 CIA has the serial clock for the fast serial interface hardwired to a CIA6526 equivalent Timer A value of 5, leading to a per-bit time of 5μs on transmission. This is different from what used to be a Timer A value of 6 in the 6526 CIA in the originalCommodore 1571.The 5710 CIA does not contain timer or timer control registers. It only contains two port registers and the register to control the serial shifter and its event.

Errata

[edit]

In addition to the aforementioned alarm clock interrupt bug, many CIAs exhibited a defect in which the part would fail to generate a timer B hardwareinterruptif theinterrupt control register(ICR) was read one or two clock cycles before the time when the interrupt should have actually occurred. This defect, as well as logic errors in the Commodore provided (8 bit) operating system, caused frequent pseudo-RS-232errors in theCommodore 64andCommodore 128computers when running at higherbaudrates.

References

[edit]
  1. ^Perry, Tekla S.; Wallich, Paul (March 1985)."Design case history: the Commodore 64"(PDF).IEEE Spectrum.22(3): 48–58.doi:10.1109/MSPEC.1985.6370590.ISSN0018-9235.S2CID11900865.Archived fromthe original(PDF)on 2012-05-13.Retrieved2011-11-12.
  2. ^articles on c64-wiki
[edit]