Creating a Four Port Expansion Decoder

Author(s): Ed Fry
Pub Details: Time Designs Magazine v4 n6 (Volume 4, Issue 6)
Date: September/October 1988
Pages: 22-26

I was impressed with Ed’s Expansion Decoder project when he demonstrated it at the Northwest TS Mini-Fair this past summer. It was attached to, and controlled a variety of external gadgets, including a motor driven shaft, and an array of LEDs. With the low cost (going price is about $10) and plentiful supply of surplus TS1000 and ZX81s, this expansion device just might make an ideal construction project for the winter months. The article appearing in this issue covers all of the necessary schematics, instructions, and theory to put it together; in another article (or articles), Ed will discuss how to use and put it to work for you. A variety of suggestions have been made: remote controller for a satellite dish, burglar alarm system, weather station, and model railroad applications. In the article Ed offers a parts kit, and be sure to write, if you have any comments or questions.

  • Editor

As most faithful Sinclair owners know, our gracious Sir Clive did not allow the user access to a fine feature of the Z80 CPU known as IROQ (input/output request).

You could, of course, tie into the keyboard inputs and use an amplified signal to trigger an SCR out of the earphone jack, but that would only allow one bit; it would also use up valuable memory.

The most efficient way to do it on our computer would be to “POKE and PEEK” and “memory map” the I/O out of the range of present ROM or RAM. This is where the Expansion Decoder comes into play.

We all know that Sinclair cut a lot of corners wherever possible. The Z80 CPU is capable of directly accessing 65,536 (64K) bits of memory. Due to the incomplete memory decoding in the bare ZX81, about 55K of that memory is “images” of the 8K ROM and 1K or 2K RAM. This means that the 8K ROM plus it’s images occupy 32K of memory, and the RAM occupies the other 32K. Why??

(NOTE: From this point on, any time you see a number preceded by a “$”, it represents that the number is a HEXADECIMAL number). Now, to repeat myself, the Z80 CPU is capable of addressing one of any 65,536 addresses or bits ($0000 thru $FFFF) by placing the bits on the 16 (0-15) address lines “hi” or “low”. Decoding is the process of generating a “strobe” whenever a particular address combination appears on the “Address Bus”.

When decoding for memory, a large number of address combinations must be decoded to provide a strobe that activates the memory chip whenever any address in that range is on the bus. Each memory chip has its own internal decoding to select the exact byte in the range of the address to read. This latter stage of decoding in an 8K ROM for example, determines which of the 8,192 bytes in the ROM is to be sent to the Z80. In order to make this selection, the lower 13 address lines must be wired directly to the ROM, and the address strobe, decoded from the remaining three address lines, is wired to the ROM’s chip select pin. The chip select requires a low in order to become active.

In a fully decoded system, all three upper address lines (A13, A14 and A15) would go through a decoder, that would provide a low-going strobe to select the ROM when its address range (for example, $0000 to $1FFF) is selected. In the ZX81 and TS1000, the 8K ROM is activated anytime the address line A14 is at a low level, and the 1K/2K RAM is active anytime (thru an inverter chip) A14 is high.

What does this do to address space?? Let’s look at our three upper address lines (knowing that the first 13 are directly wired to the ROM). Let’s let an

"X" = a "I don't care"
"1" = a "high"
"0" = a "low"

The ROM is active when-          A15=X  A14=0  A13=X
Or when these combinations
appear-                            0      0      0
                                   0      0      1
                                   1      0      0
                                   1      0      1

As you can see, this will activate the 8K ROM a total of 4 different address locations, or the original plus three images for a total use of 32K of memory space! The same thing happens with our 1K or 2K RAM, except we have either 31 or 15 images respectively. Anyway we look at it, there goes our 64K of memory.

If you would like to prove the existence of those “images”, here is a little program you can run. What we will do is look or PEEK at the first byte of ROM and then compare it to the first byte in all the remaining ascending 1K blocks to the end of the 64K. Wherever it matches, it will print that address location on the screen.

