Chapter 3
IN THIS CHAPTER
Implementing logic gates with transistors
Looking at TTL and CMOS integrated circuits
Building some simple logic circuits
In Book 5, Chapter 2 , you learn all about logic gates, including the seven most popular kinds of gates: NOT, AND, OR, NAND, NOR, XOR, and XNOR.
In this chapter, you learn how to create actual circuits that use logic gates. I start you off by showing you the basics of how logic gates can be created from simple transistor circuits. Then I look at two popular integrated circuit families that provide prebuilt logic gates.
If you haven’t already read Chapter 2 , I suggest that you go back and do so now before you read this chapter. Little of this chapter will make sense if you aren’t familiar with the different types of gates described in that chapter.
Way back in Book 2, Chapter 6 , you see how transistors can be used as switches. In a nutshell, a voltage applied to the base of a transistor allows current to flow from the collector to the emitter. Thus, by applying an input signal to a transistor’s base, you can control an output signal taken from the collector-emitter path.
You can build any logic gate you want by cobbling together a few transistors and resistors in just the right way. In this section, I look at simple transistor circuits for five gate types — NOT, AND, OR, NAND, and NOR — and I present projects to show you how to build three of them: NOT, NAND, and NOR.
Note that you won’t often actually build your own logic gates by using transistors and resistors. Instead, you’ll use integrated circuits that contain prefabricated logic gates. Before you use logic ICs in your circuits, however, you should have a basic understanding of how the gates that they contain work. After you take a look at simple transistor circuits for basic logic gates, you’ll take a look at the logic ICs.
A NOT gate simply inverts its input. If the input is HIGH, the output is LOW, and if the input is LOW, the output is HIGH. Such a circuit is easy to build, using a single transistor and a pair of resistors. Figure 3-1 shows the schematic.
The operation of this circuit is simple. The input is connected through resistor R2 to the transistor’s base. When no voltage is present on the input, the transistor turns off. When the transistor is off, no current flows through the collector-emitter path. Thus, current from the supply voltage (Vcc in the schematic, typically between and ) flows through resistor R1 to the output. In this way, the circuit’s output is HIGH when its input is LOW.
When voltage is present at the input, the transistor turns on, allowing current to flow through the collector-emitter circuit directly to ground. This ground path creates a shortcut that bypasses the output, which causes the output to go LOW.
In this way, the output is HIGH when the input is LOW and LOW when the input is HIGH.
Project 31 shows how to assemble a simple transistor NOT gate on a solderless breadboard. For this project, a normally open push button is used as the input. When the button isn’t pressed, the input is LOW and the output is HIGH, which causes the LED to light. When you press the button, the input goes HIGH, the output goes LOW, and the LED goes out. The assembled project is shown in Figure 3-2 .
In this project, you build a simple NOT gate by using a bipolar transistor. A NOT gate, as shown in Table 3-1 , is also known as an inverter. It simply reverses the logic level of its input. So, if the input is HIGH, the output of a NOT gate is LOW. If the input is LOW, the output is HIGH.
TABLE 3-1 NOT Gate Truth Table
Input |
Output |
0 |
1 |
1 |
0 |
The input to this gate is controlled by a push-button switch (SW1). When the switch is open, the input is LOW. When the switch is closed, the input is HIGH.
The output from this gate is sent through an LED, so the LED is on when the output is HIGH and off when the output is LOW.
Insert the transistor Q1.
Collector: G7
Base: G6
Emitter: G5
Insert resistors R1 and R2.
: E7 to F7
: E6 to F6
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J7
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert the jumper wires.
1: Positive bus to A4
2: Positive bus to A7
3: Ground bus to J5
Connect the batteries.
Red lead: Positive bus.
Black lead: Ground bus.
A two-input AND gate produces a HIGH output if both of its inputs are HIGH. You can create a two-input AND gate by using two transistors and three resistors, as shown in Figure 3-3 . In this circuit, the output current must flow from the Vcc supply voltage through the collector-emitter circuits of both transistors to reach the output. Thus, current will flow to the output only if both of the transistors are on.
The bases of both transistors are fed through R2 and R3 from the two inputs. Thus, if both inputs are HIGH, current will flow through the base-emitter path of both transistors, turning both transistors on and allowing current to flow through to the output. If either input is LOW, the corresponding transistor turns off, and the output goes LOW.
A two-input NAND gate produces a LOW output if both of its inputs are HIGH. You could create a NAND gate by combining the circuits shown in Figure 3-1 and Figure 3-3 so that the output from the AND gate is used as input to the NOT gate, but that combination would require three transistors. It’s easy enough to create a NAND gate by using just two transistors, as shown in Figure 3-4 .
This NAND gate circuit is almost identical to the AND gate circuit shown in Figure 3-3 , earlier in this chapter. The only difference is that instead of connecting the output to the emitter of the second transistor, the output is obtained before the collector of the first transistor. If both of the inputs are HIGH, both of the transistors will conduct through their collector-emitter paths, which creates a short circuit to ground. This causes the current to bypass the output altogether, which in turn causes the output to go LOW.
If either transistor turns off, however, the supply current can’t flow through the transistors to ground, so it flows through the output circuit instead. Thus, the output is HIGH if either one of the inputs is LOW. If both inputs are HIGH, the output is LOW.
Project 32 shows how to assemble a simple transistor NAND gate on a solderless breadboard. Normally open push buttons are used for the two inputs. The LED will be on until you press both of the push buttons. This action causes both inputs to go HIGH, which causes the output to go LOW and the LED to go dark. The completed project is shown in Figure 3-5 .
In this project, you build a simple NAND gate using a pair of bipolar transistors. As shown in Table 3-2 , the output of a NAND gate is LOW if both inputs are HIGH; otherwise, the output is HIGH.
TABLE 3-2 NAND Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
The inputs in this project are provided by two breadboard-mounted push buttons, and the output is indicated by an LED. The LED is lit unless both of the push buttons are pressed.
Lead |
Q1 |
Q2 |
Collector |
G7 |
G11 |
Base |
G6 |
G10 |
Emitter |
G5 |
G9 |
Insert resistors R1, R2, and R3.
: E7 to F7
: E6 to F6
: E10 to F10
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J7
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B8, D8, B10, and D10 such that the switch opens and closes across rows 8 and 10.
Insert the jumper wires.
1: Positive bus to A4
2: Positive bus to A7
3: Positive bus to A8
4: Ground bus to J9
5: I5 to I11
Connect the batteries.
Red lead: Positive bus
Black lead: Ground bus
A two-input OR gate produces a HIGH output if either of its inputs is HIGH or both of its inputs are HIGH. Figure 3-6 shows a schematic for an OR gate created with two transistors and three resistors.
In the OR gate circuit, the supply voltage is connected separately to the collector of each transistor. Then the emitters of both transistors are connected to the output. That way, if voltage is applied to the base of either one of the transistors, that transistor will turn on and pass current through to the output.
Thus, the output is HIGH if one input is HIGH or both inputs are HIGH. The output is LOW only if both inputs are LOW.
A NOR gate is an inverted OR gate. If at least one of the inputs is HIGH, the output is LOW. If both inputs are LOW, the output is HIGH.
Figure 3-7 shows a schematic for a NOR gate. This circuit is similar to the circuit shown in Figure 3-6 , earlier in this chapter, except that the output is connected to the collector of both transistors and the emitter of each transistor is connected to ground. If either one of the transistors is on, current from Vcc will be short-circuited to ground, bypassing the output. As a result, the output will be HIGH only when both inputs are LOW. If either input is HIGH or both inputs are HIGH, the output will be LOW.
You can build a two-transistor NOR gate by following the steps outlined in Project 33. As with the other projects in this chapter, Project 33 uses normally open push buttons to control the input circuits. When power is applied to this circuit, both inputs initially will be LOW, and the output will be HIGH. Pressing either one of the switches causes that switch’s input to go HIGH, which in turn causes the output to go LOW. The assembled project is shown in Figure 3-8 .
In this project, you build a simple NOR gate using a pair of bipolar transistors. As Table 3-3 shows, the output of a NOR gate is HIGH if both inputs are LOW. If either input is HIGH, the output is LOW.
TABLE 3-3 NOR Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
The inputs in this project are provided by two breadboard-mounted push buttons, and the output is indicated by an LED. The LED is lit unless at least one of the push buttons is pressed.
Lead |
Q1 |
Q2 |
Collector |
G7 |
G11 |
Base |
G6 |
G10 |
Emitter |
G5 |
G9 |
Insert resistors R1, R2, and R3.
: E7 to F7
: E6 to F6
: E10 to F10
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J7
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B8, D8, B10, and D10 such that the switch opens and closes across rows 8 and 10.
Insert the jumper wires.
1: Positive bus to A4
2: Positive bus to A7
3: Positive bus to A8
4: Ground bus to J5
5: Ground bus to J9
6: I7 to I11
Connect the batteries.
Red lead: Positive bus
Black lead: Ground bus
Although you can build your own logic gates by using transistors and resistors as described so far in this chapter, it’s far easier to buy prepackaged integrated circuits that implement logic gates. The main advantage of using integrated circuit logic gates is that you don’t have to design the individual gates yourself or waste time assembling them.
The logic gate circuits you’ve learned about so far in this book are among the simplest circuits for creating logic gates, but they’re by no means the only — and not necessarily the best — ways to create logic gates. Over the 50 years or so that circuit designers have been working on semiconductor-based logic circuits, many designs have been developed for creating logic gates.
Because each approach to designing logic circuits results in an entire family of logic circuits for the various types of gates (NOT, AND, OR, NAND, NOR, XOR, and XNOR), the different designs are often referred to as design families. Also, because these design families were developed by engineers far nerdier than you and I, each family has a nice three- or four-letter acronym. Here are the most popular:
TTL: Not Tinkertoy Logic, but Transistor-Transistor Logic. It uses two transistors, one configured to work as a switch and the other configured to work as an amplifier. The switching transistor is used in the input circuits, and the amplifier transistor is used in the output circuits. The amplifier allows the gate’s output to be connected to a larger number of inputs than RTL or DTL circuits.
In a TTL circuit, the switching transistors are actually special transistors that have two or more emitters. Each input is connected to one of these emitters so that the separate inputs all control the same collector-emitter circuit. The switching transistor’s base is connected to the Vcc supply voltage, and the collector is connected to the base of the amplifying transistor. Figure 3-9 shows a typical TTL circuit.
Although you can build TTL circuits by using individual transistors, ICs with TTL circuits are readily available. One of the most popular types of TTL ICs is designated by numbers in the form 74nn. In all, a few hundred types of 7400-series integrated circuits are available. Many of them provide advanced logic circuits that you aren’t likely to use for home electronics projects. The ICs listed in Table 3-4 provide several basic logic gates in a single package.
There actually is such a thing as Tinkertoy Logic. In fact, a team of MIT students actually built a complete computer that plays tic-tac-toe by using Tinkertoys. To learn more, search the Internet for “Tinkertoy Computer.”
CMOS: Complementary Metal-Oxide Semiconductor Logic, which refers to logic circuits built with a special type of transistor called a MOSFET. MOSFET stands for Metal Oxide Semiconductor Field Effect Transistor, but that won’t be on the test. The physics of how a MOSFET differs from a standard bipolar transistor aren’t all that important unless you want to become an IC designer. What is important is that MOSFETs use much less power, can switch states much faster, and are significantly smaller than bipolar transistors. These differences make MOSFETs ideal for modern integrated circuits, which often require millions of transistors on a single chip.
Apart from drawing less power and operating faster than TTL circuits, CMOS circuits work much like TTL circuits. In fact, CMOS chips are designed to be interchangeable with comparable TTL chips.
CMOS logic chips have a four-digit part number that begins with the number 4 and are often called 4000-series chips. As with the 7400 series of TTL logic chips, several hundred types of 4000-series chips are available. Table 3-5 lists the 4000-series chips that provide basic logic gates.
TABLE 3-4 7400-Series TTL Logic Gates
Number |
Description |
7400 |
Quad two-input NAND gate (four NAND gates) |
7402 |
Quad two-input NOR gate (four NOR gates) |
7404 |
Hex inverter (six NOT gates) |
7408 |
Quad two-input AND gate (four AND gates) |
7432 |
Quad two-input OR gate (four OR gates) |
7486 |
Quad two-input XOR gate (four XOR gates) |
TABLE 3-5 4000-Series CMOS Logic Gates
Number |
Description |
4001 |
Quad two-input NOR gate (four NOR gates) |
4009 |
Hex inverter (six NOT gates) |
4011 |
Quad two-input NAND gate (four NAND gates) |
4030 |
Quad two-input XOR gate (four XOR gates) |
4071 |
Quad two-input OR gate (four OR gates) |
4077 |
Quad two-input XNOR gate (four XNOR gates) |
4081 |
Quad two-input AND gate (four AND gates) |
The remaining sections of this chapter describe several popular 4000-series ICs and present a few projects that use them.
The 4000-series CMOS logic circuits include several ICs that provide several logic gates in a single package. Figure 3-10 shows the pinout connections for six popular 4000-series chips. Each of these six chips contains 4 2-input logic gates in a 14-pin DIP package. Power, which can range from to , is connected to pin 14, and ground is connected to pin 7.
Note that the 4001 and 4011 chips contain four NOR and NAND gates. Because NOR and NAND are universal gates, you can use them in combination to create other types of gates. As a result, if you stock up on 4001 or 4011 chips, you’ll be able to create any type of logic circuit you may need.
Before you start building circuits with CMOS logic chips, here are a few tips for working with 4000-series chips:
The 4011 Quad Two-Input NAND Gate is a popular CMOS logic gate IC. As its name suggests, this IC contains four two-input NAND gates. The pinouts for this IC are shown in Figure 3-10 , earlier in this chapter, along with the pinouts for several other quad two-input gate chips.
Unlike most of the components used in this book, a 4011 IC isn’t available at your local RadioShack. Thus, you’ll have to find a local electronics store that carries parts such as CMOS logic chips, or you’ll have to order them from an online source. I list several reputable sources in Book 1, Chapter 3 .
In Book 5, Chapter 2 , you learn that NAND gates (along with NOR gates) are universal gates, which means that you can construct any other type of gate by using nothing but NAND gates combined in various ways. Projects 34 through 37 walk you step by step through the process of building various types of gate circuits by using only NAND gates.
Project 34 uses just one of the NAND gates in a 4011. The two inputs of the NAND gate are connected to push buttons, and the output is connected to an LED. When you build this project, you’ll be able to visualize the operation of a NAND gate: The LED will be on unless you press both buttons.
Figure 3-11 shows Project 34 assembled on a solderless breadboard. This figure should give you a good idea of how to connect the components to the breadboard. The project description itself provides detailed instructions. The circuits for projects 35, 36, and 37 are similar enough in appearance that you can use Figure 3-11 as a guide for the overall appearance of your finished projects. (The only differences are in the positions of the jumper wires.)
Project 35 uses two of the NAND gates on the 4011 to create an AND gate. Because a NAND gate is nothing more than an AND gate whose output is inverted, you can create an AND gate from a NAND gate by inverting the NAND gate’s output. This inversion works because of one of the fundamental rules of logic: If you invert a value twice, you get the original value. Thus, if you invert an AND gate once, you get a NAND gate; if you invert it again, you’re back to an AND gate.
As luck would have it, you can easily turn a NAND gate into a single-input inverter (that is, a NOT gate) by connecting the single input to both inputs of the NAND gate. This connection causes the two inputs to always be the same: Either both are HIGH, or both are LOW. In a NAND gate, if both inputs are HIGH, the output is LOW, and if both inputs are LOW, the output is HIGH. Thus, wiring the inputs of a NAND gate together has the effect of inverting the input.
In Project 36, you see how to create an OR gate by using three NAND gates. Book 5, Chapter 2 shows that a NAND gate is the same as an OR gate whose inputs have been inverted. Thus, to create an OR gate by using NAND gates, you invert the two inputs with NAND gates configured as inverters (that is, with their inputs wired together). The output from these inverters is sent to the inputs of the third NAND gate.
The final project in this chapter, Project 37, uses all four of the NAND gates on the 4011 chip to create a NOR gate. A NOR gate is nothing more than an OR gate whose output has been inverted. Thus, you first use three NAND gates to create an OR gate by using the technique in Project 36; then you configure the fourth NAND gate on the 4011 chip as an inverter to invert the output of the OR gate.
Because these projects build on one another, I recommend that you don’t tear down your breadboard after completing each project. Instead, you can use each assembled project as a starting point for the next one. If you choose to build the projects in this way, you can just scan the steps to see what resistors and jumper wires need to be moved for each project. (The 4011 IC itself, the LED, and the two switches are in the same locations for all four projects.)
In this project, you use a 4011 CMOS chip to build a NAND gate. As Table 3-6 shows, the output of the NAND gate is LOW if both of the inputs are HIGH. Otherwise, the output is HIGH.
TABLE 3-6 NAND Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
0 |
The inputs to this gate are fed through two breadboard-mounted push buttons, and the output is indicated by an LED.
Insert the 4011 IC.
Pin 1 should be in E10.
Insert resistors R1, R2, and R3.
: E6 to F6
: E21 to F21
: E20 to F20
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J20
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B21, D21, B23, and D23 such that the switch opens and closes across rows 21 and 23.
Insert the jumper wires.
1: Positive bus to A3
2: Positive bus to A4
3: Positive bus to A23
4: Ground bus to J6
5: Ground bus to J18
6: Ground bus to J21
7: E3 to F3
8: E18 to F18
9: A6 to A10
10: A11 to A21
11: C16 to C18
12: D12 to D20
13: I3 to I10
Connect the batteries.
Red lead: Positive bus
Black lead: Ground bus
In this project, you use two of the NAND gates in a 4011 CMOS chip to build an AND gate. As Table 3-7 shows, the AND gate’s output is HIGH if both inputs are HIGH; otherwise, the output is LOW.
TABLE 3-7 AND Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
To create the AND gate, you send the output from the first NAND gate to the second NAND gate, which you configure as an inverter by tying its inputs together. Inverting the output of a NAND gate creates an AND gate.
The inputs to this gate are fed through two breadboard-mounted push buttons, and the output is indicated by an LED.
Note that the only difference between this project and Project 34 is the placement of a few of the jumper wires.
Insert the 4011 IC.
Pin 1 should be in E10.
Insert resistors R1, R2, and R3.
: E6 to F6
: E21 to F21
: E20 to F20
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J20
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B21, D21, B23, and D23 such that the switch opens and closes across rows 21 and 23.
Insert the jumper wires.
1: Positive bus to A3
2: Positive bus to A4
3: Positive bus to A23
4: Ground bus to J6
5: Ground bus to J18
6: Ground bus to J21
7: E3 to F3
8: E18 to F18
9: A6 to A10
10: A11 to A21
11: B13 to B20
12: C12 to C15
13: D16 to D18
14: D12 to D14
15: I3 to I10
Connect the batteries.
Red lead: Positive bus
Black lead: Ground bus
In this project, you use a two of the NAND gates in a 4011 CMOS chip to build an OR gate. As Table 3-8 shows, the OR gate’s output is HIGH if either one (or both) of the inputs are HIGH. If both inputs are LOW, the output is also LOW.
TABLE 3-8 OR Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
To create the OR gate, you simply invert the two inputs to a NAND gate. Thus, this circuit uses two of the NAND gates on the 4011 to invert the two inputs. It then sends these inverted inputs to the inputs of a third NAND gate to complete the OR gate.
The inputs to this gate are fed through two breadboard-mounted push buttons, and the output is indicated by an LED.
Note that the only difference between this project and Project 35 is the placement of one of the resistors and a few of the jumper wires.
Insert the 4011 IC.
Pin 1 should be in E10.
Insert resistors R1, R2, and R3.
: E6 to F6
: E21 to F21
: H14 to H20
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J20
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B21, D21, B23, and D23 such that the switch opens and closes across rows 21 and 23.
Insert the jumper wires.
1: Positive bus to A3
2: Positive bus to A4
3: Positive bus to A23
4: Ground bus to J6
5: Ground bus to J18
6: Ground bus to J21
7: E3 to F3
8: E8 to F8
9: E18 to F18
10: E19 to F19
11: A6 to A10
12: A15 to A21
13: B10 to B11
14: B14 to B15
15: C8 to C12
16: C13 to C19
17: D16 to D18
18: G8 to G15
19: G16 to G19
20: I3 to I10
Connect the batteries.
Red lead: Positive bus.
Black lead: Ground bus.
In this project, you use all four of the NAND gates in a 4011 CMOS chip to build a NOR gate. As Table 3-9 shows, the NOR gate’s output is LOW if either one (or both) of the inputs are HIGH. If both inputs are LOW, the output is HIGH.
TABLE 3-9 NOR Gate Truth Table
Input A |
Input B |
Output |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
A NOR gate is simply an OR gate whose output is inverted. Thus, to create a NOR gate, you use three of the NAND gates on the 4011 to create an OR gate, as described in Project 36. Then you use the fourth NAND gate to invert the output of the OR gate.
The inputs to this gate are fed through two breadboard-mounted push buttons, and the output is indicated by an LED.
Note that the only difference between this project and Project 36 is the placement of the third resistor and the addition of two jumpers.
Insert the 4011 IC.
Pin 1 should be in E10.
Insert resistors R1, R2, and R3.
: E6 to F6
: E21 to F21
: H13 to H20
Insert LED1.
Cathode (short lead): Ground bus
Anode (long lead): J20
Insert SW1.
The pins should be inserted in B4, D4, B6, and D6 such that the switch opens and closes across rows 4 and 6.
Insert SW2.
The pins should be inserted in B21, D21, B23, and D23 such that the switch opens and closes across rows 21 and 23.
Insert the jumper wires.
1: Positive bus to A3
2: Positive bus to A4
3: Positive bus to A23
4: Ground bus to J6
5: Ground bus to J18
6: Ground bus to J21
7: E3 to F3
8: E8 to F8
9: E18 to F18
10: E19 to F19
11: A6 to A10
12: A15 to A21
13: B10 to B11
14: B14 to B15
15: C8 to C12
16: C13 to C19
17: D16 to D18
18: G8 to G15
19: G16 to G19
20: H11 to H12
21: I3 to I10
22: I12 to I14
Connect the batteries.
Red lead: Positive bus
Black lead: Ground bus