Digital Electronics Fundamentals 4: Universal Gates

There are certain logic basic gates that can be used to reproduce the functionality of any other gate. To do that, these gates need to be able to do inversion in addition to their basic functionality. They are the NAND gate and the NOR gate. In this article, we will examine how that can be achieved.

NAND, NOT, AND

Let’s start with the NAND gate.

NAND gate

If we tale a look at the truth table of such gate, we find that considering only the first and the last row of it, it behaves exactly like a NOT gate.

To make it work, we just need to put together the two inputs of the gate, and it will work as an inverter.

NOT from NAND

Given that, we can easily build an AND gate out of two NAND gates. The first gate provides the NAND function and the second provides a NOT function that converts the NAND into an AND.

AND from NAND

At this point, before showing how to create any other gate from the NAND gate, we have to enounce the De Morgan theorem, which will allow us to manipulate the boolean expressions of the various gates to convert them into a number of NAND gates connected together.

De Morgan Theorem

The theorem states that we can convert a NAND operation into an OR operation, and we can also convert a NOR operation in to an AND operation, according to certain rules. Here is the theorem expressed in boolean algebra:

De Morgan Theorem

If you like to verify that the theorem holds true, just build the truth table for the right side of each equation and compare it with the truth table of the corresponding left side, which are respectively a NOR and a NAND truth table. The tables on the two sides should be identical.

OR from NAND

Let’s see now how we can make an OR gate using a circuit with only NAND gates.

Here is the symbol of the OR gate:

And here is its truth table:

Let’s now write down the boolean expression for the OR gate and let’s apply to it the De Morgan theorem so we can convert everything to AND and NAND.

The one on the right is the boolean expression of the OR gate expressed in terms of NAND gates, and we can convert it in to a digital circuit like this:

OR from NAND

Again, to prove that this circuit really behaves like an OR gate, we can deduct its truth table and compare it with the one of the actual OR gate. If they are identical, this circuit effectively mimics the OR gate. try yourself and, if you have difficulties, please take a look at the companion video on YouTube. The link is at the end of this post.

NOR from NAND

Like we did for the OR gate, we could determine the boolean expression of the NOR gate and find how to build the circuit that mimics it. However, since the NOR gate is essentially the same as the series of the OR gate and the NOT gate, we cna just reuse the previous circuit and add the NOT at its output, as in the following picture:

You can demonstrate the correctness of this circuit by comparing again, its truth table with the one of the NOR gate.

XOR from NAND

To convert the XOR gate in to a combination of NAND gates, we need to start from its truth table:

Now we can write down the boolean expression of the XOR gate by referencing to the lines of the truth table that have an output of one, like we have seen in the previous episode. One we have the XOR boolean expression, we can manipulate it using De Morgan to obtain a form that can be described with NAND gates only:

And, finally, we can draw the digital circuit corresponding to the rightmost part of the above boolean expression:

XOR from NAND

And this is the circuit that mimics the XOR gate using only NAND gates. And guess how we can prove that?

XNOR from NAND

For the XNOR gate, we could just add a NOT at the output of the previous circuit. However, we can use one less NAND gate if we redo the whole procedure we made for the XOR gate.

Here is its truth table:

Here is the derived boolean expression appropriately manipulated:

And here is the corresponding schematic made only of NAND gates:

XNOR from NAND

NOR, NOT, OR

Let’s now talk about the other universal gate: the NOR gate.

NOR gate

Here is its truth table:

And we can see from there that connecting together the two inputs we obtain, like with the NAND gate, a NOT function.

NOT from NOR

Given those two ports, it is easy to implement the OR gate:

OR from NOR

Do you see the similarity with what we have done with the NAND gate? At this point we can easily proceed with generating all the other basic ports using a similar procedure, with the only difference that we will now use the second part of the De Morgan theorem, rather than the first.

AND from NOR

Boolean Expression
AND from NOR

NAND from NOR

NAND from NOR

XOR from NOR

Here is the XOR truth table:

Truth Table

Let’s now derive the boolean expression from this truth table. This time, however, it is more convenient to work with the zeros of the table, for which we will use OR operations, and the OR operations will be ANDed to each other and the whole expression is manipulated to obtain all NOR gates, like this:

XOR from NOR

XNOR from NOR

Similarly, from the XNOR truth table we have:

XNOR from NOR

Conclusion

I would finally like to remind you that this series of tutorials is also backed by a corresponding video series available on YouTube. The following page provides the links to the YouTube Videos, as well as the link for the whole series, and the links to all the files involved in the tutorials, with schematics and anything else that might be needed:

Advertisement

Digital Electronics Fundamentals 3: XOR and XNOR gates

After going through some basics in the previous episode, today we will look at a couple of more gates and, with that excuse, we will see how to use truth tables and some simple Boolean algebra to design a logic circuit.

The XOR Gate

Let’s begin by talking about the XOR gate.

Here is its truth table, which describes how this gate works:

You can see how whenever the two inputs are different, the output is a 1, and it is a 0 when the inputs are different.

We could say that this kind of gate tells us if a number of digital signals are all the same or are different.

The XOR port is available in integrated circuits that contain a number of them, like this one in the picture. And from the picture you can also read the full name of the gate: the Exclusive OR. Another way to say that the circuit provides at its output an OR operation, but exclusively if the inputs are different. Like they say, if one or the other is at 1, but not both.

Let’s see now how we can draw the schematic of such circuit starting from the truth table. There are two methods to use. The first one is to look at all the rows that have a 1 at the output. We will look at the other method in a later episode.

So, here are the two rows that have ones on the output:

Let’s look now at the corresponding inputs. For each of these two rows, we write the name of the input as is, if it is represented by a 1, and as a NOT input if it is represented by a 0.

For the first of the two rows, we therefore write

And yes, we consider this as an AND operation, so we write down the two inputs as if they were multiplied by each other.

Now we are going to add to this expression the one for the other row that has an output of 1. Keep in mind that when we say “add” in boolean algebra, we intend the OR operation.

Following the same rule we used for the first raw, we then write:

The result of this whole operation is our output U:

We have now a Boolean expression that can be easily translated to a schematic, if we just keep in mind what each of the symbols represents.

And this is the schematic of the XOR gate, made with 2 AND gates, 2 NOT gates, and 1 OR gate.

We can quickly double check if this circuit works really as described by the truth table.

Consider first the rows with an output of 1. In them, A and B are opposite. And now look at the circuit. Because in each AND we get both A and the opposite of B, we can be sure that we are inputting two identical values, either both zeros or both ones, on each of the two ports. And while we are inputting both 0s on one port, the other port gets both 1s, and vice-versa. The result is that one AND gate will have an output of 1 and the other will have an output of 0. And since these outputs go to the OR gate, the output of the OR gate will be 1 in both cases.

If we look now at the rows of the truth table where the output is 0, you’ll see that the inputs are either both at 1 or both at 0. Back to the schematic, if A and B are both 1 or both zero, each of the AND gates will have at their input a 1 and a 0, because of the presence of the NOTs. Therefore, the two AND gates will both have, simultaneously, an output of 0. And since these are the inputs of the OR, the output of the OR will be 0 in both cases.

The XNOR Gate

Let’s now work on the XNOR gate.

Here is it’s truth table:

since this is a NOT XOR, the outputs are exactly the inverse of the XOR gate.

As such, when we refer to the symbol for the XNOR gate, we just draw the one for the XOR gate and then we put a NOT at its output.

Like with the XOR gates, we have ICs that can provide multiple XNOR gates, like this one in the picture, which provides 4 gates with 2 inputs each:

Let’s now repeat the previous exercise to draw the schematic for this gate. These are the rows that present a 1 at their output.

For the first row, since both A and B are at zero, we have to write NOT A and NOT B. Then we write the OR symbol, and then we add the part relative to the second row with an output of 1. In this case, both the inputs are at 1, and so we simply write down the names of the inputs. This boolean expression now represents the truth table for the XNOR, so we put it equal to U.

And here is the corresponding schematic:

We can verify that this circuit satisfies the truth table, by noticing that while one of the two AND gates takes A and B, the other one takes NOT A and NOT B. As a result, only if A and B are exactly the same, one of the two AND gates will output a 1. Otherwise, if A and B are different, the AND gates will always have a 0 and a 1 as inputs, which will cause them to output a 0. And so, in the case A and B are the same, the OR gate will receive a 0 and a 1 at the inputs, therefore giving an output of 1. Instead, in the case where A and B are different, the OR gate will receive 0 on both inputs, therefore giving a 0.

