## 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:

Advertisement

## 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:

## Digital Electronics Fundamentals

This is the first of a new series of tutorials, with hands on experiments, to learn the basics of digital electronics. We will go together from the very basics information and we will move on illustrating first the building blocks of the digital circuits, and then continue the discussion introducing circuits more complex, like flip-flops, couters, multiplexers, and much more.

In each episode of the series we will add a little theory to the pile and will showcase simple digital circuits that you can build for a hands on learning experience.

In this blog, as a start, we will go through some important definitions and then I will provide you all you need to build a device that we will use a lot in the future episodes of this series: the logic probe.

This series of tutorials will also be 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 link to all the files involved in the tutorials, with schematics and anything else that might be needed:

https://eleneasy.com/digital-electronics-fundamentals-articles-and-video-archives/

## What is Digital Electronics

Digital Electronics is that branch of Electronics that involves the use of circuits that are capable of dealing with only two voltages, as opposed to Analog Electronics that works on circuits that handle voltages in an infinite range.

An example of analog electronics is a classic FM radio, which works with radio waves and produces sounds made of a continuous signal that can assume any value within the limits of the power supply of the circuit.

An example of digital electronics is the CPU of a computer, that deals with signals that can assume only two values, usually named Low State and Hgh State, or Low and High for short.

Circuits in the analog world are made of resistors, capacitors, inductors, transistors, and so forth.

Circuits in the digital world are made of logic gates, also know as logic ports, which are basically made with transistors working in the saturation region, so that they can be only off or on, therefore delivering only two possible signals: low and high.

Besides the possibility of actually making logic ports with transistors, we normally use pre-made ports packed in integrated circuits.

And, finally, while we sometimes need to use complex mathematics to deal with analog circuits, in the digital world we use only Boolean operators, which behave very similarly to the arithmetic operators like plus and minus. This actually helps a lot, because it is much more simple to deal with digital circuits than it is with analog circuits. Well, of course this is more of a subjective statement. Somebody might disagree on that.

## Families

For the most part, digital circuits are available in the form of integrated circuits.

There is in fact a great compatibility on this kind of components, although made by different manufacturers. The thing is that digital circuit and signals are standardized, so it is easy to mix and match components from different vendors to build a specific circuit.

There is one thing, though, that we need to be careful about.

We said that logic ports are made of transistors. But there are different type of transistors. In particular, we use the bipolar transistors (BJT) and the field effect transistors (MOSFET).

With the bipolar transistors we can build logic circuits usually named TTL, or Transistor-Transistor Logic. These circuits are essentially made of transistors and resistors.

With field effect transistors, we can use together n-channel and P-channel MOSFETs to create simple logic gates.

Because we mix together p- and n-channel MOSFETs, the technology used by these transistors is named C-MOS, or complementary MOS. For each port we use one n-MOS transistor and one p-MOS transistor. One is the complement of the other. No resistors involved.

Digital circuits that use these components are said to be part of two different families: the TTL family and the CMOS family.

Why there are two of them?

Well, the first digital circuits were RTL and DTL, now obsolete, followed by TTL. They used a lot of space on the chip dies because they had to implement also the resistors to correctly polarize the transistors in the saturation zone.

Once the MOS technology became easier to use, the CMOS logic ports were created. In these, the two transistors are usually connected one against the other, so that when one is on the other one is off. This eliminates the need of resistors, since the off transistors, when off, behave like infinite resistances. It also reduces drastically the power needed to make the circuits work. A CMOS circuit can easily consume between 1,000 and 1,000,000 times less power than the corresponding TTL circuit.

In addition, CMOS circuits use less space on the die, allowing putting more components than TTL circuits in the same space, as you can see from these pictures.

There is a catch, though. CMOS devices are more difficult to handle because they are very sensitive to electrostatic discharges, and so they can break just by holding them in your hands.

In the simpler integrated circuits, there are protections in place on the die itself to limit the problem, but bigger devices, like CPUs, are very sensitive to electrostatic discharges, and so they need to be handled with extreme precaution.

In this series we will examine both TTL and CMOS technologies.

The TTL family is greatly used when there is a special need for speed, since the CMOS equivalents are slower, due to the intrinsic capacitance at the gate of the MOS transistors.

CMOS, however, use less space, and so their technology is preferred when building very complex devices, like a CPU.

And there is also a trend of building CMOS transistors smaller and smaller on the die. Smaller transistors have a smaller gate and, therefore a smaller capacitance, which leads to greater speed.

One last thing that differentiate the two families is the supply voltage.

The TTL family is usually limited to a supply voltage of +5V.

The CMOS family can be powered on a vast range of voltages, typically between 1.5V and 18V.

## Logic States

Let’s now go back for a moment to the logic states.

We have already said that all digital devices work on two states only, the high state and the low state, and they are associated with the supply voltage and the ground reference respectively. Any other value of voltage at the input or output of the logic devices is not supported. Or is it?

Well, sometimes, because the way a circuit is built, it is not possible to achieve exactly those voltage levels. What do we do then?

Put it simply, we define an acceptable range, and we say that all digital devices have to accept anything in that range as a high level. And we do similarly for the low level.

Now, thanks to this requirement, all the vendors that build digital devices, and follow such requirement, can be sure that their components will be compatible with similar components from other vendors, and so will be all the customers that buy these components. Welcome to standardization!

And now that we have established that digital devices work within voltage ranges rather than exact voltages, we can define a better way than call those states high and low, so nobody will get confused, because they won’t need anymore to think in terms of ranges.

The adopted way to do so is to use the terms of the boolean algebra, which was invented by George Bool way before the digital circuits were invented. George Bool created such algebra as a way to easily solve complex logic problems. He realized that any logic statement can be described to be either true or false. Combining several statements becomes then a matter of operating with these two states of true and false and, therefore, the analysis of several concurrent statements can be done simply by operating appropriately on these two states.

