Spectrum I/O Controller

Author(s): Dave Goodman
Publication: LISTing Newsletter
Date: February 1997
Pages: 5-9
  • Buffered 2 Way 8-Bit Data Bus
  • 8 Control Lines
  • Access Made Via Keyboard ‘IN’ and ‘OUT’ Commands or From Machine Code
The I/O Controller module with a ZX Spectrum
The I/O Controller module with a ZX Spectrum

Prompted by the many requests received from our customers for a series of interfaces allowing add-on expansion to the Spectrum computer, the I/O Controller module is offered to achieve this. Although not a programmable parallel/serial device in itself, the I/O Controller will decode 8 independant select control lines with data bus access via a bi-directional buffer. Buffered read and write lines are also available, thus establishing CPU protocol during I/O time.

It is intended that the controller be used with latch modules, serial interfaces and speech/sound generators which will be available from Maplin, designed as an expandable system to extend the Spectrum’s capabilities. Of course, many other commercial add-on’s could be controlled by this module, especially in the field of Robotics.

Circuit Description

The Z80 CPU IN/OUT accumulator instruction determines the state of the lower (A0 – A7) address bus. This effectively allows 256 input/output ports for use either from the keyboard or with machine code. Spectrum firmware uses A0 to A4 for printer, key scanning, cassette and sound functions leaving A5 to A7 free for use with suitably decoded address lines. IC1 determines when firmware is active and prevents the address decoder IC2 from being accessed. Assuming that a valid I/O Port address is presented, say 31, then the enable input of IC2 (pin 5) is taken low when A0 to A4 is logic high.

A5, 6 and 7 will be logic low, whereupon IC2 I̅O̅R̅Q̅ pin 4 is enabled and the decoded output appears on pin 15. There are eight select outputs (CS) from IC2, but only one may be accessed at any time. Address lines A5 to A7 determine which one of these CS outputs are active and Table 1 shows each I/O address associated with their respective control lines.

Table 1

Select     Port I/O
Line       Address
(CS) 1     31
     2     63
     3     95
     4     127
     5     159
     6     191
     7     223
     8     255

IC3 buffers the eight CS lines and produces an active low output. Alternatively, these outputs could all be made active logic high by fitting an inverting 74LS240 in place of IC3. A bi-directional data buffer, IC5, connects the Spectrum data bus to the port outputs for reading (PRD) and writing (PWR) operations. The PRD control line will not be active (logic 0) during the PWR sequence. Therefore, the data bus state always appears on the outputs of IC5 irrespective of correct port addresses being available or not! To read information in from the port, both I̅O̅R̅Q̅ and one of the eight CS lines must be active. IC4a OR’s both of the enable signals producing a logic 0 to send to IC4b. When a logic 0 read signal is presented, IC5 switches the port data bus through to the Spectrum bus. This arrangement ensures isolation between the CPU and the outside world. The regulator, REG1, supplies the +5V for powering port electronics and is tapped into the Spectrum 9V PSU. Although a +5V regulated output has been brought out to the expansion connector, the current available is small. Additional loading of the internal regulator will increase heatsink temperature – and may cause overheating problems – especially on 48K machines with Interface 1 attached.

Facilities for connecting an external PSU have been added which connect to the IDC outlet for powering modules connected to the port. R9, D1 can be used as a power on/off sensing device and control to these devices – more on this later. Finally, the system RESET line is extended through so that the Spectrum can be externally reset, and/or periphals reset during power up. The reset line is active low, and reset occurs after a low to high transition has been initiated.

Figure 1. Circuit Diagram
Figure 1. Circuit Diagram

Construction

Begin construction by first fitting the 2 x 28 way Edge Connector into the PCB, (Figure 5). Insert the terminal pins from the track side, and not the legended component side. You will see a blank locating peg fitted in position 5 of the connector; line it up with the PCB so that it sits directly behind but on the opposite side to the bar on the legend. Do not cut off any of the connector pins as they are used for mounting an expansion PCB, as we shall see shortly. Carefully push every terminal pin through the PCB leaving a 4mm gap between the rear of the connector and the PCB. This allows for clearance when fitting the module into a box, otherwise not enough of the socket protrudes for insertion into the Spectrum. Make sure that both the PCB and the socket are at right angles to one another with an even 4mm gap along the back and solder all terminal pins to the PCB, on the component side! Each drilled hole has plated through connections joining the tracks on both sides of the board so it is only necessary to solder one side. Ensure the connector does not move whilst doing this as it can be quite difficult to straighten out afterwards.

