© Jonathan Bartlett 2020
J. BartlettElectronics for Beginnershttps://doi.org/10.1007/978-1-4842-5979-5_12

12. Using Logic ICs

Jonathan Bartlett1 
(1)
Tulsa, OK, USA
 

In Chapter 11, we worked with our first integrated circuit, the LM393 voltage comparator. In this chapter, we are going to look at other ICs and talk more about how they are named and used in electronics.

12.1 Logic ICs

One of the easiest class of ICs to use are the logic ICs. A logic IC is a chip that implements a basic function of digital logic . In digital logic, electric voltages are given meanings of either “true” or “false,” usually with “false” being a voltage near zero and “true” being a positive voltage (often between 3 and 5 volts). These values are also referred to by a number of other designations—a 1 (for true) and 0 (for false) or HIGH (for true) and LOW (for false).1 Then, the digital logic ICs implement logic functions that combine different signals (usually designated as A and B) and give an output signal (usually designated as Y or Q).

For instance, the AND function will output a “true” (positive voltage) value if both of its inputs are true and will output a “false” (near-zero voltage) value otherwise. In other words, if A and B are true, Y is true. As another example, the OR function will output a “true” value if either of its inputs is true. In other words, if A or B is true, Y is true. Figure 12-1 shows the most common types of logic operations and how they work.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig1_HTML.png
Figure 12-1

Common Logic Operations

As we have seen, AND yields a true result when both A and B are true, and OR yields a true result when either A or B is true. So what are the others? XOR is exclusive OR, which means that it is just like OR, but is also false when both inputs are true. NOR is not OR, which means that it is the exact opposite of OR. Likewise, NAND is not AND, which means that it is the exact opposite of AND. Finally, NOT only has one input and simply reverses its value.

Each digital logic function, when implemented in electronics, is called a gate. The nice thing about building circuits with logic gates is that, rather than using math, you can build circuits based on ordinary language.

If you were to say, “I want my circuit to output a signal if both button 1 and button 2 are pressed,” then it is obvious that you would use an AND gate to accomplish this.

INVERTED INPUTS AND OUTPUTS

Sometimes an input or an output on a chip will be labeled with a line on top of the input or output name. This means that the result (or requirement) will be the opposite of what you would otherwise expect. For instance, if the output is Y, then $$ overline {mathrm{Y}} $$ refers to the opposite value of Y. So, if Y is true, then $$ overline {mathrm{Y}} $$ will be false.

The same can occur on inputs as well. For instance, some chips have a reset on the chip which will reset the chip. However, we would normally consider “signaling” a pin to be sending it a voltage. Sometimes the chips would prefer that you signal the reset by bringing the voltage low instead of high. In these cases, they usually designate this by putting a bar over the name of the input pin, so the reset pin would be labeled $$ overline {mathrm{RESET}} $$ in order to indicate this behavior.

These are known as inverted inputs and outputs.

Most logic gates are implemented in chips that contain multiple (often four) implementations of the same gate. For instance, the CD4081 chip is a quad–NAND gate chip. The pinout for this chip is shown in Figure 12-2. Note that it has a supply voltage pin (pin 14) as well as a ground pin (pin 7) to supply power to all the gates on the chip. Each logic gate is numbered 1–4, and the inputs are labeled A and B with the output of Y.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig2_HTML.jpg
Figure 12-2

The Pinout of a CD4081 Chip

To use the chip, you pick which one of the four gates you are going to use (it doesn’t really matter which). If we want to use Gate 1, then we put our inputs on 1A and 1B, and then our output signal goes to 1Y. Note that, unlike the IC from the last chapter, this logic gate has a powered output—it actually supplies voltage and current to drive a (small) output signal.

Logic gates are wired to expect relatively fixed, predefined voltages on their inputs and output the same voltage levels. They do not need current-limiting resistors for their inputs because the inputs themselves are usually high resistance (i.e., 1,000,000–10,000,000 Ω). Because of the high resistance on the inputs, it also means that even if there is a resistor on the input, it will not affect the input voltage significantly. It also means that the current going into the gate is essentially ignorable: $$ I=frac{V}{R}=frac{5}{10,000,000}=0.0005; mA $$.

For some logic chips, the input voltage is expected to be around 3.3 V or 5 V, while for others, it is based on the supply voltage. However, nearly all ICs are limited in how much current they can put out before they fry. This is usually somewhere in the range of 8–20 mA, depending on the chip. Because of this, if you use a logic gate to directly power a device (such as an LED), you probably will need a current-limiting resistor to keep the output current down below these limits.

There are logic chips that have open collector outputs (like the LM393 from Chapter 11), but they are more rare because they are harder to use.

Let’s say that we want to build a circuit which will turn on an LED if both of two buttons are pushed at the same time. Figure 12-3 shows a circuit to accomplish this. It has two buttons, one wired to 1A (pin 1) and one wired to 1B (pin 2). The output 1Y (pin 3) then goes to an LED with a current-limiting resistor. You may wonder what the resistors attached to the buttons are doing. Those will be explained in Section 12.3, “Pull-Down Resistors.”
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig3_HTML.jpg
Figure 12-3

Example Circuit Using an AND Gate

For most logic chips, the manufacturers recommend that unused inputs (but not outputs!) be connected to ground. This makes the chip more efficient in power consumption, but for simple projects like these, it isn’t really necessary. If you wish to connect the unused inputs to ground, then it is a better circuit design.

Note that the circuit shows a 5 V source. While the CD4081 is tolerant of a wide range of input voltages and would operate just fine at 9 V, many digital logic chips are not. Many digital logic chips operate at pre-specified voltages, usually either 5 V or 3.3 V. Therefore, we will take a moment and look at how we can get an input source for a specific voltage.

12.2 Getting a 5 V Source

So far in this book, we have used a custom power regulator to regulate the voltage on the board. Thankfully, this voltage is actually selectable—jumpers on the board allow you to select 5 V or 3.3 V, which are precisely the voltages usually required.

However, if we didn’t have such fancy regulators, how would we achieve a 5 V source? There are several options for doing this, all depending on your requirements and/or the supplies you have available to you.

One option is to build a simple 5 V power supply using the knowledge you already have. In Chapter 9, we showed how to build a voltage divider to step down the voltage from a higher voltage source to a lower one. Although not ideal, this could work fine for simple test circuits. A better option would be to build the Zener diode voltage regulator that was shown in Chapter 8 if you have a 5 V Zener diode handy (however, you would need to be careful to calculate the output wattage, as these can dissipate a lot of power).

A better option is to use a voltage regulator IC. The LM7805 is a simple voltage regulator circuit you can use to convert a 7–24 V voltage source into a 5 V voltage source with somewhat minimal current loss. It is itself an IC, though with a different kind of packaging than we’ve seen, known as a TO-220 package . You can see what this looks like in Figure 12-4. On these packages, if you are reading the writing on the package, pin 1 (input voltage) is on the left, pin 2 (ground) is in the middle, and pin 3 (output voltage) is on the right. Figure 12-5 shows what this looks like in a circuit diagram.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig4_HTML.jpg
Figure 12-4

A 7805 Voltage Regulator in a To-220 Package

../images/488495_1_En_12_Chapter/488495_1_En_12_Fig5_HTML.jpg
Figure 12-5

Logic Gate Circuit with a Voltage Regulator

Figure 12-6 shows how to attach the LM7805 regulator to your breadboard. First, plug the regulator into your breadboard so that each pin is on its own terminal strip. Next, plug the positive wire from the battery into the terminal strip with the voltage regulator’s pin 1 and the negative wire from the battery to the negative/ground power rail on the breadboard. Then, connect the voltage regulator’s pin 2 (ground) to the negative/ground power rail. Finally, connect the voltage regulator’s pin 3 (output voltage) to the positive power rail.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig6_HTML.jpg
Figure 12-6

Simple Way to Attach the LM7805 to Your Breadboard

This will give you a 5 V supply without all of the circuitry of our previous power regulator. This is especially helpful if you have strange power needs or need to use a minimum of space for your power regulation.

Note that some LM7805s have pins that are too big for breadboards. That’s unfortunate, but they are pretty rare. As long as you buy from companies that target hobbyists, you are likely to get a component that will work well with breadboards.

In any case, we will continue to use our power regulators, but I wanted to note that there are other ways to supply the correct amount of power to chips that require fewer components.

12.3 Pull-Down Resistors

In Figure 12-3, we looked at the circuit diagram for a simple AND gate. We noted that each button had a resistor connecting it to ground, but we did not mention why. In digital logic circuits, buttons and single-pole switches, when they are open, essentially disconnect the circuit. Because the inputs are high-resistance inputs (i.e., they use very little current), simply disconnecting the input circuits is not always enough to turn them off! Think of it this way—when you connect the circuit by pushing the button, the whole wire becomes positive. When you let go of the button, the state of the wire has not changed. Eventually the positive charge will drain out through the gate, but, since the input uses so little current, it may take a while for that to happen. Therefore, we have to provide another path for the electricity to go when the button is not pressed. These resistors are called pull-down resistors because, when the button circuit is not connected, they pull the voltage level down close to zero.

The resistor is very important because, when the button is connected, it keeps the voltage high and limits the amount of current that leaks out across the resistor. If you directly connected the button to ground without the resistor, then pushing the button would not raise the voltage because it is still directly connected to ground and would therefore remain at 0 volt. Having the resistor there makes sure that the voltage on the inputs remains high while the button is pressed and bleeds off when the button is released.

In short, without a path to ground, when you let go of the button, the input could remain high. Moreover, without the resistor, pushing the button would cause a short circuit. Therefore, a pull-down resistor allows voltage to drain off quickly when the button is not pressed, but also prevents disasters and wasted current when the button is pressed.

Additionally, static electricity in the air can cause the actual voltage on the gate to fluctuate when it is not connected. Physically connecting the gate to the ground through a resistor will make sure there is always some complete circuit which provides a deterministic value for the voltage at the gate.

The value of a pull-down resistor is usually somewhere between 1 kΩ and 10 kΩ. Beyond 10 kΩ, the actual function of pulling the voltage down to zero can be slowed down. Additionally, even above 4 kΩ, it is possible to interfere with the actual logic operation of the chip. Having a resistor below 1 kΩ, however, means that you are just wasting current.

So, for any button-type input to a digital logic circuit (where the circuit is phyiscally disconnected when the input is off), a pull-down resistor is needed to make sure that the input actually goes low when the button stops being pushed or the switch turns off.

12.4 Combining Logic Circuits

Logic chips that operate at the same voltage are very easy to combine together. Let’s say that you had three buttons that you wanted to monitor and you wanted the light to come on if someone pushed either buttons 1 and 2 together or button 3 (or all of them). To do that, you would need an AND gate and an OR gate. Buttons 1 and 2 would be wired with the AND gate, and button 3 would be combined with the output of the AND gate through an OR gate.

Figure 12-7 shows what this looks like. Since there are so many voltage/ground connections, the figure does not have an explicit battery drawn; instead, it simply shows +5 V wherever it should connect to the voltage source and a ground symbol wherever it should connect to the battery negative. As you can see here, there are two logic ICs—the CD4081 having the AND gate and the CD4071 having the OR gate. The output of the first AND gate is wired into one of the inputs of the OR gate.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig7_HTML.jpg
Figure 12-7

Multiple Logic Gates Combined in a Circuit

This works because, unlike the LM393 (discussed in Chapter 11), these logic gates actually supply output voltage and current as well. Because the inputs to the logic gates are high resistance (they act like there is an extremely large resistor connected to the input), there is no need for a current-limiting resistor when combining gates in this way.

