Home arrow Electronic Projects arrow Power Supplies arrow Introduction to digital logic 05 September 2008  
Main Menu
Home
News
Forums
Downloads
Contact Us
Search i-hacked
Become a Member
- - - - - - -
Computer Components
Consumer Electronics
Electronic Projects
Game Systems
Cell / Phone
Car / Home
Misc
- - - - - - -
Info and Contests
Reviews
Login Form





Lost Password?
Latest Edge
Advertisement
Privacy Policy
Vote for us in Top 100 Security Sites
Click here to Vote!
Newsflash
Introduction to digital logic Print E-mail
Written by hevnsnt   
Wednesday, 02 March 2005

The following is an complete tutorial from the book "APPLE I Replica Creation: Back to the Garage" by Syngress Publishing.

This exciting new book takes you back to computings "breakthough" with the Apple 1, walking you though its construction.  I don't think you can find a book that says "Hardware Hacking" more than this one.  Make sure to read the the forward written by one of my personal heros Steve Wozniak.

This article provides an introduction to digital logic, the basis of microcomputer design.  It will teach you the basics of building your own electronics by learning how each component works.  If you are interested in electronics at all, You will want to bookmark this article!
Topics in this Article:
  • Introduction
  • Breadboarding
  • Electricity
  • Gates
  • Circuits With Algebra
  • Latches and Flip-Flops
  • What Is Data?
  • A Few More Chips


Breadboarding

We’ll perform all the experiments in this chapter using breadboards. To begin, perform the following steps:

1. Find a power supply and snip off one of the hard drive connectors.

2. Strip down the end of the red wire (5 volts) and the black wire (ground).

3. Turn the power supply on and check these cables with your multimeter to ensure that they really are 5 volts and ground.

4. On your breadboard, you’ll see a series of red and blue lines running the length of the plastic. Connect the power supply cables to the banana plugs, and connect the banana plugs to these lines (see Figure 3.1)

Figure 3.1 Connecting Power and Ground

The holes beside these lines are for power and ground, respectively. A look inside may help us understand how these boards work (see Figure 3.2).

Figure 3.2 Inside the Breadboard

Inside each hole is a metallic socket into which you can plug a wire or component. Every socket in the ground strip is connected; therefore, if you connect one socket to your ground supply, all sockets in the strip are grounded. The same rule applies to the power strip. We have three columns of power and ground strips with nothing connecting them, so we need to use jumper wires across the bottom (see Figure 3.3).

Figure 3.3 Jumpering Power and Ground Lines

To help gain an understanding of the rest of the board, take a look at Figure 3.2 once again. Each horizontal row of five sockets is connected. Therefore, if we wanted to connect three resistors in a series (one after the other), we could configure them as shown in Figure 3.4.

Figure 3.4 Resistors in Series

Next, let’s make sure everything’s configured correctly by running some tests using the logic probe:

1. Connect your probe’s alligator clips to the power and ground lines (see Figure 3.5).

Figure 3.5 Connecting the Logic Probe

2. Touch the point of the probe to any socket on the power line. The “HI” light should come on.

3. Test a socket in each strip by repeating Step 2.

4. Repeat Step 2 yet another time for the ground sockets; for these, the “LOW” light should come on (see Figure 3.6). The sockets connected to neither power nor ground should produce no light at all.

Figure 3.6 Testing with the Logic Probe

Electricity

Here you’ll find a very brief, hands-on introduction to electronics fundamentals. This chapter provides enough of the basics that you shouldn’t have too much difficulty completing the Apple I. However, a more substantial understanding of electronics will serve you well in the future. If you’d like to do some further reading, The Art of Electronics, by Paul Horowitz and Winfield Hill (Cambridge University Press, 1989), is the most widely acclaimed book on the topic but is perhaps too difficult for the beginner. A more appropriate book for the novice is Hands-On Electronics, by Daniel M. Kaplan and Christopher G. White (Cambridge University Press, 2003).

Voltage and Current

Voltage (V) is the potential difference between two points, measured in volts. When you set your multimeter to Volts DC and touch the probes to the breadboard, negative to negative and positive to positive, you’ll get a reading of 5 volts. That’s the amount of energy it takes to move charge from the lower point (ground) to the higher.

