Logic Gates with NAND Gates (and the 7400 chip)

This will be a short post… but useful. You will learn how to build different logic gates with just one chip (or several… but the same kind).
Of course… I will not use just this chip in my project… but this will help you understand how to do it if you want.

In the previous posts I showed you how the NAND, NOT and AND gates works, and I promised to show you how to create the last two with just the first one.

Well, we are going to use a 7400 chip, in my case I usually use the 74LS00 chip, but it doesn’t matter for this example. The first 2 digits are the family (7400), the 2 letters are the subfamily (if none, they are the original ones), and the last digits are the actual component, in this case 00 is a quad 2-input NAND gate.

Yo already know the NAND symbol, you can see that there are 4 of them inside this chip. VCC is for positive voltage, and GND is for ground.

If we play a little with this pins, we can create the NOT and NAND Gates, as you can see in the following picture, in the bottom we connect the pins 1 and 2 (d3 and d4) which are the inputs of one of our NAND gates, and the 3rd pin (d4) which is our output, will become a NOT gate, our first INVERTER (line 5 at the bottom of our breadboard)

On top of that we are using 2 NAND gates, the inputs (lines 4 and 5 at the top) are not connected, but the output of this first NAND gate, pin 11 (g6), is connected to both inputs of the next one at pins 10 and 9 (g6 to h7 and h8) which we are using as an INVERTER too, and we know from our previous post that NAND + INVERTER = AND, which is our output at pin 8 of our chip (line 9 on top of our breadboard)

We can also use the output of the top NAND to the combined input of the first INVERTER too, but I wanted to show you both examples in the same breadboard :). These chips are less than 1USD a piece, we are not going to worry about using more NANDs than needed… at least for now.

We have more Logic Gates to learn…. OR, XOR, NOR and XNOR. Let’s see the tables for input and output for each one (and how to build it with NAND gates, just the diagram, I’ll let you play with the 7400 chip and figure it out).
Of course… there are 74?? chips with each one of this gates, we are just using the NAND as an exercise. But I promise… it will be easier in the future

OR Gate
A B A OR B
0 0 0
0 1 1
1 0 1
1 1 1

If ANY of the inputs are 1 (or both), the OUTPUT will be 1.

XOR Gate (Exclusive OR)
A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

If A or B are 1 (but not both), the OUTPUT will be 1

We need all 4 gates of the 7400 to build a XOR gate
We need all 4 gates of the 7400 to build a XOR gate.
NOR Gate
A B A NOR B
0 0 1
0 1 0
1 0 0
1 1 0

ONLY when A and B are both 0 the OUTPUT will be 1

XNOR Gate (Exclusive NOR)
A B A XNOR B
0 0 1
0 1 0
1 0 0
1 1 1

When A and B are the same (0 or 1) the OUTPUT will be 1

How does it work? GATES!!!

Ok, it’s time to start this. Of course… I have already made some progress, and I will do this in parallel with the actual build, so, it will take a while until the blog reaches the actual status of the computer… but… I have to start writing at some point.

I’ll start with GATES!. Why? First, because I want to. Second, because it’s the smallest piece of hardware with some logic and actual application in programming. Yes… we can go with smallest pieces, but trust me, gates will do. Also we need to start talking about, what a computer actually does, and how fast.

REGARDING SPEED

The main goal of a computer is… to compute things… and do it fast… but, how fast? Well, really fast, but the problem is not just showing a text in a millisecond, but it goes way beyond that.
Usually you use a programming language, which is a “human” readable way of programming. A computer does not understand that, instead it moves 1s and 0s really fast. Showing just a simple character on display may take just one line in your programming language of choice… around 10 in assembly language… and maybe a hundred in microcode.
Just showing “Hello World” in screen may take one thousand microinstructions… that will be executed… FAST.

One quick example, simplified of course : loading a byte from RAM into the Accumulator : LDA in assembly.

In “microcode” it would look something like this assuming we just booted our computer, assuming it starts from location $00

  • READ FROM LOCATION $00, LDA
  • READ FROM LOCATION $01 THE DESIRED RAM ADDRESS AND STORE IT IN MEMORY ADDRESS REGISTER (MAR)
  • ENABLE MEMORY OUTPUT FROM STORED LOCATION IN MAR
  • ENABLE ACCUMULATOR INPUT
  • INCREASE PROGRAM COUNTER

So… at least 5 microcode steps, for loading a single value from RAM, assuming just 8 bit addressing. The amount of microcode steps will be increased if the address is larger, and obviously… I’m ignoring a couple of steps, a CPU has dozens of components that must be in sync, and turned on and off in perfect harmony.

We will discuss assembly and microcode in a future post, but you can get a small idea regarding speed.

REGARDING GATES

We have a door, with locks… we need to be secure that the door is well shut, you know… you have the door open… insects come in… some stray dogs… maybe a moose… the mailman… You need to close your door!.
This are tricky locks, because… you have to combine them in a specific way to actually close your door.  In our case… only when both locks are in OPEN position, the door will be closed.

LOCK 1 LOCK 2 DOOR
CLOSED CLOSED OPEN
CLOSED OPEN OPEN
OPEN CLOSED OPEN
OPEN OPEN CLOSED

Again… only when both locks are in OPEN position… the door is CLOSED

This is a type of GATE called NAND, or Not AND. Some thing like “When 1 is NOT open AND, 2 is NOT open… then… open”. If we change OPEN for 1 and CLOSED for 0 the table will look like :

A B Y (OUTPUT)
0 0 1
0 1 1
1 0 1
1 1 0

All GATES have a symbol, for NAND gate this is the one :

The small circle at the end is the “NOT” part, so each time you see that small symbol you can safely assume it’s a NOT kind of gate

But… why I’m showing this GATE first and not one of the others. Because you can create ANY kind of gate with this one.

Let’s create another one… just a NOT GATE. This is a gate that has only one input, and just inverts it, that’s why is also called an INVERTER.
How can we create a NOT gate with a NAND ? Well, simple, just send the same value to both inputs.

A Q
0 1
1 0

Simple!, and this NOT gate has a symbol:

See ? the small circle at the end?

Ok… this is a long post so I’ll just add one more gate. The AND gate, in which when if only both inputs are 1, the output will be one.
Again… we can build it with NAND gates…

You can see… it’s a NAND gate… and the output goes to both inputs of a 2nd NAND gate… or an NOT gate as we saw before.
Let’s look at the value table (truth table from now on)

A B OUPUT 1 Q
0 0 1 0
0 1 1 0
1 0 1 0
1 1 0 1

So that’s all for today. Next time I’ll introduce to you the 7400 chip series that I will use for building my homemade computer. And of course, will show to you some diagrams about building the NOT and AND gates, with one of those chips.

See you next time!!!!