And so, thanks to that visionary mathematician, today we tend to associate the state TRUE with the high state of the digital circuits, and we associate the state FALSE with the low state.

And then came the engineers, and they said: why in the world we need to use TRUE and FALSE as the values for making calculations? Why don’t we use just numbers? We can associate the state TRUE with the number 1 and the state FALSE with the number 0. And we already have binary arithmetic, so we can easily converge these two concepts.

And that’s why today we use the values of 1 and 0 when we work with digital electronics.

With ones and zeros, we can create a so-called abstraction layer when we do digital circuits design. We can ignore the fact that we are working with TTL circuits or with CMOS circuits, so we don’t have to worry about voltage values which, we know, are not the same with the two families of circuits.

Only when the design of the logic is done, and we need to implement it in circuits, then and only then we translate ones and zeros in voltages.

And because we have a standard to follow, everything will work just fine.

From the first two rows of this table we can see that for TTL circuits, which are powered with 5V, everything above 2.3V is a logic 1, and everything below 0.08V is a logic 0.

For the CMOS family, since these devices can be powered at different voltages, we have a 1 when the voltage exceeds 70% of the value of the supply voltage, and we have a 0 when the voltage is below 30% of the value of the supply voltage.

We won’t talk for now about other details on these families, but we will get back to that in the future.

## Measuring The States

OK, now the problem is: how do we take measurements of digital signals?

Can we use a multimeter? Of course we can, but then we need to remember the specs to make sure that the voltages we read are within the required ranges to be a 1 or a 0. Possible, but not practical.

Can we use an oscilloscope? Same thing: we read voltages, and we need to convert them in our mind to figure out if they are ones or zeros.

And so… is there a practical way to make measurements of digital values?

But of course there is. There are at least two ways.

Way number 1.

We use a so-called logic analyzer. It is like an oscilloscope, but it is capable of making all the calculations to see if the voltages are in the correct ranges to be a 1 or a 0, and then they show directly a wave signal that represents only those values as Vcc or ground; no ranges whatsoever. These devices have also several channels, so you can usually watch 16 or more digital signals at once. That is very practical but… logical analyzers cost money. They cost at least like a good multitrack oscilloscope.

What if we don’t want to spend that amount of money to work on our small projects at home?

Well, in that case…

Way number 2.

We use a so-called logic probe. A logic probe is a small device, capable of testing just one single signal at a time, and tells us if that signal represents a one or a zero using just a pair of LEDs.

There are logic probes capable of doing that on TTL signals, and there are those that are capable of doing that on CMOS signals.

I’m going to show you now the schematic of one that can do both, one that is capable of measuring both TTL and CMOS signals. And you can build one with just a few bucks, it is a very cheap device. To see how to make one, please head to the corresponding video on YouTube, accessible through this page:

https://eleneasy.com/digital-electronics-fundamentals-articles-and-video-archives/

Only when you outgrow this device, because you start working on complicated circuits that require watching multiple signals at once, you will have to buy and use an actual logic analyzer. Until then, this little device will do its job very well for many years to come. Even if you, one day, decide to buy a logic analyzer, the logic probe will still be there for you to use when you don’t need the whole power of the mighty logic analyzer.

That said, let’s take a look at the schematic of such a useful device.

## The Schematic

Our logic probe is built around a couple of voltage comparators, part of an integrated circuit that contains 4 of them. We are not going to use the two extra ones.

Why comparators? But, of course, to be able to measure voltage ranges, so the device will take care of making all the conversions between voltages and the logic levels.

The device will be powered by the same circuit under test, so it will be able to know what the value of the supply voltage is, and make its deductions in terms of converting the voltages in logic states.

The diode D3 is there to prevent the circuit from burning out in case we reverse the polarity when we connect the device to the circuit under test.

The tip of probe, on the left, sends the input signal we want to measure to the two comparators. The one on the top will measure the upper range, to see if the voltage is equivalent to a 1. We will therefore connect the probe to its inverting input, while on the non-inverting input we will put the minimum voltage of the range. Whenever the voltage at the inverting pin will exceed the voltage at the non inverting pin, the output of the comparator will go low, turning on the LED D1, which we will choose of red color.

Similarly, to detect a zero, we apply the input voltage to the non-inverting input of the second comparator. The inverting input, instead, will be connected to the maximum possible voltage of the range that represents the zero. This way, whenever the input signal is lower than the signal on the inverting input, the input of the comparator will go low and will turn on LED D2, which I have chosen to be green.

We also have a switch that allows us to change the reference voltages for the comparators, depending on the logic family we are working with: CMOS or TTL. For CMOS circuits, we set the switch to open, and the voltage dividers made of R7 and R8, and the one made with R5 and R6, will generate the 70% and the 30% of the supply voltage, which are the range boundaries of the digital signals.

For TTL circuits, we will close the switch, which will put a couple more resistors in parallel to those that make the voltage dividers. These new resistors, when the probe is powered with 5V from the circuit under test, will make sure that the reference voltages will be the ones for the TTL circuits: 2.3V for the 1 and 0.08V for the 0.

To use the device, we set the switch on the appropriate position, then we power the probe connecting it to the power supply of the device under test, then we use the probe terminal to read the signals. Depending on the LED that will turn on, we will know if the signal was a 1 or a zero. And if no LED turns on, it means that there is no signal, or that the signal is not in the correct range to be a valid 1 or 0.

We are going to use this simple device in many episodes of this tutorial, in the hands on sections. It will turn out to be very useful to understand how the proposed circuits work, and will help us acquire a practical view on the insights of digital electronics.

See you soon in this space and…

Happy experiments!