Current (I) is used to measure the rate of flow of an electrical charge and can be thought of in terms of a water current. Current is measured in amperes (A). Whereas voltage is measured between two points, current measures the rate of flow at a particular point. DC voltage is steady (hook your circuit up to a 5-volt supply, and 5 volts is what you’ll get), but current only “pulls” as much as you need. If you have a power supply capable of 10 amps and your circuit only needs 5 amps, then 5 amps is all that it will pull.

Power (P) is voltage multiplied by current. Power is measured in watts, which you’re probably familiar with seeing on light bulbs. In fact, light bulbs serve as an excellent example. Consider a 20W and a 50W halogen bulb (see Figure 3.7). Both require 12 volts. The difference is in the current, which we can calculate using P = V • I.

I = P/V 20 watts / 12 volts = 1.6 amps 50 watts / 12 volts = 4.16 amps

Appropriately, we see that the brighter light bulb draws significantly more current than the dimmer one.

Here’s an exercise: Replace all the 40W lights in your house with 200W bulbs and see what happens to your electricity bill.

Figure 3.7 A Light Bulb Circuit

Need to Know…

Intersections

If you have two wires you want to connect in a schematic, place a large dot at the point of connection. If there is no dot, readers (and the schematic software) will assume there is no physical connection between the two lines. See Figure 3.8.

Figure 3.8 Intersections

Resistors and Diodes

Now that we’ve explained the basics of current and voltage, we can take a more hands-on approach to resistance. Let’s wire up an LED. A diode is a device that allows current to flow in only one direction. For this experiment, let’s use a standard red LED, such as Model #276-041 from Radio Shack. These LEDs have a recommended voltage of about 2.25 volts, with a maximum voltage of 2.6 volts (you’ll find all this information on the packaging). The maximum current is 28 mA. Our power supply provides 5 volts; therefore, if we hook the LED up directly to the power supply, it will probably burn out. (If you have a spare, try this!)

To reduce the voltage, use a resistor. A resistor is a partial conductor, usually made of carbon. We can calculate resistance using the equation:

R = V/I

where R (resistance) is calculated in ohms, V (voltage) in volts, and I (current) in amps.

Our circuit is shown in Figure 3.9. In moving from our 5-volt supply to ground, we have 5 volts we need to dispose of. The LED uses 2.25 volts, which leaves 2.75 volts for the resistor. This is the value we want to use for V in this equation. Now we can calculate:

R = (5v – 2.25v) / .028 A = 98 ohms

If you calculated decimal places, you’re taking these numbers too seriously. Next, we need to find a 98-ohm resistor. A resistor with a smaller value will provide less resistance and potentially allow damage to your LED. One with greater resistance merely means that your LED won’t be quite as bright. We’re just experimenting, so brightness level isn’t a major concern. I used the nearest resistor I had available, which happened to be 300 ohm.

Now it’s time to wire it up:

1. Snip off the ends of the resistor, making it fit conveniently into your breadboard.

2. Hook up the resistor and the LED in series. It doesn’t matter which one you connect first; however, be aware that the orientation of the LED does matter (see the “LED Polarity” sidebar). The finished circuit is displayed in Figure 3.10.

Try swapping your current resistor with some resistors of varying sizes to see what happens. Also try putting the LED in backward.

Figure 3.9 LED Circuit

Figure 3.10 Wired LED

Need to Know…

LED Polarity

An LED typically has two leads projecting from its base (see Figure 3.11). The longer lead is the positive lead (also known as the anode), and the shorter lead is the negative lead (also known as the cathode). The cathode is also denoted by a flat edge on the plastic LED housing. The anode will connect to a positive voltage (5V in this case), and the cathode will connect to ground.

Figure 3.11 LED Diagram

 

Need to Know…

Resistor Codes

Most resistors have four colored bars that will give you the value in ohms, as shown in Table 3.1. A resistor of Yellow, Red, Red, Gold would be 4,200 ohms, with an accuracy of 5%. If we needed a 30-ohm resistor, we would search for the colors Orange, Black, Brown, Gold.