10 LET AS=0                        Since rom address starts a0
20 LET B=PEEK(AS) Assign byte to B to compar
30 FAST You can leave it slow
40 FOR N=0 TO 65535 STEP 1024 To 64K in 1K steps
50 IF PEEK N=B THEN PRINT N, Making comparison
60 NEXT N You know what this does
70 SLOW If you want

The following diagram is a representation of the Sinclair Memory Map before and after our Expansion Decoder has been added.

Sinclair memory map before and after the Expansion Decoder
Sinclair memory map before and after the Expansion Decoder

CONSTRUCTION TIPS

REMEMBER YOU ARE WORKING ON THE BOARD UPSIDE DOWN, SO ALL NUMBERS, PINOUTS, LAYOUTS, ETC., ARE A MIRROR IMAGE!!

(1) Use a fine steel wool to clean any tarnish off the foil side of the P-board.

(2) Locate and solder all components, connectors, and IC sockets to P-board.

(3) Solder all +5 volt connections, then solder all ground connections.

(4) Solder one chip at a time. Example: say you are starting with IC#1-pin #2. You also have a connection to the edge connector-#4a and IC#9-pin #3. Make all those connections then go back and finish the other connections on IC#1.

(5) Pick up a wire-wrap tool at Radio Shack, or other electronics supplier. The Radio Shack tool has a little stripping tool inside the barrel of the wrap/unwrap tool. These tools run about $5.50. Buy some hook-up wire to match the gage of the stripping tool.

(6) When making a connection that goes to more than one point you might follow these instructions: We will use the +5 volt run for an example. It has approximately 23 points to connect in the one run!

(a) First find all the points to be connected (remember the edge connector or if you build your own supply you will want a connector to the power supply and a connection to the +5 volts for the inputs).

(b) Find the shortest route. (you might use the layout sheet and lightly draw the path.)

(c) Cut a length of wire to follow the route laid out plus about 2 1/2 inches. (We will call this a trace.)

(d) Strip about 1 inch of insulation off one end.

(e) Heat the solder to the melting tempature at the point you have decided for the start. Immediately stick the end of the wire into the melted solder and remove the the solder iron. Let cool for a couple of seconds and let go of the wire. Give a little tug on wire to make sure of a good solid connection.

(f) Find the next point. Strip a length of insulation approximate to the distance between the two points If the distance between the two points is 1 inch then strip a length of insulation about 1 1/8 inches long.

Diagram A: wiring a trace, and pinouts of the 74LS04, 74LS20, 74LS02, 74LS125, 74LS138 and 74LS175
Diagram A: wiring a trace, and pinouts of the 74LS04, 74LS20, 74LS02, 74LS125, 74LS138 and 74LS175

(g) Slide this 1 1/8 inch piece of insulation against the solder at the start point. DO NOT CUT THIS “TRACE” UNTIL ALL +5 VOLT POINTS ARE CONNECTED!!!!!

(h) Find your next point again. Place unsoldered end of 1 1/8 end of insulated wire at the next point (point “A”), as close as possible to the insulation.

(i) Repeat step (e).

Diagram B: trace wiring, TS1000 connector with extender for add ons, and power supply with 7805 voltage regulator
Diagram B: trace wiring, TS1000 connector with extender for add ons, and power supply with 7805 voltage regulator

(j) Repeat steps (h) thru (i) until “trace” is complete. After last point is soldered trim off any extra wire with a razor blade.

(k) Go to next trace and continue till done.

Cartoon: "Daddy's not mad...Daddy just wants to know how you did it!"
Cartoon: "Daddy's not mad…Daddy just wants to know how you did it!"

(7) For the TS1000 edge connector you will probably have to start with either a 50 or 100 pin connector and cut it to 46 pins. Be sure to buy one that has .100 inch spacing and also that the pins will go thru the holes in the P-board and have enough length to attach the extender card. (no less than 1/4 inch.)