Conclusion

Whenever you have a truth table that describes a certain logic function, is always possible to write the Boolean expression equivalent to the truth table, and from that, we can finally draw the schematic for such function.

Note also that if we have a truth table with more than 2 inputs, we can still go through the exact same procedure, just keep in mind that we will need gates with more than 2 inputs.

And finally, I would also like to remind you that this series of tutorials is also backed by a corresponding video series available on YouTube. The following page provides the links to the YouTube Videos, as well as the link for the whole series, and the links to all the files involved in the tutorials, with schematics and anything else that might be needed:

Digital Electronics Fundamentals 2: Basic Logic Ports

Let’s talk a little bit of logic ports, how they can be made with discrete components, and how to use the premade one available as integrated circuits.

All of this, while learning a thing or two about Boolean Algebra, which is very useful both for designing and analyzing digital circuits.

The NOT Gate

Let’s start with the NOT gate, the simplest form of logical port.

The little circle on the right is the actual symbol for the not operator. The rest of the symbol represents just an active component, an amplifier in particular.

And, in fact, the NOT gate is made of a simple transistor polarized in such a way that it works in only two possible states: OFF, where it does not conduct any current, and ON, where it does conduct enough current to be in saturation. And to obtain this behavior, we just need a couple of resistors: one on the collector, to limit the maximum amount of current, and one on the base, to limit the current that goes through the base-emitter junction when the base is positively polarized.

Let’s now figure out how it works.

If we put a positive voltage in A, basically the +Vcc, the transistor will be ON and a current will flow between collector and emitter, limited only by the resistor on the collector. Because of that, the output U will be at about the ground level.

If we connect A to ground, instead, the transistor will be OFF, or open, and there will be no current flowing through it. As a result, U will find itself at the positive voltage +Vcc.

Remeber now that we associate the +Vcc to TRUE, or the number 1, and we associate the ground level to FALSE, or the number 0.

With such information, we can build what is called a truth table, which is a table that represents how a logic circuit works. In this case the NOT gate.

To build this table, we list all the input symbols on the left side, and all the output symbols on the right side.

In this case, we have only one input, A, and one output, U.

Then, we write on the left side of the table all the possible combinations of ones and zeros on the inputs. In this case, since there is only one input, we will have only a 0 and a 1.

Last, on the right side, we write the output values corresponding to the inputs on the same line. Again, in this case there will be only a 1 and a 0.

This table, now tells that every time the input is at 0, the output is at 1 and, viceversa, every time the input is at 1, the output is at 0.

This logic function, therefore, does just one simple thing, it generates an output that equals the inverse of the input. And, for this reason, the NOT gate is also called Inverter.

Using the boolean algebra, we can define for each basic logic function a specific symbol. For the NOT function, or inverter, the symbol is simply a dash on top of the name of the input or output.

So, using the boolean algebra notation, the NOT function is represented like this:

This notation doesn’t seem to be important, right now, but you’ll see later how important it becomes when we need to design logic circuits.

For the everyday use, NOT gates are usually available in the form of integrated circuits that contain a number of them.

This IC needs a power supply of +5V, since it belongs to the TTL family, and it contains six NOT gates.

The NAND Gate

The symbol of the NAND gate is made of two parts: the NOT gate, which is the circle at the output of the symbol, on the right, and the AND gate, which we will talk about later.

Let’s see how we can make one with discrete components, which will help us understand how it works.

In this case we have two inputs and one output.

If both inputs are at 0, both transistors will be OFF and no current will flow through them. As a result, we will have a 1 at the output.

If one of the inputs is at 1 and the other one is at 0, one transistor will be ON and the other one will be OFF. And since they are connected in series, there will still be no current flowing through them. The output will still be at 1.

But now, if both inputs are at 1, both transistors will be ON and the current will be able to flow through them. And this will bring the output level toward ground, or a logic 0.

Here is the corresponding representation with a truth table:

And here is a typical IC carrying 4 NAND ports:

The AND Gate