Memorizing Table 3.1 will save you time if you’re going to do a lot of work with resistors. At the very least, knowing the values in column three will help prevent you from using an exponentially incorrect resistor. If you don’t have the time to memorize the table or have no desire to haul the chart around with you, there are a multitude of Java applets on the Web that will do the conversions for you. There are also many applications for graphing calculators that allow you to complete the conversion without the work, including the RCOL for the HP 48, which is available at hpcalc.org. You can also simply use your multimeter to measure the ohms.

Table 3.1 Resistor Codes

Color

Bar 1

Bar 2

Bar 3

Bar 4

Black

0

0

x1

 

Brown

1

1

x10

 

Red

2

2

x100

 

Orange

3

3

x1,000

 

Yellow

4

4

x10,000

 

Green

5

5

x100,000

 

Blue

6

6

x1,000,000

 

Magenta

7

7

 

 

Gray

8

8

 

 

White

9

9

 

 

Gold

 

 

x0.1

5%

Silver

 

 

x0.01

10%

Capacitors

A capacitor, like those shown in Figure 3.12, stores energy in an electric field. In building our circuits, we’ll use these as de-spiking capacitors to filter the power supply. When the output of one of our chips changes, it causes a sudden voltage drop (a negative-going spike). When this occurs, the capacitor will partially discharge its energy to eliminate the severity of this spike.

Figure 3.12 Capacitors

Gates

Those little black chips that cover circuit boards look extremely complex. Today, most of these integrated circuits, or ICs, are quite intricate, but there are still many chips available of the simpler variety. If you examine the chips in a modern computer, you will notice that many of them have hundreds of pins placed so closely that they appear almost impossible to work with. Open an older computer, and you’ll discover chips that look much more accessible, with few pins and great spacing. We’ll be working with these older, more “classic” chips throughout this book.

The 7400 series of ICs serves as the basis for digital logic and is very easy to understand. Throughout the rest of this chapter we’ll concentrate on building a few very basic digital circuits using 7400 series ICs, resistors, and LEDs.

AND

IF it is dark AND IF there is a car in the driveway THEN turn on the porch light.

Under what circumstances is the porch light turned on? Only if both statements are true—it must be dark, and there must be a car in the driveway. One of the two is not enough. In a schematic, we’d express this idea as shown in Figure 3.13. The D symbol is a logical AND. We can also use a truth table. Follow along with the truth tables in Table 3.2 and see if they match the aforementioned assertions. You’ll note that all three tables contain the same data. True is a logical 1, which is implemented with a 5-volt signal. False is a logical 0 and is implemented by a 0-volt signal.

Figure 3.13 An AND Gate

Table 3.2 AND Truth Tables

Input A

Input B

Output C

False

False

False

False

True

False

True

False

False

True

True

True

 

Input A

Input B

Output C

0

0

0

0

1

0

1

0

0

1

1

1

 

Input A

Input B

Output C

0v

0v

0v

0v

5v

0v

5v

0v

0v

5v

5v

5v

 

With all this in mind, perform the following steps:

1. Take a 7408 IC and insert it into your breadboard. This chip has four AND gates, arranged as you see in Figure 3.14. Note the location of the notch in the diagram.

2. Orient all chips so that the notch is at the top, and pin 1 will always be in the upper-left corner.

3. Hook up the supply voltage and ground. Pin 14 is Vcc (Voltage common collector) and should be tied to your 5-volt line. Pin 7, GND, should be connected to ground.

Figure 3.14 A 7408 IC

Need to Know…

Pin Numbering

Pin numbering always starts in the upper-left corner, goes down the left side, and follows up the right side. Pin 1 is marked either by a circle in the upper-left corner or by a notch in the top center (at which point it’s up to you to know left from right). See Figure 3.15.

Figure 3.15 Pin Arrangement

Now let’s wire the first AND gate on the chip:

1. Connect pins 1 and 2 (inputs to the AND gate) to the supply voltage line.

2. Then, connect pin 3 to the input of the LED that was wired up earlier.

3. Turn on the power, wait a few nanoseconds for the signal to propagate, and the LED should light up (see Figure 3.16). Since both Input A and Input B are high, the output will also be high and the LED will be powered on.

Figure 3.16 The Lit LED