(8) The extender!!! You probably will have to make one. Here is how. (Here we have a bunch of steps again.)

(a) You will need a piece of double side copper clad circuit board 2 3/8 inches long, 1 inch wide, and .062 inches thick.

(b) Next you will need some drafting tape. .050 wide would be ideal but .062 wide is a standard size.

(c) The last thing to buy is some circuit board etch solution.

(d) Plug the circuit board into the female edge connector. Use this as a guide to mark the board for placing the tape. Mark the board BETWEEN EACH SET OF CONTACT FINGERS, mark both sides without disturbing the board.

(e) Remove the board from the connector. Place the tape CENTERED between the marks on the board. Go around the the board for both top and bottom “trace”. cut the tape and repeat for the other 44 “traces”.

(f) Make sure there are no wrinkles or bubbles in any of the pieces of tape.

(g) Mix the etch soluation and etch according to directions. Check to make sure all exposed areas of copper are removed.

(h) Rinse well with warm water. Remove tape. Rinse again well. Dry. Use fine steel wool to clean any residue off board.

PARTS LIST

PARTS LIST FOR MAIN DECODER AND I/O BOARD

IC1, IC2, IC9, IC10   74LS125    QUAD TRI-STATE BUFFERS
IC3                   74LS20     DUAL 4-INPUT NAND GATES
IC4                   74LS138    3-LINE TO 8-LINE DECODER
IC5                   74LS04     HEX INVERTER
IC6, IC7              74LS175    QUAD D-TYPE FLIP-FLOP
IC8                   74LS02     QUAD 2-INPUT NOR GATES

R1   1/4 Watt 1000 OHMS       7   14 PIN DIP IC SOCKETS
R2   1/4 Watt 270 OHMS        3   16 PIN DIP IC SOCKETS

1    4 CIRCUIT DIP SWITCH

1    CONNECTOR FOR INPUT          (see text)
1    CONNECTOR FOR OUTPUT         (see text)
1    46 PIN EDGE CONNECTOR        (see text)
1    46 FINGER EXTENDER CARD      (see text)

1    PERF-BOARD (P-BOARD) RADIO SHACK #276-147 (cut in half)

                    MISCELLANEOUS

FINE STEEL WOOL       ROSIN CORE SOLDER       WIRE STRIPPER
WIRE      25 WATT OR LESS SOLDERING IRON (too high of a wattage
will lift the solder pads off the P-board)

          PARTS LIST FOR INPUT TEST/DEMO CIRCUIT

(2) 16 PIN DIP SOCKETS              (1) 8 CIRCUIT DIP SWITCH
(1) 8 CIRCUIT 4.7K DIP NETWORK or (8) 1/8 or 1/4 watt 4.7K resistors
(1) CONNECTOR TO MATCH CONNECTOR ON DECODER/PORT INPUT

          PARTS LIST FOR OUTPUT TEST/DEMO CIRCUIT

(1) 16 PIN DIP SOCKET      (8)  RECTANGULER LEDS (any color)
(1) CONNECTOR TO MATCH CONNECTOR ON DECODER/PORT OUTPUT

          (OPTIONAL) PARTS LIST FOR POWER SUPPLY

(1) TRANSFORMER    115 VAC PRIMARY   AND DUAL 12VAC SECONDARYS
(1) 7805   +5 VOLT REGULATOR
(1) HEAT SINK FOR REGULATOR  (optional but worth it)
(2) BRIDGE RECTIFIERS  MINIMUM OF 50 VOLTS @ 1 AMP
(2) 2200uf  @ 25VDC ELECTROLYTIC CAPACITORS
(1) 4.7uf @16VDC TANTALUM CAPACITOR

WITH THE EXCEPTION OF THE TRANSFORMER ALL THE PARTS IN
THE LAST THREE LISTS SHOULD MOUNT ON THE OTHER 1/2 OF THE
RADIO SHACK P-BOARD MENTIONED IN THE DECODER PARTS LIST.

For the purchase of the connectors and IC sockets. I would recommend checking with any surplus stores or suppliers in MODERN ELECTRONICS or other electronic oriented magazines before Radio Shack (Radio Shack is the least expensive source of plated P-board I have found).

The I/O connectors can be of your choice, but I found the 8-pin sip header was the easiest to use. Whatever you use, be sure to get male/female pairs.

You can power the board from the TS supply, but if you want to add much in I/O you will have to be careful. The TS supply will only carry an additional 350ma or so (if you have the 1 amp power pack), much less if you have the old 650ma power pack. Strange things will happen if you overload the power supply. I have included a simple regulated +5 volt power supply and unregulated 12 volt supply. The 12 volts may be regulated with a +12 volt regulator and the same basic circuit as the +5 volt supply. (The 12 volts will be used on a later project for the output port.)

To test the power supply, plug in and check voltages. CAUTION: YOU ARE DEALING WITH 110 VOLTS. IT POTENTIALLY CAN KILL!!

The construction of the two test/demo circuits is the same as the main decoder I/O board. For additional reference I have also included circuit drawings of all the ICs used in the project.


A complete set of “hacker parts” can be obtained from the author (some parts are new and some are used, but ALL are guaranteed good)…less the circuit board and connectors. This includes the test/demo boards, BUT not the optional power supply parts. The price for the parts kit is $20 + $1.50 S&H (while supplys last). I will also provide a transformer with dual 12 volt secondaries suitable for the optional power supply for an additional $2.00 + $1.50 S&H, if ordered with the main parts kit. Send check or money order to: ED FRY, 7044 N.E. 8th, Portland, OR 97211.


DO NOT connect the 1000 ohm resistor to ROMCS at this time. Using an ohmmeter or continuity checker, check for shorts between +5 volt contact (1B) and GND (4B and 5B). You should read an open circuit. If anything else is noted, find out why. You will probably find a small solder bridge between two pins on a socket. Check any point where the +5 volts and ground are adjacent to each other. Check continuity between all adjacent edge connector contacts on both “A” and “B” sides of the board. You should get no readings between any two contacts except ground pins B4 and B5 (if these two pins are not tied together, do so now, they HAVE to be tied together).

AT NO TIME SHOULD YOU PLUG OR UNPLUG THE BOARD FROM THE EDGE CONNECTOR WITH THE POWER ON. Plug the bord into the TS connector. The board should NOT have any ICs in any sockets yet!! Turn on the power. You should have a cursor immediately. If not, unplug the power and look for the short. When you get the cursor, remove the board.

Now you can connect the 1000 ohm resistor to ROMCS, insert IC3 (74LS20), IC4 (74LS138), and IC5 (74LS04). Plug the board back in. You should again immediately get the cursor. If not, check for solder bridges on one of the three IC sockets you just installed. Correct the problem (also be sure that you have all the ICs installed correctly and not oriented backwards). Now you can run the “ROM IMAGE” program at the beginning of this article again. You should only have a “0” on the screen. If you do not get a “0” then you probably have an IC incorrectly wired. Correct the problem. When you can run the program and come up with “0” then continue. (No images means the decoder is working.) Next insert IC1 and IC2 (74LS125), IC6 and IC7 (74LS175), and IC8 (74LS04). Plug the board in again, if no cursor, remove and check the sockets of the ICs last installed for solder bridges. When you have the problem corrected, insert the last two ICs, IC9 and

IC10 (74LS125). Go thru the check procedure again. When all the ICs are inserted and cursor comes on properly, the board is complete. Run the “ROM IMAGE” program one more time, make sure of the “0” readout and we will go to the I/O test/demo.

