### Author Topic: Logic gates to select single values on an 8/16-bit bus  (Read 3584 times)

0 Members and 1 Guest are viewing this topic.

#### ALonda

• Contributor
• Posts: 23
• Country:
##### Logic gates to select single values on an 8/16-bit bus
« on: March 19, 2017, 11:19:41 pm »
This all is in relation to using gates or logics of some sort to determine if a particular 8/16-bit address is on an address bus is of a particular value in order to do a chip enable, or to check if all 8/16 bits of an adder is zero, or in general to validate that all logic outputs from a certain circuit is of a particular value.

I want to create a circuit to set a chip enable if a particular address is on a bus. My best idea so far is using a combination of 4-input NOR and AND gates connected on selected lines but with one of each leaves two outputs needed to be combined with yet another logic chip. so probably one 4-input AND + one 4-input NOR + one 2-input NOR for an 8-bit address input.

I have tons (60+) old 4K proms I could use but no programmer/eraser equipment.

I imagine diodes would work in place of (N)OR?

Just connecting them together without anything I expect would work (in place of (N)ORs but if one output was high and the other low, alot of current would go to waste. (?)

Transistors/mosfets should work but would be a wiring nightmare (?)

I have no experience with PALs. Are PALs easy to program? Need special equipment?

Is there something Im not aware of that could solve my problem cheaper/easier?

/A
(Yes I have been bitten by jealousy bug and dream of making a breadboard cpu built with logic gates just like my hero Ben Eater)

#### evb149

• Super Contributor
• Posts: 1666
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #1 on: March 19, 2017, 11:42:53 pm »
Whoa.  Ok. Here are the general categories of logic circuits you should know about:
* address decoder: does the address decoding and outputs chip select or similar signals.  Usually somewhat bus specific or somewhat uncommon these days.

* binary decoder / demultiplexer like the 74HC138.  This takes for example 3 bits in and produces 8 bits out according to the bit value of the three binary input bits. 74HC154 is a 4 line to 16 line decoder analogously.  Bigger ones are not so common as standard products.

* magnitude comparator, like the 74HC688, takes in an 8 bit input code and compares that value bit for bit against another 8 bit input set.  If the two sets of 8-bit inputs are equal then it outputs a logic indication.  Usually more than 4 or 8 bits are not common as standard logic products.

* CPLD: This is a complex Programmable Logic Device.  It implements basically an AN / OR array with some flip flops and clocks thrown in.  You can basically generate "any" combinatorial function of N inputs generating P outputs with or without registering / clocking and with possible inversions, possible feedback terms in a given macrocell.  What's a macrocell?  Well just a chunk of circuitry that does the former function.  Most CPLDs have K Macrocells with K being several and then you can have the outputs of those K macrocells also participate as sources of data to other macrocells so you can have complex    functions of not just the IC input pins but also internally generated state / signal variables.  And of course you can route "any" of the internal outputs to actual output pins according to a programmable routing matrix.  Another routing matrix selectively connects input pins into the input matrices.  So basically anything you can do with a couple of hand fulls of TTL logic ICs implementing any hierarchal logic function of Q inputs and producing X outputs can be achieved.  For a few dollars you can get chips with for instance 32, 64,  or 128 I/O lines and you can do whatever you want    with them limited by some timing and routing limitations.  This is the modern way to have things like a parallel bus interface with address decoding implemented.  They are called PROGRAMMABLE logic devices  because you must program them usually with JTAG or SPI or some proprietary in system programming process using a few dedicated pins.  Sssometimes you can reprogram them using the system MCU other times they are factory programmed by test points / connector / JTAG on the PCB.

* FPGA, like a CPLD but usually bigger, even more logic and I/O functions.  How much bigger?  Well big enough that you can create a logic representation of a  CPU like a Z80 or PIC or 8086 or SPARC processor using the logic inside a medium size FPGA and also implement "peripherals" like timers, address decoders, etc.  You can also have up to hundreds of kbits of internal RAMs, multipliers, etc. etc. Someone recently said they made a 10 year old $13 FPGA evaluation board for a SMALL FPGA emulate some old CP/M processod (8088?) and a bunch of I/O interface hardware and it plays the actual game of Zork just like an old computer from 1985 would. Overkill for your needs, though, but would also work. Like CPLDs you program your logic into the chip as a configuration either volatile or non-volatile and the chip just does the logic it is programmed to do thereafter. Sometimes you can even use it to reprogram parts of itself and some experiment with neural networks and stuff like that in such a way. To create the logic definitions for a PLD (smaller than a CPLD), CPLD, or FPGA you usually use a language called Verilog or VHDL but sometimes other logic entry methods like schematics can be used. You compile your logic input definitions and the output is a programming image for your device. This all is in relation to using gates or logics of some sort to determine if a particular 8/16-bit address is on an address bus is of a particular value in order to do a chip enable, or to check if all 8/16 bits of an adder is zero, or in general to validate that all logic outputs from a certain circuit is of a particular value. I want to create a circuit to set a chip enable if a particular address is on a bus. My best idea so far is using a combination of 4-input NOR and AND gates connected on selected lines but with one of each leaves two outputs needed to be combined with yet another logic chip. so probably one 4-input AND + one 4-input NOR + one 2-input NOR for an 8-bit address input. I have tons (60+) old 4K proms I could use but no programmer/eraser equipment. I imagine diodes would work in place of (N)OR? Just connecting them together without anything I expect would work (in place of (N)ORs but if one output was high and the other low, alot of current would go to waste. (?) Transistors/mosfets should work but would be a wiring nightmare (?) I have no experience with PALs. Are PALs easy to program? Need special equipment? Is there something Im not aware of that could solve my problem cheaper/easier? /A (Yes I have been bitten by jealousy bug and dream of making a breadboard cpu built with logic gates just like my hero Ben Eater) The following users thanked this post: MK14, ALonda #### evb149 • Super Contributor • Posts: 1666 • Country: ##### Re: Logic gates to select single values on an 8/16-bit bus « Reply #2 on: March 20, 2017, 12:05:10 am » You "always" need special software and equipment of some sort to program PALs, PLDs, CPLDs, FPGAs, or PROMs. The equipment for somewhat modern low cost devices is usually more available and also less expensive than trying to find equipment to program old obsolete PROMs / PLDs that might be from the 1980s or 1990s. Since maybe 2010 or so there are lots of ICs that are provided with free software tools as well as inexpensive ($10-$50 range for CPLDs I guess, maybe$30-$200 range for small to medium FPGAs) boards / kits that include a logic device, some example peripherals (LEDs, switches, maybe some I2C / SPI peripheral), and a programmer device / adapter of some kind. If the programmer unit is external from the target board then you can use it to program custom made or other target boards. If the programmer is built into the target board you man be provided with a header / cable that you can use to connect the output of the programmer to another different target board so you can program something else other than the single kit board. Maybe not though. The fellow that did the Zork FPGA project said he used some$13ish altera cyclone II series FPGA board because it was one of the cheapest FPGA kit boards he could find from some Chinese vendor or something.  I don'tt know if he used an external $15 or whatever clone of the USB Blaster (USB based programming hardware for Altera FPGAs) to program the kit target board or if the target has a USB Blaster on it as well. For$13 I guess maybe it needed an external programmer?

There are cheap FPGA boards based on the Altera: Cyclone II, Cyclone III, Cyclone IV; Xilinx: Spartan II, Spartan III, Spartan 6 LX.
Also ones from Lattice: MachXO2, Mach XO3, ICE40HX series parts.

Some makers of kits include Terasic, Digilent, Arrow (e.g. BeMicro), Altera, Xilinx, and various generic no-name brand boards you can get from ebay / aliexpress.

For your stated long term goals I recommend a low-mid range FPGA kit   board with something like a 25k to 200k LUT or so range FPGA on it.  That is big enough to program interesting MCUs and a little bit of peripherals.  The 25k size part on the Arrow BeMicro is a Cyclone IV (I could be mis remembering) and it was big enough to run the Altera NIOS II 32 bit soft-core CPU created only with programmable logic as well as to have a few peripherals and external bus interfaces to DRAM on the PCB.  Altera's NIOS II soft core is nice along with the Lattice Mico32 cores because they are free to use.  Xilinx has a powerful soft core that is 32 bit called MicroBlaze but I think it is not free to use if you do not use a "7 series" FPGA which limits you to an Artix 7 based board like the "Arty" as far as I know.
There are free 32 bit, 16 bit, 8 bit soft core MCUs you can download and use in a FPGA like the LEON or the RISC V (I think) or OR1K or so on.
Someone recently mentioned buying a nice sounding RISC V  kit that has an open source hardware CPU, I assume that may have been a soft CPU or it could have been a    hard core CPU, I'm not sure.

You can do the address decoding in almost the smallest CPLD you can buy but since ultimately you want to build on that much more at the SOC system on chip level, you should get a device that has room to grow in terms of hardware emulation.

rstofer, hamsternz and others here have done impressive soft computing and other FPGA projects besides the recent Zork device by ... james_s?

Go through the Altera university tutorials or similar content that is free online.  Look at fpga4fun site etc.  Learn some verilog.

#### evb149

• Super Contributor
• Posts: 1666
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #3 on: March 20, 2017, 12:34:07 am »
https://www.eevblog.com/forum/projects/an-fpga-that-you-can-play-zork-on/msg1091319/#msg1091319
https://www.eevblog.com/forum/microcontrollers/i-am-looking-for-an-easy-vhdl-risc-soc/msg464344/#msg464344
https://www.eevblog.com/forum/microcontrollers/sifive-hifive1-(risc-v-based-microcontroller)/
http://store.digilentinc.com/arty-artix-7-fpga-development-board-for-makers-and-hobbyists/
http://store.digilentinc.com/fpga-programmable-logic/
http://store.digilentinc.com/fpga-programmable-logic/system-boards/
http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=163#Category165
http://pipistrello.saanlima.com/index.php?title=Welcome_to_Pipistrello
https://m-labs.hk/m1.html
http://papilio.cc/index.php?n=Papilio.ZPUinoIntroduction
http://www.xess.com/blog/building-the-zpuino/
http://www.fpga4fun.com/

Looks like the RISC-V boards that were referred to use hard core CPUs that have been permanently built as CPUs and can be reprogrammed in SW only but not as a FPGA, which is understandable since SiFive wants a low cost commercially used CPU product and not just a FPGA development kit.  So the RISC-V core IP design which is open source may be interesting ttto see but the kit is not a FPGA/programmable logic kit.

And attribution / congratulations to both  robertbaruch and james_s for FPGA Zork projects:
https://www.eevblog.com/forum/projects/an-fpga-that-you-can-play-zork-on/msg1156686/#msg1156686
http://searle.hostei.com/grant/Multicomp/

#### ALonda

• Contributor
• Posts: 23
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #4 on: March 20, 2017, 12:38:59 am »
Talking about a CPLD or FPGA is way off the mark for this question.

I do have a cyclone II FPGA in the mail coming from china but that would not be part of a breadboard cpu. I could use it to verify a design maybe but it wont achieve my dream.

The idea of using 74xx138 is great. I figure with proper wiring it can be used to verify up to 11 bits for the cost of 2 chips. Better than using AND and (N)OR chips. Would only need 3 chips to cover 16 bits!

/A

• Regular Contributor
• Posts: 59
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #5 on: March 20, 2017, 12:54:10 am »
There are lots of ways to do this.  I'm assuming you want something simple.

Here's how we'd have done it back in "the old days" of SSI.

I'm assuming that you want to decode 16 bits to see if they match exactly one address.
This block of logic has two inputs  IN<15:0>  (16 bits)

Option 1.  Compare each bit of IN to the corresponding bit in ADDR.  You do this with an
XOR gate.  Then check to make sure the output of every XOR gate is false.

That takes 16 XOR gates (like four 7486 chips), 2 8-input NAND gates (2 x 7430) and one 2 input NOR (1/4 * 7402)

Option 2. Build it out of muxes -- this is also known as a poor man's PLA.

It will take four 16:1 muxes (like a 74HC4067 or 74150).  we'll call them U1,U2,U3,U4

U1 select inputs are connected to IN<3:0>
U2 """"" to IN<7:4>
U3        to IN<11:8>
U4       to IN<15:12>

Now this is where it gets a little complicated.
Tie all the data inputs (E0...E15 in the drawing I found at http://ee-classes.usc.edu/ee459/library/datasheets/sn74150.pdf
high by default.   But one of them on each chip will be tied low.

On U1, tie the Ex input low that corresponds to the value of ADDR<3:0>  That is if ADDR<3:0> is 0b1010, tie E10 low.
On U2 tie the bit corresponding to ADDR<7:4>

All of the 16:1 muxes need to have their ENABLE pins tied low.

Now connect all the W outputs to the input of a 4 input NAND.  (7420)

The output of this NAND gate will be LOW when the address matches.

I'm sure you can imagine other ways of doing this with 8:1 muxes or even
decoders and muxes. These are the two obvious ways, assuming 1980's
technology.

I can't imagine using an FPGA for this (and I spent 20+ years as a chip designer).
If this is the only function you need, there are probably a bunch of PLA or
PLDs that can do it.  Your initial notion of a ROM would work too.
------------------------

#### ebclr

• Super Contributor
• Posts: 1989
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #6 on: March 20, 2017, 12:56:42 am »

#### FrankBuss

• Supporter
• Posts: 2310
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #7 on: March 20, 2017, 01:38:21 am »

Problem is to find a chip which is not obsolete. The sn74as885 is not in stock at Digikey and costs a fortune at Mouser. Good idea to search at Digikey:

http://www.digikey.com/products/en/integrated-circuits-ics/logic-comparators/773

Then click "in stock", 108 ICs left. This one looks nice: http://www.digikey.com/short/32dmc9 available in DIP, 2-6V, 8 bit, costs less than a buck.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer

#### ebclr

• Super Contributor
• Posts: 1989
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #8 on: March 20, 2017, 07:16:36 am »

#### Ian.M

• Super Contributor
• Posts: 8143
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #9 on: March 20, 2017, 08:37:28 am »
Assuming you are doing it 'old skool' with a mix of non-programmable SSI and MSI logic, it depends whether you need to decode for one address or for multiple independent addresses.

If its multiple fixed addresses, use a 4 to 16 line decoder for each nibble of the address bus.  Each output represents a decoded hex digit and if you combine one output from each decoder using a four input AND gate (or OR gate if active low), you have a fully decoded address.  Each additional address only needs another four input gate, which at two a package scales well up to the fanout limits of the 4 to 16 line decoders.

#### ebclr

• Super Contributor
• Posts: 1989
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #10 on: March 20, 2017, 08:47:26 am »

#### FrankBuss

• Supporter
• Posts: 2310
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #11 on: March 20, 2017, 09:20:45 am »
This all is in relation to using gates or logics of some sort to determine if a particular 8/16-bit address is on an address bus is of a particular value in order to do a chip enable, or to check if all 8/16 bits of an adder is zero, or in general to validate that all logic outputs from a certain circuit is of a particular value.

I want to create a circuit to set a chip enable if a particular address is on a bus. My best idea so far is using a combination of 4-input NOR and AND gates connected on selected lines but with one of each leaves two outputs needed to be combined with yet another logic chip. so probably one 4-input AND + one 4-input NOR + one 2-input NOR for an 8-bit address input.

I don't get it, how can you check a particular value with these chips? I guess the datasheet of the 74688 shows the simplest solution: A bunch of 2 input XNOR gates, like the 74LS266, and then combining the outputs with AND gates, and NAND for the last stage, if you want output low on match. For 8 bits you would need 2 x 74266 XNOR gate chips, 2 x 7421 AND gates and one 7400 NAND gate.

Quote
I have tons (60+) old 4K proms I could use but no programmer/eraser equipment.

I can recommend a MiniPro TL866, I have one. Dave tested it, too. You can get it from eBay. Nice about using an EPROM is that you need only one EPROM to decode many different addresses. You can use d0-d7 for 8 different chip selects.

Quote
I imagine diodes would work in place of (N)OR?

Just connecting them together without anything I expect would work (in place of (N)ORs but if one output was high and the other low, alot of current would go to waste. (?)

With diodes you can implement OR and AND gates, see https://en.wikipedia.org/wiki/Wired_logic_connection The disadvantage is that it is slower than using gates, if the pullup or pulldown resistor is too high, because of parasitic capacitance, or power consumption is higher, if you use lower value resistors. And the fan-out is not so good.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer

#### rstofer

• Super Contributor
• Posts: 6757
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #12 on: March 20, 2017, 06:52:48 pm »
The bad thing about EPROMS is that some of them are seriously SLOW.  The venerable 1702, for example, needs 900 nS from CS' to data out.  This delays the address decoding for every device it selects.

You need to get something with a delay of 10 nS or so.  So, can your CPU load the memory map into some kind of fast RAM?  Boot from a piece of flash that sets up the memory map and then maps itself out at some point.

Not much different than a MMU, really.  I haven't even thought about the block diagram...

#### james_s

• Super Contributor
• Posts: 10200
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #13 on: March 20, 2017, 07:14:21 pm »
Look at existing 8 bit computer designs from the late 70s-80s for lots of examples of how to do it. Classic arcade games are good for this too, manuals are available for most with full schematics.

#### kony

• Regular Contributor
• Posts: 239
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #17 on: March 21, 2017, 12:24:15 am »
Drop some CPLD on that.
Lately each time I'm facing using more than single 74xx chip other than trivial combinatoric gate, I rather put there some of the XC95xx - price difference is basically nill, and the crossbar matrix makes PCB layout so much simpler that it is worth the JTAG programming fuss.

#### BrianHG

• Super Contributor
• Posts: 3495
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #18 on: March 21, 2017, 01:42:24 am »
2 of these will give you 16 bits, you might need an inverter to invert the output if you want positive logic.
You don't need any other ICs.

+1 chip to combine the 2 outputs.
74138 can do 16bits matching in 3 chips at about half the price.
But would need cmparators to compare two values for branching and such

/A
Take the output of one and feed it into the output enable of the second.  No need for another chip.  That oe is not a tristate, but was placed there to bridge these ICs.
__________
BrianHG.

#### ALonda

• Contributor
• Posts: 23
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #19 on: March 21, 2017, 02:57:05 am »
Take the output of one and feed it into the output enable of the second.  No need for another chip.  That oe is not a tristate, but was placed there to bridge these ICs.

Youre right, but still, 3x 74138 only cost 42cents while 2x 74521 cost \$1.3

Ive ordered 20x 74138's and put 10x 74521 in my shopping cart

/A

#### rstofer

• Super Contributor
• Posts: 6757
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #20 on: March 21, 2017, 01:37:44 pm »
Have you worked out the delay through the decoder chain?  How does this affect the cycle time of devices?

#### FrankBuss

• Supporter
• Posts: 2310
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #21 on: March 21, 2017, 01:44:15 pm »
If he builds his own computer, he can clock it as slow as he want
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer

#### rstofer

• Super Contributor
• Posts: 6757
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #22 on: March 21, 2017, 07:04:54 pm »
If he builds his own computer, he can clock it as slow as he want

Sure, but there are no bonus points for making things slower!  Nobody ever went to the store asking for a slower computer!

#### james_s

• Super Contributor
• Posts: 10200
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #23 on: March 21, 2017, 08:25:04 pm »
I do remember having to use software that deliberately slows down a computer though in order to run older games that ran too fast. Haven't had to do that for a long time though.

#### rstofer

• Super Contributor
• Posts: 6757
• Country:
##### Re: Logic gates to select single values on an 8/16-bit bus
« Reply #24 on: March 21, 2017, 09:31:55 pm »
I do remember having to use software that deliberately slows down a computer though in order to run older games that ran too fast. Haven't had to do that for a long time though.

That was always a consideration for text based games.  The programmers had to make the player believe they were challenging the machine.
It was disconcerting when the teletype rattled off the response immediately after pressing return.

Smf