4. Next, take the wire from pin 2 (or pin 1) and move it from supply voltage to ground. To grasp the importance of this step, imagine that instead of moving the cable by hand, it’s hooked up to a light sensor that outputs 0 volts when it’s light out and 5 volts when it’s dark.

Note … Nanoseconds

When a chip’s inputs are changed, the output does not change instantaneously. The new signals take time to propagate throughout the chip. This propagation varies depending on the speed and complexity of the design, but TTL gates tend to take about 10 nanoseconds (ns) to complete propagation. There are 1 billion nanoseconds in a second.

If you like a challenge, try playing around with the chip a bit more by wiring the inputs of some gates to the outputs of others. Create the equivalent of a four-input AND gate. You can also examine the logic table in Table 3.3 to find patterns.

Table 3.3 Input AND Gate

Input A

Input B

Input C

Input D

Output E

0

0

0

0

0

0

0

0

1

0

0

0

1

0

0

0

0

1

1

0

0

1

0

0

0

0

1

0

1

0

0

1

1

0

0

0

1

1

1

0

1

0

0

0

0

1

0

0

1

0

1

0

1

0

0

1

0

1

1

0

1

1

0

0

0

1

1

0

1

0

1

1

1

0

0

1

1

1

1

1

 

Inverter, NAND

IF it is dark AND IF there is a car in the driveway, THEN turn OFF the porch light.

This statement is almost identical to the one in previous section, even though our goal has changed to produce the opposite effect. The only change that needs to be made is the addition of an inverter (see Table 3.4). The inverter takes whatever signal it is given and outputs the opposite; therefore, if you put 0 volts in, you’ll get 5 volts out, and vice versa. In Figure 3.17, you’ll see the symbol for an inverter along with an AND gate. The triangle means “buffer” (replicate the signal), and the small circle means “invert it.” Find a 7404 (shown in Figure 3.18) and connect the voltage to supply and ground. Now connect the output of your AND gate (pin 3) to the input of the 7404’s inverter (pin 1). The output of the inverter (pin 2) goes to the LED to complete our circuit, shown in Figure 3.19.

Table 3.4 Inverter Truth Table

Input A

Output B

0

1

1

0

Figure 3.17 An Inverter and an AND Gate

Figure 3.18 A 7404 IC

Figure 3.19 AND and NAND Gates, Wired to LED

The inverted AND is so common that it has its own gate, the NAND (not AND) gate. This gate is functionally equivalent to an AND followed by an inverter. The NAND is pictured in Figure 3.20, with its layout in Figure 3.21. Table 3.5 displays its operation, which, hopefully, you were able to surmise.

Figure 3.20 The NAND Gate

Figure 3.21 A 7400 IC

Table 3.5 NAND Truth Table

Input A

Input B

Output C

0

0

1

0

1

1

1

0

1

1

1

0

OR, NOR

IF it is dark AND IF there is a car in the driveway OR if the light switch is on, THEN turn on the porch light.

Here we take our output from the AND gate already wired up and OR it with “the light switch is on.” The OR gate in TTL logic is the 7432 (see Figure 3.22), which exhibits the characteristics provided in Table 3.6.

Figure 3.22 A 7432 IC

Table 3.6 OR Gate Truth Table

Input A

Input B

Output C (A OR B)

0

0

0

0

1

1

1

0

1

1

1

1

 

Perform the following steps:

1. Take your 7432 and connect power and ground.

2. Using the AND circuit that you already wired, hook the output of the AND gate to an input of the OR (pin 1). The other OR input (pin 2) should be connected directly to power or ground to simulate the light switch being on or off.

3. Next, wire the OR’s output (pin 3) to the LED (see Figure 3.23). Table 3.7 describes the behavior of this entire circuit. Note that the light comes on for five out of eight possible combinations.

Figure 3.23 AND and OR, Wired

Table 3.7 Truth Table for Figure 3.23

Input A

Input B

A AND B

Input C

Output E ((A AND B) OR C)

0

0

0

0

0

0

1

0

0

0

1

0

0

0

0

1

1

1

0

1

0

0

0

1

1

0

1

0

1

1

1

0

0

1

1

1

1

1

1

1

 