OUTPUT PORT TEST/DEMO

We are going to discuss just a little bit about binary numbers (if you need more info, you should be able to get a book at the library). First, the largest number in decimal that we can express with an 8-digit binary number is 255 (i.e., 11111111). The smallest is 0 (i.e., 00000000). Just as decimal deals in powers of 10 (i.e., 1, 10, 100, 10000, etc.), binary deals with powers of 2 (i.e., 1, 2, 4, 8, 16, etc.). Since we will only be dealing with 8 digits of binary, I will stop at the 8th power (128). A grid chart is provided to further the discussion.

           |-----|-----|-----|-----|-----|-----|-----|-----|
           | 128 |  64 |  32 |  16 |   8 |   4 |   2 |   1 |
DECIMAL    |-----|-----|-----|-----|-----|-----|-----|-----|
   1    =  |  0  |  0  |  0  |  0  |  0  |  0  |  0  |  1  |
           |-----|-----|-----|-----|-----|-----|-----|-----|
 135    =  |  1  |  0  |  0  |  0  |  0  |  1  |  1  |  1  |
           |-----|-----|-----|-----|-----|-----|-----|-----|
  15    =  |  0  |  0  |  0  |  0  |  1  |  1  |  1  |  1  |
           |-----|-----|-----|-----|-----|-----|-----|-----|
 254    =  |  1  |  1  |  1  |  1  |  1  |  1  |  1  |  0  |
           |-----|-----|-----|-----|-----|-----|-----|-----|
 124    =  |     |     |     |     |     |     |     |     |
           |-----|-----|-----|-----|-----|-----|-----|-----|

To convert a decimal to a binary number, select the decimal number, in this case 124. Start with the eighth of the powers of 2 columns (i.e., 128). 128 will not subtract from 124 (we are only using positive numbers), so we place a “0” in the 128 column. 64 will subtract from 124, so we will place a “1” in the 64 column. 124-64=60 right. We will always work with the remainder. 32 will subtract from 60 so put a “1” in the 32 column. 60-32=28. 16 will subtract from 28, a “1” goes in th 16 column. 28-16=12. 8 will subtract from 12, a “1” in the 8 column. 12-8=4. 4 will subtract from 4, a “1” in the 4 column. 4-4=0, that means all the rest get a “0”. Our 8 digit binary number for decimal 124 will look like this: “011111100”. Lets try another like 174. Work it out by yourself. The answer should be “10101110” binary. Easy…right?!

Now lets go the other way; that is, to convert binary to decimal. Take an 8 digit binary number “00100001”. Take only the columns that have a “1” and add the powers of 2 up. “00100001” the 1 column has a “1” and the 32 column has a “1”, so 32+1=33. Lets do another…”10101011″. The 1 has a “1”, 2 has a “1”, 8 has a “1”, 32 has a “1”, and 128 has a “1”, so 1+2+8+32+128=171. Try this one: “01100110”. If your answer is 102, then you’ve got it down, if not, work with your grid until you do get it.

Now, the reason for all of this, is that your I/O ports are a representation of an 8 digit binary number. To work with them you will have to understand at least this much about binary numbers. OK..lets go!

Plug your demo/test board output circuitry into the output port. Be sure you have the two wire jumper for +5 volts and GND plugged in. (Note: If you are using your own supply you MUST NOT connect the TS +5 volt and your own +5 volt supplies together. You MUST connect the GNDs together).

The four address ranges of your ports in decimal and in ($hex) are:

          DECIMAL/($HEX)    TO    DECIMAL/($HEX)
PORT #1    8192/($2000)           10239/($27FF)
PORT #2   10240/($2800)           12287/($2FFF)
PORT #3   12288/($3000)           14335/($37FF)
PORT #4   14336/($3800)           16383/($3FFF)

Pick the port you want to use, then pick an address in the port range, that is easy for you to remember. I use 10000 for port #1, 12222 for port #2, 13333 for port #3, and 14444 for port #4. You have 2047 addresses in each range to choose from.

