For a long time now I have shied away from using or designing circuits that use A/D converters. I’ve always figured that they were too difficult not only to build, but also align and set up. So in this issue I’ve decided to take a stab at an A/D converter for the TS/ZX.
I picked the TLC548 as the work-horse for a few reasons: it’s cheap ($6.95), it’s easily obtained (Radio Shack #276-1796), it’s fairly fast for an inexpensive converter (8 micro-seconds conversion typical), it’s CMOS, and it looks quite easy to interface to the TS/ZX. (I found out later on that it’s easier to interface than I thought! The entire circuit only took me three hours to set-up, from design to working prototype.) The technical info that comes with the TLC548 really helped to speed the design. This circuit is based on the one in that tech sheet, although re-designed for the TS/ZX. The software is again based on the example in the tech sheet but re-written for the re-designed hardware.
The Sinclair’s architecture for I/O is rather complex, ironically, because Mr. Sinclair was trying to keep the hardware design simple! The Z80A used in the TS/ZX is capable of 256 I/O ports using address bits 0-7. However, in order to keep circuit parts count down, the Sinclair’s I/O is only PARTIALLY decoded. That means instead of decoding all 8 I/O address bits to come up with an address to read the keyboard, Sinclair only used bit 0 to select the keyboard whenever it is a logical zero, and IGNORES ALL OTHER BITS. So, any EVEN I/O address (bit 0=logic zero) will read the keyboard. That eliminates using all even addresses for external devices. Bit 1 is also used within the computer, when it’s a logical zero, so we can’t use that bit either. The TS2040 printer is also partially decoded by selecting bit 2=zero and bit 7=one, so if we keep bit 7=zero, then we can use bit 2. The 2050 modem is completely decoded and uses ports 73 and 77 hex. You’ll note that they keep bit 7=zero and bits 0 & 1=one to avoid selecting I/O operations in the computer or in the printer. In our A/D converter we will use port 67 hex. which will avoid conflict with any of the common peripherals.
You can make this project simple or complex depending on the options you decide to use. ICs 8-19 are optional. To wire up just one channel all you need are ICs 1-7. For two converters just add IC8, and wire up the second half of IC5. You can continue to add A/D converters as shown in the schematic, up to a total of eight. The pin connections on the left side of IC7 are common to all A/D converters that you connect up. For multiple converters, this circuit is more complex than using an ADC809 converter from National Semiconductor, but that converter takes 10 times longer for each conversion than does the TLC548. So for speed’s sake the slightly more complex circuit is worth it.
Looking at the schematic #1, IC1 & IC2 serve to decode the I/O address and form the proper read and write signals we will need to access the A/D converters. IC5 is used as a simple output port to “select” the A/D converter that we want to read. Note that upon power up or reset IC5 will be preset, deselecting the attached A/D converter. IC7-IC14 are the converters. IC3 is a tri-state buffer used to read the serial conversion data from the TLC548s. IC6 is the A/D converter supply and reference.

Schematic #2 shows how you can use the other port commands that happen to decode from IC2 for a general purpose I/O port. IC18 can be added if you want a general purpose input port (input 63H) and IC19 for a general purpose output port (out 63H). You could also use that port for any other project you may have in mind. If you can wait until next issue, my next article will be using port 63H for a D/A converter.
To begin an operation, we first select one of the converters by writing port 67H (the “H” designates hex) with the appropriate bit=zero and all other data bits set high. For instance, to select converter #0 we write port 67H with FEH (binary = 1111 1110). So, to select converter #1 we would write port 67H with FDH (binary = 1111 1101). After we have selected one of the converters we then can read the PREVIOUS conversion results from it in SERIAL form. [So after selection, data bit 7 of the result is available from the data out pin (pin 6).] All we need to do is issue a read port 67H instruction and IC3 will put the serial bit on to bit 0 of the data buss for the Z80A to input. IC4 inverts the read port 67H signal so that at the END of the read port instruction the low-going signal will cause the TLC548 to send the next bit out by toggling the I/O CLOCK pin (pin 7). All we need to do in the software is READ PORT 67H, SHIFT LEFT, READ PORT 67H, SHIFT LEFT, ect., until all 8 bits have been read. Then, at the end of the operation, we de-select the A/D by writing port 67H with FFH (binary = 1111 1111). You can deviate from the circuit when selecting a regulator for IC6. I used a 723 because I have a lot of them, and they are readily available. The overall accuracy of the converter is based on this regulator since it supplies the reference voltage to the converter. You could also leave the regulator out and use the regular five volt supply, but accuracy would suffer. The TLC548 is an 8-bit converter. This means that it can “dissect” the voltage being measured by 256, and this would be the smallest measurable voltage. For instance, if the reference voltage is 2.56 volts, then the maximum measurable voltage would be 2.56 volts and the smallest would be 2.56/256 or .01 volts. This would be an ideal reference because each count would be .01 volts. However, the tech sheet indicates that “unadjusted errors may increase if the differential voltage Vref+ to Vref- falls below 4.75 volts”. So we need something greater than 2.56 volts to keep accuracy up. If we use 5 volts this would give us the smallest measurable voltage 5/256 or .01953125 volts—a rather hard number to work with. Looking again at the tech sheet you’ll see we can supply up to 6 volts in normal operation. So if we use 5.12 volts this would not be too high for the other logic and it would give us 5.12/256 or .02 volts as the smallest measurable voltage—an easy number to work with. Why use the 5.12 as the supply voltage too? If we use the TS/ZX 5 volt supply to supply VCC to the TLC548 and the 5.12 volts as reference voltage only, we would be violating one of the specs for the TLC548. Page 4 of the sheet, the line that states “Positive reference voltage, Vref+ (see Note 2)”, this states that the max Vref+ that can be supplied is VCC + .1 volts. We would be .12 volts over VCC.
The following ML routine can be poked into the first REM statement and will give you the PREVIOUS conversion results each time it is accessed. The routine uses relative jumps so it can be placed anywhere. Just remember to add 6 to the starting address of the routine to obtain the address to change the converter selection byte.
LD B,08H 06 08 06 08 ;initialize counter
LD C,0 0E 00 14 00 ;clear result register
LD A,FEH 3E FE 62 254 ;select converter
OUT 67H,A D3 67 211 103 ;via out instruction
LOOP:RLC C CB 01 203 01 ;shift result register left
IN A,67H DB 67 219 103 ;read converter bit
AND A E6 01 230 01 ;mask off bit 0
OR C B1 177 ;or result register to new bit
LD C,A 4F 79 ;put new result into result
register
DEC B 05 05 ;decrement bit count
JR NZ,LOOP 20 F5 32 245 ;if bit count>0 continue
LD A,FFH 3E FF 62 255 ;de-select all converters
OUT 67H,A D3 67 211 103 ;via out 67 instruction
RET C9 ;return to BASIC
The following is a BASIC program that shows usage of the ML routine above.
1 REM 123456789012345678901234
1000 PRINT AT 12,0;"AD1=";AT 12,16;"AD2=";
1004 POKE 16519,254
1005 LET A=USR 16514*.02
1006 POKE 16519,253
1007 LET B=USR 16514*.02
1010 PRINT AT 12,5;A;AT 12,21;B;
1020 GOTO 1004
Poke the assembly language routine starting at 16514 which is in the REM statement. Then run the program and it will continiuously read conversions from both A/Ds.
Lines 1005 and 1007 show the usage of the routine, simply call the routine as a USR funtion and multiply the count returned by .02. Of course, if you decide on a different reference voltage, then you would multiply by the result of this formula: Vref+/256.
Location 16519 contains the converter selection byte layed out as follows:
BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0 CONVERTER # 7 6 5 4 3 2 1 0
PARTS LIST
IC1,IC2 74LS138 IC3 74125 IC4 74LS04 IC5 74LS74 IC6 LM723 IC7 TLC548
OPTIONAL PARTS
IC8-IC14 TLC548 IC15-IC17 74LS74 You'll need 1 for every 2 TLC548s IC18 74LS244 IC19 74LS374
YOU MUST SELECT ONLY ONE CONVERTER AT A TIME! A ZERO in the bit location selects that converter, and a ONE deselects it. There should be only ONE ZERO in the byte at location 16519 when selecting a converter. This selection method allows up to eight converters to be used while only using one I/O port!
Layout is not critical, however, use a large enough perf board to allow for expansion. My next article will include the addition of a D/A converter to this board, using port 63H. I used a Vector P178-1 tool and the heat vaporizing wire to wire mine up on a perf board, and using one of the Zebra Systems Inc. edge connectors. Hot glue works great for attaching the IC sockets and edge connector to the perf board.
Most of the parts can be obtained at Radio Shack, Jameco, or JDR Microdevices who all advertise in most of the electronic journals. The Zebra edge connectors are $5.95 each (Zebra Systems, 78-06 Jamaica Avenue, Woodhaven, NY 11421), or you can cut a 50 pin wire-wrap edge connector down to the 46 pins required using a fine saw or small cutting disc attachment on a Dremel Moto-tool.
If you have any problems, or even if you don’t, drop me a line and let me know how you made out. Tim Stoddard, [address omitted]. CompuServe ID# [e-mail address omitted].