Figure 2. PCB Overlay
Figure 2. PCB Overlay

Expansion PCB

The smaller expansion PCB can be fitted at this stage although it is not part of the port section. All address, data, control and supply lines found on the Spectrum connector are extended out with this board. Note that no buffering or port outputs are available from here, just direct connections. Figure 5 shows all relevant details. In position 5 on both edges of this PCB, there are slots cut for alignment purposes. Insert the PCB between both rows of connector pins standing out from the main PCB with the slot against the legend bar. Gently bend all 54 terminal pins towards the expansion PCB until it is self supporting at right angles to the main PCB and solder each pin to the relevant track. Clean off surplus flux with brush and thinners and inspect every solder joint made so far. There must not be any short circuits between tracks or terminals; otherwise damage may occur to the Spectrum when running the port! As an extra precaution, use an ohmeter or multimeter set to measure resistance and test for shorts between adjacent tracks across and between both sides of the expansion PCB. A little time spent carefully checking at this stage is likely to prevent major headaches later on.

Component Assembly

With reference to the Parts List and Figure 2, insert all five IC holders, noting that those for IC’s 1 and 4 are 16 pin types, IC’s 3 and 5 are 20 pin and IC2 is a 14 pin type. Push them down onto the PCB, then carefully solder each terminal in place. Mount C5, 6 and 7, which are circular disc capacitors, ensuring clearance between leads and nearby tracks. Next insert resistors R1 to R9. They are all of the same value and colour coded: Yellow, Violet, Red (‘normal’ code), or Yellow, Violet, Black, Brown (5 band code). Fit diode D1 which must be the correct way around with the Cathode (K) or ringed end pointing to the outside edge of the PCB. Align the band with the legend. Now insert capacitors C1, 2, 3 and 4. These electrolytic type capacitors are polarised and must only be fitted one way around. The case or negative end is designated with a -V sign on the package, or by the shortest of two leads. Unmarked or longest leads are then +V; insert according to the legend. Finally, the 3-pin regulator REG1 can be fitted with the flat side containing the heatsink bracket laying over a section of track on the PCB. Bend all 3 terminals downward, approximately 6mm away from the plastic body and locate each one through its mounting hole. This square of copper track beneath the regulator helps to dissipate heat radiated from the heatsink, although it is fairly insignificant. Solder remaining components in place, remove excess leads, wires etc, and clean track face with brush and thinners. Because plated through holes have been incorporated, it is possible for solder to run down to the component side of the PCB. Therefore, closely inspect both sides of the board, looking for short circuits and probable errors.

The I/O Controller fitted to the Spectrum
The I/O Controller fitted to the Spectrum
                 C2
          +12V  --o|   |o--  -12V
  [illegible]V  --o|   |o--  +5V
            nu  --o|   |o--  nu
           P̅R̅D̅  --o|   |o--  nu
           P̅W̅R̅  --o|   |o--  PD7
           CS4  --o|   |o--  PD6
           CS8  --o|   |o--  PD5
           CS3  --o|   |o--  PD4
           CS5  --o|   |o--  PD3
           CS2  --o|   |o--  PD2
           CS6  --o|   |o--  PD1
           CS1  --o|   |o--  PD0
           CS7  --o|   |o--  R̅E̅S̅E̅T̅
                 IC3
                    PCB

2 x 13 way  Connector
+12V                    CS7
-12V        Slot        R̅E̅S̅E̅T̅
Figure 3. Connections to Header Plug
Figure 3. Connections to Header Plug
Figure 4. Fixing 2x13-Way Header to PCB
Figure 4. Fixing 2×13-Way Header to PCB
Figure 5. Fixing 2x28-Way Edge Connector
Figure 5. Fixing 2×28-Way Edge Connector

IDC Header

Every connection to and from the port is made via a 26-way IDC header plug. To fit this plug, slot the terminal pins over the PCB solder pads situated along the top edge, according to the diagrams of Figures 3 and 4. Arrange all terminals centrally to each pad and push the plastic body down onto the board edge. One side of the plug has a locating slot cut down it – arrange this facing outwards – which is situated on the track side of the PCB (same side as the 28-way socket!). Solder in place. It does not matter which side the slot faces, but Figure 4 notation is arranged for this particular configuration, so best stay with this standard.

Final Assembly