And now let’s see why we have talked first about the NAND gate instead of the AND. Look at how it is made with discrete components:

Yes, you can see now that although logically the NAND gate is made with an AND and a NOT gate, building such gate works exactly the opposite. With discrete components, we need the NAND gate and a NOT gate to make an AND gate!

This is because a transistor is intrinsically an inverting amplifier and, therefore, it’s natural use is the NOT gate. Whenever we try to build a port with transistors, it will come out with inverted logic, and so building a NAND is actually more straightforward than building an AND.

And now that we have seen how to build the truth table for the NAND gate, it seems natural to obtain the truth table for the AND gate just by inverting the output. And you can easily verify that following the signals on the previous circuit.

Look closely at the table now. The AND function actually resembles the well known multiplication function. In fact, the boolean AND is identical to the classic arithmetic multiplication, but in an extremely simplified way, because there are only two digits in boolean arithmetic.

Given the resemblance, we usually represent the AND operation in the same way as we do with the arithmetic multiplication:

And now that we have a boolean representation of the AND operation, we can define the representation of the NAND, just by recalling that the output is the inverse of the AND:

Another interesting thing is that building a NAND gate is easier than building an AND gate also for TTL integrated circuits. It is not by chance that the first in the list of the TTL ICs is the NAND gate itself.

Regardless, here is the pinout of a TTL IC providing 4 AND gates with 2 inputs:

The NOR Gate

Let’s now examine another kind of port. With the NAND gate, we connected the two transistors in series. Let’s see now what happens when we connect them in parallel.

So we have the first transistor with its two resistors.

Then we add another transistor, but we connect its collector directly to the one of the first transistor.

And then this second transistor has its own input.

The output is taken on the two collectors.

Let’s see how it works.

With a zero on both A and B, both transistors will be OFF, and therefore will not draw current from the resistor at the collectors. The result is that the voltage at the two ends of the resistor is the same, which means that the voltage at the collectors is +Vcc, or a logical 1.

Putting now a 0 on A and a 1 on B, the transistor on the left will be OFF, while the transistor on the right will be ON, so it will behave like a closed switch.

This transistor will then drain current from the resistor on top, causing the output to go low, which is the logic 0.

Putting a 1 on A and a 0 on B will sort a similar effect. But now the transistor ON is the one on the left, and the transistor OFF is the one on the right.

So, this time, the current will flow through the transistor on the left and the output will still be a 0.

Finally, a 1 on both inputs causes both transistors to be ON and, therefore, the output U will once again provide a 0.

The behavior presented by this circuit is called NOR function, and the device is a NOR gate which has this representation made with 3 arcs and the circle that represents the NOT.

This is instead its truth table:

And here is the pinout of a typical IC providing 4 NOR gates with two inputs each:

In boolean algebra, we represent this function as:

And yes, it looks like the inverse of the addition. But note that in boolean algebra, the value of 1+1 is still a 1. And this is something important to remember. We are talking about logic operations here, not arithmetic operations. If one thing is true and another one is also true, if we put them together we still have a true.

The numbers 0 and 1 are used for convenience, but they do not represent actual numbers, just logic states.

The OR Gate

Let’s now make the OR port.

Similarly to what we did with the AND gate, we will make first a NOR port, and then we will attach at its output a NOT gate.

And now that you are good at it, try to verify on your own that this is the truth table for the OR function:

Here is the symbol of the OR gate:

And here is an IC with 4 ports inside:

Finally, the boolean representation of the OR function:

And remember: this is a logical expression, not an arithmetic one. Therefore: 1+1 = 1.

Conclusion

So, today we have seen 5 different logic gates, or ports: The NOT, the NAND, the AND, the NOR, and the OR.

We have also seen how it is easier to build inverting gates, because of the way transistors actually work.

And we have seen that obtaining in practice non-inverting ports requires more components, so we reach the paradox where simpler logic ports have a more complex implementation.

Now that we have the basics, next time we will start looking at something more complex, obtained as a combination of 2 or more ports of the kind we have seen today.

This series of tutorials is also backed up by a corresponding video series available on YouTube. The following page provides the links to the YouTube Videos, as well as the link for the whole series, and the links to all the files involved in the tutorials, with schematics and anything else that might be needed:

%d bloggers like this: