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).
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.
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 refers to the opposite value of Y. So, if Y is true, then 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 in order to indicate this behavior.
These are known as inverted inputs and outputs.
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: .
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.
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).
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.
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.
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
- 1.
A logic IC implements basic digital logic functions such as AND, OR, NOT, and so on.
- 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.
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.
True is sometimes referred to as HIGH or 1. False is sometimes referred to as LOW or 0.
- 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.
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 would be the opposite of the output value.
- 7.
A single digital logic function is called a gate. Most logic ICs have more than one gate on a single chip.
- 8.
Logic ICs require a supply voltage and a ground connection to power the logic.
- 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.
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.
Logic ICs can usually be combined by wiring the output of one to the input of another to create more complex logical conditions.
- 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.
Every logic gate can actually be built from NAND gates wired together.
- 14.
IC names are very confusing and take time and experience to get to know them well.
- 15.
Many ICs require specific voltage levels to operate, often at 5 V or 3.3 V.
- 16.
Many solutions are available for generating specific voltages, including voltage dividers, Zener diodes, voltage regulators, and add-on breadboard power units.
- 17.
The LM7805 is a very common 5 V voltage regulator.
12.7 Apply What You Have Learned
- 1.
Draw the circuit in Figure 12-3 yourself. Identify the function of each resistor.
- 2.
Build the circuit in Figure 12-3 (don’t forget that the power source should be 5 V).
- 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.
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.
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.
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.
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.
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.
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.
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.
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!).