Insert IC’s into their sockets. Looking from the front of an IC with the ‘D’ slot facing left, pin 1 will be the first pin beneath the slot. Be careful to observe this! Fit the 5 Vero pins by inserting them from the track side and gently push their heads down onto the track pad before soldering in position. Again, re-check all work done and when satisfied that all is well, proceed with testing the module.

Testing the Module

Refer to Figures 3, 4 and 8 for testing. You will again need the services of a good multimeter, a length of hook-up wire and a diode, which should be left over after construction.

Solder two short lengths of wire to each end of the diode as in figure 8 and strip, then tin the opposite ends.

With PSU disconnected, plug the I/O controller module into the Spectrum expansion port. Turn on the power and check the usual start-up routine and cursor appears. Now try all keyboard operations and make sure they function normally; if not, switch off immediately and remove the module. In this case, take out all IC’s and re-insert the module – repeat the same check as before. The most common cause of problems is usually due to incorrect assembly and soldering, so if the Spectrum functions O.K. with the IC’s out, then one or more of them may be suspect.

Set the multimeter to read 5V DC and connect with the negative lead attached to the heatsink of REG1 (OV) and positive lead to REG1 output pin, marked with an arrow. Expect a reading of +4.9 to +5.1V on the supply rail. Remove the meter.

Type in PROGRAM 1 and RUN it.

Each 1 of 8 ports will be addressed and the DATA bus read. The left hand column lists each port and the right hand shows the data read which, for this test, should be &H FF (255) for every port address.

ENTER NEW and type in PROGRAM 2.

RUN this program, input address 223 and data received will be displayed as zero, in the right hand column opposite. Take the test diode and connect the cathode (K) to CS7 – port address 223 – and the anode (A) to PD0. Figure 3 details the appropriate IDC terminals. A new data reading of 1 should be displayed, due to the CS7 select line going low and pulling data line PD0 low with it. In fact, the data is inverted and is really 254 as PD0 to PD7 are all pulled high by resistors R1 – R8, thus returning 255 – 1. Line 170 in the program inverts data readings for clarity during testing. Removing the test diode from PD0 will cause data to return to 0. Repeat this test on the remaining seven data lines PD1 to PD7 using CS7 only, checking for data 2, 4, 8, 16, 32, 64 and 128. All combinations from 0 to 255 can be found by joining different data lines together and connecting to CS7 as required. Press ENTER and input a new port address from the list. Again repeat previous tests with the test diode connected to the selected CS pin until all eight addresses and CS lines have been checked. Only data input to the port is read in while running program 2 and a good indication of correct operation results in doing this. However, data output should also be checked but this operation is not quite as easy. To test port WRITE requires additional hardware in the form of latching registers and LED’s, and figure 9 shows a suitable circuit of this type. Data placed at the 74LS374 inputs is clocked into the latch during the WRITE cycle and appears at the Q outputs. Sending out data codes 0 – 255 will bring on the appropriate combination of LED’S at this time but not during the read cycle. PROGRAM 3 can be used with Figure 9, with c.c.t connected to the I/O module where each port and data code will be set up.

PROGRAM 1

10 FOR I=31 TO 255 STEP 32
20 PRINT I,IN I
30 NEXT I

PROGRAM 2

10 CLS:RESTORE 200
20 PRINT "ADDRESS";
30 PRINT TAB 10;"SELECT(CS)";
40 PRINT TAB 23;"DATA":PRINT
50 FOR I=1 TO 8:READ a,cs
60 PRINT TAB 2;a;
70 PRINT TAB 15;cs;
80 PRINT TAB 21;"********"
90 PRINT:NEXT I
100 INPUT "ENTER ADDRESS";p
110 RESTORE 200
120 FOR J=1 TO 8:READ a,cs
130 IF p=a THEN GOTO 150
140 NEXT J:GOTO 100
150 IF INKEY$<>"" THEN GOTO 150
160 PRINT AT 21,0;"PRESS ENTER TO CHANGE ADDRESS"
170 PRINT AT INT(P/16)+1,23;255-IN p;"**"
180 IF INKEY$=CHR$ 13 THEN GOTO 10
190 GOTO 170
200 DATA 31,1,63,2,95,3,127,4,159,5,191,6,223,7,255,8

PROGRAM 3

10 CLS
20 FOR J=31 TO 255 STEP 32
30 FOR I=0 TO 255
40 PRINT AT 5,7;"PORT =";J
50 PRINT "DATA =";I
60 OUT J,I
70 PAUSE 10
80 NEXT I:CLS
90 NEXT J:PRINT "END"
Figure 6. Box Cutting Details
Figure 6. Box Cutting Details
Figure 7. Fixing PCB into Box
Figure 7. Fixing PCB into Box
Figure 8. Test Diode
Figure 8. Test Diode
Figure 9. Additional Circuit to Test WRITE Function
Figure 9. Additional Circuit to Test WRITE Function
Figure 10. Circuit For External PSU
Figure 10. Circuit For External PSU

External PSU

As mentioned before, external power source connections can be brought into the I/O PCB and hence to the IDC plug. Note that these supplies do not drive the module at all. +12V, -12V, +5V and 0V inputs are available which can be extended to peripheral devices along the IDC cable and connector. Also Figure 10 shows a simple application for disabling or enabling these power rail connections when turning the Spectrum off or on – this being useful for preventing false triggering or even damage from occurring.

Further Expansion

Additional modules designed to be used with the controller module will be available, such as a parallel/serial system for communications applications; a sound/speech generator with amplifier and speaker and a 4-channel PWM servo/motor drive module. Some of these projects can be found in this issue and others will appear in future editions.

Interface 1

The I/O module should function normally with Interface 1 although this cannot be guaranteed in every case. We have found that some series 3/3B 48K machines do not tolerate extra ‘add on’s’ especially when the ZX printer is attached, possibly due to excessive loading on the PSU.

Fitting into a case

Should it be required to enclose the module, and it is highly recommended this be done, Figures 6 and 7 give the necessary cutting and drilling details for the box. There are 3 cut-outs to be made and 4 holes to be drilled in the lid for mounting the PCB. Use 4 1/8in 6BA spacers, bolts and nuts for this purpose. Fitting a 5-pin DIN plug into the box sidewall will allow a neat connection for an external PSU, if required, or perhaps a larger box could be used for containing both the PSU and the I/O module.

Final Hints

Control lines CS1 – 8, P̅R̅D̅ and P̅W̅R̅ are all active low (0V). Use CS to select the peripheral device and P̅R̅D̅/P̅W̅R̅ to enable Tri-state buffers on the data bus. Remember to connect the common 0V line as well! Only the addresses in TABLE 1 are decoded so if you are using several different modules as well as this module, check what codes can be used without clashing with any others.

SPECTRUM I/O CONTROLLER
PARTS LIST

RESISTORS: All 0.4W 1% Metal Film
R1-9       4k7                               9         (M4K7)

CAPACITORS
C1         100µF 10V Axial Electrolytic      1        (FB48C)
C2,3,4     100µF 25V P.C.Electrolytic        3        (FF11M)
C5,6,7     100nF Minidisc                    3        (YR75S)

SEMICONDUCTORS
D1,Test    1N4148                            2        (QL80B)
IC1        74LS30                            1        (YF20W)
IC2        74LS138                           1        (YF53H)
IC3        74LS244                           1      (QQ5[illegible]L)
IC4        74LS32                            1        (YF21X)
IC5        74LS245                           1        (YF91Y)
REG 1      µA78M05UC                         1        (QL28F)

MISCELLANEOUS
PL1        26-Way IDC Header                 1        (FJ15R)
SK1        2 x 28-Way Edge Connector         1        (FG23A)
           14-pin DIL Skt                    2        (BL18U)
           16-pin DIL Skt                    1        (BL19V)
           20-pin DIL Skt                    2        (HQ77J)
           Veropin 2141                      1 pkt    (FL21X)
           Spectrum I/O Controller PCB       1        (GB80B)
           Spectrum I/O Pin Ext PCB          1        (GB81C)
           8BA C/S Screws x ½in              1 pkt    (LR00A)
           8BA Nut                           1 pkt    (BF19V)
           8BA x 1/[illegible]in Spacer      1 pkt    (LR[illegible]9A)
           Box PB1 Black                     1        (LH14Q)

A kit of the above parts is available.
Order As LK65V (Spctrm I/O Cntrlr Kt) Price £17.95

The following are also available separately, but do not
appear in the 1985 catalogue:
Spectrum I/O Controller PCB Order As GB80B Price £5.75
Spectrum Pin Extension PCB Order As GB81C Price £1.85
SPECTRUM I/O CONTROLLER PARTS LIST (Maplin order codes; kit LK65V)
SPECTRUM I/O CONTROLLER PARTS LIST (Maplin order codes; kit LK65V)

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.