Lets go ahead and use Port #1 for our demo port. If you want to use another, go for it, but remember to change the addressed POKES and PEEKS to match the port chosen.

If you have everything hooked up, turn the power on. You might have one or more random LEDs on, but that’s ok. First enter POKE 10000,0. That should turn all the LEDs off. Next enter POKE 10000,255 that should turn all the LEDs on. Next lets make a little program:

10 INPUT X
20 POKE 10000,X
30 GOTO 10

Lets input 3 first. LEDs 1 and 2 should turn on (remember we are going from right to left, not left to right), all others should be off. Now try 8. Number 4 should be on, and all others should be off. If you get anything else, then you probably have your data lines mixed up. Data lines are D0 thru D7. To check, POKE 1, 2, 4, 8, 16, 32, 64, and 128 in sequence. Note the order that the LEDs turn on. Remove the board and rearrange the wiring to the output port connector properly. Plug th board back in and rerun the program and the sequence of the powers of 2. You will notice that the LEDs look just like an 8 digit binary number, with “LED on” representing “1” and “LED off” representing “0”. After you get the sequence right, lets run another little program:

 10 POKE 10000,0
20 PAUSE 30
40 LET A=1
50 FOR N=1 TO 7
60 POKE 10000,A
70 LET A=A*2
80 PAUSE 5
90 NEXT N
100 LET A=128
110 FOR N=1 TO 7
120 POKE 10000,A
130 LET A=A/2
140 PAUSE 5
150 NEXT N
160 GOTO 40

If you want to decrease the speed increase the pause. To increase the speed, decrease the pause. For the maximum speed without machine code, add the line:

5 FAST

Now for the input test/demo. Lets use the same port. When I PEEK an address, I always use the first address in port range. For Port #1 that would be 8192 decimal. Hook a cable from the decoder/port board input connector to the test/demo board input connector. Turn all the switches “off”, then enter PRINT PEEK 8192. The display should read “255”. Now turn all the switches “on”. The display should read “0”. If you do not get these results, then run this program:

10 SCROLL
20 PAUSE 30
30 PRINT PEEK 8192
40 GOTO 10

Now set the sequence of powers of 2 using the switches. If you noticed a switch “off” = “1”, and a switch “on” = “0”, run the program. Turn all the switches “on”. The display should be scrolling a “0”. Turn switch 1 “off” and leave all others on. The display should now scroll a “1”. Turn 1 back “on” and turn only 2 “off”. A “2” should appear. Turn 2 back “on” and turn only 3 “off”. Continue thru the sequence of turning all the switches “on” and turning one switch back “off” in order, from right to left. you should get increasing powers of 2 displayed on the screen. The power of 2 displayed should match the switch that is “off” (i.e., switch 5 “off” should display “16”, switch 8 “off” would display “128”, etc.).

Again note the sequence. If it is mixed up, unplug the decoder port board and rearrange the wiring properly to the input connector on the decoder

board. Once you get everything squared away, here is our last little demo program. Plug both the input and output connectors into the decoder port board. Just for kicks, we will change our port select switch to Port #2. Here is the program:

10 POKE 12222,0
20 PAUSE 30
30 LET A=PEEK 10240
40 POKE 12222,A
50 GOTO 30

Now you will note that for any switch that is “off” on the input port, there will be the corresponding LED “on” for the output port.

These programs and demo, should give you something to play with until the next issue of TIME DESIGNS, when we will explore different types of output driver cards and applications. Have Fun!

Test/demo (and optional power supply) component diagram
Test/demo (and optional power supply) component diagram
Main decoder component diagram
Main decoder component diagram
Main decoder and I/O board circuit
Main decoder and I/O board circuit
Output test/demo circuit
Output test/demo circuit
Input test/demo circuit
Input test/demo circuit