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

## How To Make A PCB Using A Laser Printer

When working with electronic circuits, sooner or later we feel the need to make our own PCBs to get a more functional and better looking circuit board.

I already made a video in the past to show how that could be done, for simple circuits, by drawing the circuit manually on the copper clad with a special kind of pen that uses an ink impervious to the chemicals needed to etch the PCB.

This time, I am presenting you a different technique, that allows you to draw the traces, and also the silk layer, with any of the design tools of your choice available on the Internet and the market in general. All you need to have is a laser printer. You can refer to this newer video for a demonstration of the process.

The whole process works on the concept that the printouts of the laser printers are made with a toner that has the characteristic of being able to protect the copper from the etching chemicals, like the ink from the pen in the original video. This is because the toner is made with a sort of plastic material.

Unfortunately, we cannot use a laser printer to print the masks directly on the copper clad, because the PCB boards are too thick for the printer. Therefore, we need to find a way to print on paper and then tranfer the printed ink to the copper afterwords.

This is made possible by a certain quality of glossy paper that do not allow the toner to stick permanently on its surface when exposed to heat. Even paper from magazines that are printed on glossy paper works relatively well for this to happen. However, there are specialized papers, that are designed specifically for this, which are called Thermal Transfer Paper For PCBs. A quick search on-line will give you plenty of places where you can buy it at a relatively modest price.

Once you have your PCB design ready and printed on such paper, the process to create PCBs becomes really straightforward.

First step is the transfer of the traces drawing to the copper. The copper needs to be perfectly clean, so it is always better to use a piece of steel wool to scrape away copper oxide and other dirt from the copper surface. Just move the wool in a circular fashion to remove all the particles of oxide from the copper clad and make sure to use gloves, otherwise the contact with the skin of your hands will soon oxidize again the copper.

Once all the oxide is removed, you need to deep clean the copper to remove any particle of dust from it. To do so, you can use some alcohol. Once done, let the board stand for a a while to make sure it is completely dry.

Then lay the board on the printout, making sure the copper is in contact with the drawing. Wrap the paper all around the board to make sure it will not move during the transfer process.

Once the PCB is wrapped with the paper, put it on the table copper-side up and use an iron at the max temperature, with no steam, to heat uniformly the whole surface of the paper and the pcb wrapped in it. Be careful not to burn yourself in the process, of course. You do not need to press hardly, the weight of the iron is just enough. Just make sure you keep moving the iron so that the whole surface is heated uniformly. Do that for a while, until the copper clad becomes almost as hot as the iron. Don’t worry about burning the paper. it is not going to happen. Paper burns at 451 F while the iron, even at the hottest temperature, doesn’t normally go over 400F.

Once the paper and the clad are well heated, put aside the iron and unwrap the board, making sure that when you remove the paper from the copper side you do that slowly and uniformly. The ink from the printout will now have moved from the paper to the copper.

Second step is the actual etching. Use a plastic container, fill it with some ferric chloride solution, enough to cover the whole pcb, then dump the board in the solution. Once the board is in the solution, you’ll notice that the ferric chloride starts changing color. From the initial brown color, it starts becoming darker and darker. This happens because of the copper on the board that starts dissolving in the solution.

While the etching process continues, try to agitate the solution periodically, which will speed up the reaction. A warmer room will also help. Every now and then, check the status of the board and remove it from the solution as soon as you don’t see any more copper on the surface of it.

Once the etching is completed, remove the PCB from the solution and start rinsing it immediately, to stop the reaction that would continue to attack the remaining copper on the surface.

You now need to remove the toner film from the copper traces, otherwise you will not be able to solder the components on it. To do so, use a Lacquer thinner on a piece f paper or cotton and work slowly a little bit at a time. Do this in a well ventilated area. Solvent vapors are both unpleasant to breath and harmful.

Third step is to drill the holes. It is only necessary if you use pass through components, of course. If you use surface mounted components, this step is not necessary, unless you need holes to hold in place the board.

Finally, the fourth and last step is to do another transfer, on the components side of the board, to transfer the drawing for the silk layer. The procedure is exactly the same, but this time the toner will be lay down directly on the board support, not on the copper.