Now, it is fine to draw logic circuits the way we have in Figure 12-7. However, as the logic becomes more complex, actually drawing all of the connections to voltage and ground becomes tiring, and trying to get all of the wires to the right spot on the chip can get messy as well. Because of this, engineers have devised a simpler way of describing logic gates and logic circuits in schematics.

Instead of representing the entire chip on a schematic, engineers will represent only the logic gates themselves.

Additionally, since the power goes to the whole chip (and not the individual gates), in such a drawing, the power connections for the gates are not shown. The standard that was developed represents each type of gate with a shape. Figure 12-8 shows what this circuit drawing looks like if it is drawn using shaped gates instead of IC pins. The actual physical circuit is the same; this is only to simplify the schematics to make them easier to understand and follow.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig8_HTML.jpg
Figure 12-8

Logic Gates Represented as Shapes Instead of IC Pins

Figure 12-9 shows what these gate drawings look like. The AND gate has a flat back panel and a simple, rounded front. The OR gate looks a bit like a space shuttle, with both the back and the front angled. The NOT gate is a triangle with a circle at the tip. This circle can also be added to other gates to show that the gate is the opposite one. For instance, a NAND gate is drawn by first drawing an AND gate and then adding a circle to the front, indicating that the gate behaves like an AND gate with a NOT gate in front of it. Similarly, the NOR gate is an OR gate with a circle in front of it. The XOR gate is similar to the OR gate, but with an extra line going across its inputs.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig9_HTML.jpg
Figure 12-9

Common Gates Used in Schematic Drawings

Many times, the internal schematics of a chip are shown using gate symbols, in order to help you understand the operation of the chip and how the pins work. For instance, Figure 12-10 shows how the CD4081 chip is wired up internally. You can see the inputs going through the logic gate and out toward the output. While this isn’t any new information you didn’t already know, if may help you understand why the pins are laid out the way that they are.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig10_HTML.jpg
Figure 12-10

The Internal Layout of the CD4081

As an interesting sidenote, every logic function can actually be built from NAND gates, though you have to wire them up in strange ways. You can actually build a computer almost entirely from NAND gates if you wanted to. It is not incredibly important, but Figure 12-11 shows how to build each type of logic gate from NAND gates. As an activity, go through the truth tables in Figure 12-1 and see if you can follow how each set of values becomes the result.
../images/488495_1_En_12_Chapter/488495_1_En_12_Fig11_HTML.jpg
Figure 12-11

How Each Gate Can Be Built from NAND Gates

12.5 Understanding Chip Names

One of the biggest problems in learning to build electronic devices is the bewildering array of chips, each with some weird name. “Oh, for that you want an NE555P,” or “You could use a SN74HC00P or a CD4011BE for that task.” What language are such people speaking?

There is a huge selection of chips available, and learning their names is a daunting task. Appendix C attempts to offer some method to the madness, but, at the end of the day, chip names are like people’s names—you get to know them by using them. Nobody knows everybody’s name, but, for the types of projects you like to work on (whatever that happens to be), there will be standard chips whose names you will eventually come to know.

Once you make it through this book, you should have a solid enough background to search for the chips you need, have some understanding of the part names, and be able to find the chips you need for your projects. If you buy the chips from a seller geared toward amateurs and hobbyists, they will likely also include tutorials and additional information available in an easier-to-understand format than just datasheets.

12.6 Review

In this chapter, we learned the following:
  1. 1.

    A logic IC implements basic digital logic functions such as AND, OR, NOT, and so on.

     
  2. 2.

    These logic functions refer to essentially the same ideas that they mean in ordinary language and exactly what they mean in formal logic.

     
  3. 3.

    Logic ICs use different voltage levels for true and false—usually with true being near the supply voltage and false being near zero voltage.

     
  4. 4.

    True is sometimes referred to as HIGH or 1. False is sometimes referred to as LOW or 0.

     
  5. 5.

    The inputs of a logic function are usually designated as A and B, and the output is usually designated as Y or Q.

     
  6. 6.

    If an input or output name has a line/bar printed on top of it, that means that the value is the logical opposite of what would be expected. So, if Y is the output value, then $$ overline {mathrm{Y}} $$ would be the opposite of the output value.

     
  7. 7.

    A single digital logic function is called a gate. Most logic ICs have more than one gate on a single chip.

     
  8. 8.

    Logic ICs require a supply voltage and a ground connection to power the logic.

     
  9. 9.

    Most logic ICs provide powered logic outputs, so that a “true” value supplies both voltage and a small amount of current on its output. However, a current-limiting resistor is usually required.

     
  10. 10.

    If an input to a logic IC may be disconnected for its “false” state (as is common with button inputs), then it needs a pull-down resistor to connect it to ground when the button is not being pushed.

     
  11. 11.

    Logic ICs can usually be combined by wiring the output of one to the input of another to create more complex logical conditions.

     
  12. 12.

    Logic gates are often drawn in schematics using basic shapes to indicate their operation, rather than as connections to chips. In these cases, the power connections are not shown by schematics.

     
  13. 13.

    Every logic gate can actually be built from NAND gates wired together.

     
  14. 14.

    IC names are very confusing and take time and experience to get to know them well.

     
  15. 15.

    Many ICs require specific voltage levels to operate, often at 5 V or 3.3 V.

     
  16. 16.

    Many solutions are available for generating specific voltages, including voltage dividers, Zener diodes, voltage regulators, and add-on breadboard power units.

     
  17. 17.

    The LM7805 is a very common 5 V voltage regulator.

     

12.7 Apply What You Have Learned

  1. 1.

    Draw the circuit in Figure 12-3 yourself. Identify the function of each resistor.

     
  2. 2.

    Build the circuit in Figure 12-3 (don’t forget that the power source should be 5 V).

     
  3. 3.

    If you assume that a negligible amount of current flows through the inputs of the AND gate and that the output functions as a 5 V voltage source (and the LED is red), how much current flows through each resistor when all of the buttons are pressed? What, then, is the total current used by the circuit if you ignore the logic gate?

     
  4. 4.

    Measure the actual current that flows through each resistor. If you are having trouble pushing the buttons while you measure the current, just replace the buttons with wires for this test.

     
  5. 5.

    Measure the current that is used by the AND gate itself. You can do this by measuring the supply current of the AND gate. Measure it both when its output is true and false.

     
  6. 6.

    Draw a schematic of a circuit that has two buttons (B1 and B2) which light up an LED if either button is pressed. Use the logic gate shapes for the schematic.

     
  7. 7.

    Draw a schematic of a circuit that has two buttons (B1 and B2) which light up an LED if neither button is pressed. Use the logic gate shapes for the schematic.

     
  8. 8.

    Draw a schematic of a circuit that has four buttons (B1–B4) which light up an LED either if B1 and B2 are pressed or if B3 and B4 are pressed. Use the logic gate shapes for the schematic.

     
  9. 9.

    Look at the construction of the different gates from NAND gates in Figure 12-11. Copy down the OR gate construction four times, and trace how the output is generated for each possible set of inputs (true/true, true/false, false/true, false/false). Show the inputs and outputs on each NAND gate. Compare the outputs to the truth table for the OR function in Figure 12-1.

     
  10. 10.

    Take the circuit in Figure 12-3 and draw a schematic to use pull-up resistors on the inputs rather than pull-down resistors. How will this change the behavior of the circuit?

     
  11. 11.

    Let’s say that we want to create a door buzzer so that someone outside a door can push a button to be let in. However, the person inside also wants a switch to be able to disable the buzzer. The buzzer can be thought of as a simple device that buzzes when any positive voltage is applied. Draw a circuit diagram of this setup using logic gates. The buzzer can be drawn as a resistor labeled “buzzer” (don’t forget to connect the other side to ground!).

     
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.84.7.255