As with NAND, there is also a NOR gate (see Figure 3.24), which is OR followed by an inverter. You can find NOR gates on the 7402 (see Figure 3.25). Table 3.8 shows a NOR gate truth table.

Figure 3.24 A NOR Gate

Figure 3.25 A 7402 IC

Table 3.8 NOR Gate Truth Table

Input A

Input B

Output C (A NOR B)

0

0

1

0

1

0

1

0

0

1

1

0

 

Need to Know…

Combining Outputs With OR

Let’s say you have two AND gates and you want to combine their outputs so that if either AND gate’s output is HI, our final output is HI as well. What happens if you connect the two output lines, as in Figure 3.26? When output A goes HI and output B goes LO, the two signals will compete, potentially damaging your chips.

If you’re tempted to try this configuration, you’re probably looking to use an OR gate, as shown in Figure 3.27.

Figure 3.26 A Bad Circuit

Figure 3.27 A Good Circuit

XOR

IF it is dark OR IF there is a car in the driveway—but NOT if both—THEN turn on the porch light.

Perhaps this behavior would be desirable if you wanted to discourage visitors after dusk? XOR is short for exclusive OR and means “if one or the other is true, but not if both are true.” You can find XOR gates on the 7486 (see Figure 3.28). In Figure 3.29 you see the schematic for this circuit, along with an equivalent circuit that does not use the XOR gate but achieves the same effect. Table 3.9 shows an XOR truth table.

Figure 3.28 A 7486 IC

Figure 3.29 Schematic of Circuits With and Without XOR Gates

Table 3.9 XOR Truth Table

Input A

Input B

Output C (A XOR B)

0

0

0

0

1

1

1

0

1

1

1

0

 

Circuits With Algebra

Don’t worry, this topics is not as bad as it sounds. Using logic expressions, DeMorgan’s Laws, and Boolean algebra, you can quickly sketch out basic circuits on paper or even in a simple text editor. Logic expressions will allow you to show gates and lines with symbols and letters. DeMorgan’s Laws will allow you to swap gates to get more efficient circuits. Boolean algebra will allow you to simplify your circuits.

Logic Expressions

Ambiguities in the English language can make it very difficult to precisely express digital logic; therefore, an algebra has been developed for this purpose. Understanding this algebra is merely a matter of getting accustomed to the symbols. Table 3.10 displays these symbols, listed in order of precedence.

Table 3.10 Algebraic Symbols for Expressing Digital Logic

 

Symbol

Meaning

'

NOT

AND

+

OR

Å

XOR

 

Figure 3.30 shows a few logic expressions and their equivalent circuits. Take a good look at these and make sure you understand them. Try writing a few of your own.

Figure 3.30 Logic Expressions

DeMorgan’s Laws

The term DeMorgan’s Laws sounds dull and tedious, but these laws are a real boon for the improvising hacker. DeMorgan’s laws explain how we can substitute different combinations of gates to best use our available resources. They can be expressed as:

(A + B) ' = A' • B'

(A • B) ' = A' + B'

Let’s take (AB) ' (a NAND gate), for example. This statement means that A and B are not both true; therefore, at least one of them is false. Consequently, it follows that A is not true or B is not true, which we can write as A' + B'. This looks like a slight change from the first equation, but it can make a huge difference. Consider, for example, that the signals you are receiving may already be inverted or that you may not even have any NAND gates. Also note that each of the chips we’ve been using contains multiple gates. DeMorgan’s Laws allow us to more fully utilize the chips with which we’re already working.

There’s an easy way to remember DeMorgan’s Laws in practice (see Figure 3.31). To find the equivalent for any gate, first swap the symbol (OR to AND, AND to OR). Then look at each input and output. Everywhere there’s an inverter, remove it, and everywhere there isn’t, add one.

Figure 3.31 DeMorgan’s Laws

Boolean Algebra

Boolean algebra is a method for manipulating logic expressions. It allows us to reduce complex expressions to simpler statements that are logically equivalent. Some useful equivalencies are shown in Table 3.11.

Table 3.11 Equivalences

-A • 1 = A

A + 0 = A

A • 0 = 0

A + 1 = 1

A • A = A

A + A = A