You can see how this process allows you to quickly repeat the whole procedure on as many boards as you like. You just need to print multiple copies of the layouts on the thermal paper and go through the previous four steps.

Hope yo liked this procedure, and don’t forget to go watch the corresponding video, so you will see exactly how this procedure works.

## How To Choose A Resistor

How do we choose the right resistor when designing and building an electronic circuit? Here are the major parameters that should be kept into account.

A resistor is a component made out of a poor conducting material, so that it can offer a resistance to the flow of the current.

You can think to resistance in terms of the obstacles that charges encounter when moving from one end to the other of a conductor. The more obstacles, the higher the resistance. In a metallic wire, for example, the charges are the electrons of the conduction band (see this post and this other one for further details).

In today’s post I would like to address an issue that sometimes is underestimated when designing an electronic circuit: how to choose the right resistor for the job.

Resistors are not all the same. Besides the resistance value that distinguishes one from the other, there are other factors that are important as well.

Here is a list of all the important factors, why they are important, and what are the consequences of not choosing a resistor based on each specific factor.

• The first thing that comes to mind is the tolerance, which is usually provided on the body of the resistor itself, along with its resistance value.

In color coded resistors, the tolerance is defined by the band that is far away from all the others. In the above picture, for example, it is the gold band, which means that the tolerance is of 5%. In other resistors, where the resistance is explicitly written on the body of the resistor, the tolerance is usually written in clear along with the resistance. More in general, you’ll have to refer to the data sheet provided by the constructor to figure out its tolerance.
Tolerance is an important factor for those circuits that require very precise resistors, like measuring instruments and the like. It is also important when the resistor is used for the polarization of a critical component. If the resistors used in the project have a tolerance that is too high, the whole circuit may not function properly because the actual value of the resistor is too different from the one that was required.

• Operating Temperature. This depends both from the ambient conditions and by the temperature raise produced by the power dissipation. There are two reasons to keep the temperature range into account. First, resistors slightly change their resistance with the change of the temperature. Using the resistor outside its temperature range would cause a variation greater than the one considered by the tolerance. Second, but not last, when the resistor is traversed by current it heats up. As long as the current stays within a range for which the power dissipation is not exceeded, everything is fine. Otherwise, the resistor can easily overheat and burn.

• Maximum Voltage. Operating a resistor above its maximum voltage rating may cause sparks that would destroy the resistor.

Resistors used in low power circuits usually have a maximum voltage in the order of at least 100V, and that’s why people usually don’t care or it doesn’t even know that there is such a parameter. In fact, low voltage circuits will normally never exceed the maximum voltage of any resistor. However, there are specific applications where voltages in the circuits can be above the 100V threshold. In such cases, it is important to verify that the resistors used in the circuit can withstand those voltages.

• Temperature coefficient. This is the parameter that tells us how much the resistance changes per degree Celsius. It depends on the material the resistor is made of, but also on the heat dissipation capability of the component. Some resistors are built with an embedded heat sink to reduce the value of this factor.

This information becomes important in those cases where it is known that the resistor is going to dissipate a considerable amount of power. Based on that, it is possible to figure out if the resistor needs an external heat sink and, eventually, the heat sink thermal resistance.

• Parasitic Capacitance and Inductance. A real resistor does not have only a resistance but also a very low value of capacity and inductance that may affect its functionality at high frequencies.

These parasitic capacitance and inductance are caused by the physical dimensions and shape of the component and cannot be avoided. When working at high frequencies, these values need to be taken into account, since they will generate both capacitive and inductive reactance that will affect the value of the resistor at the particular frequency it is going to be used.

• Packaging. This keeps into account where and how the resistor is going to be mounted. It can be a through holes resistor, which is provided with two leads to make the connections. The leads are usually inserted in the holes of a perforated board or of a Printed Circuit Board (PCB). Or, the resistor can be a Surface Mounted one. This has no wires, just two pads that can be directly soldered on a Surface Mounted technology (SMT) PCB. Other factors affecting the packaging include the possibility of attaching it to an external heat sink, and/or the necessity to properly ventilate it, to guarantee enough heat dissipation.