Book Read Free

Make: Electronics

Page 27

by Charles Platt


  744078*

  XOR

  7486

  XNOR

  747266

  Inverter

  (1 input) 7404

  *The 744078 has an OR output and a NOR output on the same chip.

  Figures 4-66 through 4-74 show the internal connections of the logic chips that you are most likely to use. Note that the 7402 NOR gate has its logical inputs and outputs arranged differently from all the other chips.

  Figure 4-66. Figures 4-66 through 4-74 show pinouts for some of the most widely used logic chips. Note that the inputs of the 7402 are reversed compared with the other chips.

  Figure 4-67.

  Figure 4-68.

  Figure 4-69.

  Figure 4-70.

  Figure 4-71.

  Figure 4-72.

  Figure 4-73.

  Figure 4-74.

  Fundamentals

  Rules for connecting logic gates

  Permitted:

  You can connect the input of a gate directly to your regulated power supply, either positive side or negative side.

  You can connect the output from one gate directly to the input of another gate.

  The output from one gate can power the inputs of many other gates (this is known as “fanout”). The exact ratio depends on the chip, but you can always power at least ten inputs with one logic output. The output from a logic chip can drive the trigger (pin 2) of a 555 timer. The output from the timer can then deliver 100mA, easily enough for half-a-dozen LEDs or a small relay.

  Low input doesn’t have to be zero. A 74HCxx logic gate will recognize any voltage up to 1 volt as “low.”

  High input doesn’t have to be 5 volts. A 74HCxx logic gate will recognize any voltage above 3.5 volts as “high.”

  See Figures 4-75 and 4-76 for a comparison of permitted voltages on the input and output side of 74HCxx and 74LSxx chips.

  Figure 4-75. Each family of logic chips, and each generation in each family, has different standards for input and output minimum and maximum voltages. This diagram shows the standards used by the HC generation of the CMOS family, which was chosen for most of the projects in this book. Note that the current required for input is minimal compared with the current available for output. The power supply to the chip makes up the difference.

  Figure 4-76. Because the LS generation of the TTL family has such different tolerances for input voltages and different standards for output voltages, the LS generation of TTL chips should not be mixed in the same circuit as the HC generation of CMOS chips, unless pull-up resistors are used to bring the LS chips into conformance with standards expected by the HC chips. See Experiment 21 for a case study in using LS chips.

  Fundamentals

  Rules for connecting logic gates (continued)

  Not permitted:

  No floating-input pins! On CMOS chips such as the HC family, you must always connect all input pins with a known voltage, even if they supply a gate on the chip that you’re not using. When you use a SPST switch to control an input, remember that in its “off” position, it leaves the input unconnected. Use a pull-up or pull-down resistor to prevent this situation. See Figure 4-77.

  Figure 4-77. Because a CMOS chip is so sensitive to input fluctuations, a logical input should never be left “floating,” or unattached to a defined voltage source. This means that any single-throw switch or pushbutton should be used with a pull-up or pull-down resistor, so that when the contacts are open, the input is still defined.

  Don’t use an unregulated power supply, or more than 5 volts, to power 74HCxx or 74LSxx logic gates.

  Be careful when using the output from a logic gate to power even a low-current LED. Check how many milliamps are being drawn. Also be careful when “sharing” the output from a logic gate with the input of another gate, at the same time that it is driving an LED. The LED may pull down the output voltage, to a point where the other gate won’t recognize it. Always check currents and voltages when modifying a circuit or designing a new one.

  Never apply a significant voltage or current to the output pin of a logic gate. In other words, don’t force an input into an output.

  Never link the outputs from two or more logic gates. If they must share a common output wire, use diodes to protect them from each other. See Figure 4-78.

  Figure 4-78. The output from one logic gate must not be allowed to feed back into the output from another logic gate. Diodes can be used to isolate them, or they can be linked via another gate.

  In the 74HCxx logic family, each input of a logic gate consumes just a microamp, while the output can source 4 milliamps. This seems paradoxical: how can the chip give out more than it takes in? The answer is that it also consumes power from the power supply attached to pins 7 and 14. That’s where the additional electricity comes from.

  Because the logical output from a chip can be greater than the logical input, we can put the chip in a state where it keeps itself “switched on” in a way which is similar to the way the relay in the alarm project was wired to lock itself on. The simplest way to do this in a logic chip is by feeding some of the output back to one of the inputs.

  Figure 4-79 shows an AND gate with one of its inputs wired to positive and its other input held low by a pull-down resistor, with a pushbutton that can make the input high. A signal diode connects the output of the chip back to the pushbutton-controlled input. Remember that the diode has a mark on it indicating the end which should be connected to the negative side of the power supply, which in this case will be the end of the 10K resistor.

  Figure 4-79. Using a diode, the logical output from a gate can be allowed to feed back to one of its inputs, so that the gate latches after receiving a brief logical input pulse.

  The schematic in Figure 4-79 shows how the circuit should look in breadboard format. Figure 4-80 shows it in a simpler format.

  Figure 4-80. The breadboard-format schematic in is simplified here to show more clearly the way in which a gate can latch itself after receiving an input pulse.

  From this point on, I won’t bother to show the power regulator and the capacitors associated with it. Just remember to include them every time you see the power supply labeled as “5V DC Regulated.”

  When you switch on the power, the LED is dark, as before. The AND gate needs a positive voltage on both of its logical inputs, to create a positive output, but it now has positive voltage only on one of its inputs, while the other input is pulled down by the 10K resistor. Now touch the pushbutton, and the LED comes on. Let go of the pushbutton, and the LED stays on, because the positive output from the AND gate circulates back through the diode and is high enough to overcome the negative voltage coming through the pull-down resistor.

  The output from the AND gate is powering its own input, so the LED will stay on until we disconnect it. This arrangement is a simple kind of “latch,” and can be very useful when we want an output that continues after the user presses and releases a button.

  You can’t just connect the output from the gate to one of its inputs using an ordinary piece of wire, because this would allow positive voltage from the tactile switch to flow around and interfere with the output signal. Remember, you must never apply voltage to the output pin of a logic gate. The diode prevents this from happening.

  If you’ve grasped the basics of logic gates, you’re ready now to continue to our first real project, which will use all the information that I’ve set out so far.

  Experiment 20: A Powerful Combinati
on

  Suppose you want to prevent other people from using your computer. I can think of two ways to do this: using software, or using hardware. The software would be some kind of startup program that intercepts the normal boot sequence and requests a password. You could certainly do it that way, but I think it would be more fun (and more relevant to this book) to do it with hardware. What I’m imagining is a numeric keypad requiring the user to enter a secret combination before the computer can be switched on.

  The Warranty Issue

  If you follow this project all the way to its conclusion, you’ll open your desktop computer, cut a wire, and saw a hole in the cabinet. Without a doubt, this will void your warranty. If this makes you nervous, here are three options:

  1. Breadboard the circuit for fun, and leave it at that.

  2. Use the numeric keypad on some other device.

  3. Use it on an old computer.

  You will need:

  Numeric keypad. As specified in the shopping list at the beginning of this chapter, it must have a “common terminal” or “common output.” The schematic in Figure 4-82 shows what I mean. Inside the keypad, one conductor (which I have colored red to distinguish it from the others) connects with one side of every pushbutton. This conductor is “common” to all of them. It emerges from the keypad on an edge connector or set of pins at the bottom, which I’ve colored yellow.

  Figure 4-81. Caution: This just might void your warranty.

  Figure 4-82. A keypad of the type required for Experiment 20 incorporates a common terminal connected to one side of each of the 12 pushbuttons. The wire from the common terminal is shown red, here, to make it more easily identifiable.

  Keypads that use “matrix encoding” won’t work with the circuit that I’m going to describe. If the Velleman keypad, which I recommend, is unavailable, and you can’t find another like it, you can use 12 separate SPST pushbuttons. Of course, that will cost a little more.

  74HC08 logic chip containing four AND gates. Quantity: 1.

  74HC04 logic chip containing six inverters. Quantity: 1.

  555 timer chip. Quantity: 1.

  Latching relay, 5 volt, DPST or DPDT, “2 form C” package, Panasonic DS2E-SL2-DC5V or similar. Must have two separate coils (one to latch, one to unlatch) with separate inputs. Quantity: 1.

  LEDs, 5mm generic, your choice of colors. Quantity: 3.

  Ribbon cable, with six conductors minimum, if you want to do a really neat job. You can use a cable of the type sold for hard drives, and split off the six conductors that you need, or shop around on eBay.

  Tools to open your computer, drill four holes, and make saw cuts between the holes, to create a rectangular opening for the keypad (if you want to take this project to its conclusion). Also, four small bolts to attach the keypad to the computer cabinet after you create the opening for it.

  The Schematic

  This time I’d like you to study the schematic before building anything. Let’s start with the simplified version, shown in Figure 4-83.

  Figure 4-83. A simplified schematic showing the basic structure of the combination lock circuit.

  I want this to be a battery-powered circuit, so that you don’t have to run a separate power supply to it or (worse) try to tap into your computer’s 5-volt bus. Battery power means that the circuit has to be “off” most of the time, to prevent the battery from running down. Because the keypad has two spare buttons (the asterisk and the pound sign), I’m going to use the asterisk as the “power on” button. When you press it, the LED at the top of the schematic lights up to confirm that everything’s working, and the button sends power to the two logic chips and the 555 timer. You have to hold down the asterisk button while you punch in a three-digit code to unlock the computer.

  Arbitrarily, I’ve chosen 1-4-7 as the three-digit code. Let’s track what happens when you enter this sequence. (Naturally, if you build the circuit, you can wire it to choose any three digits you prefer.)

  Pressing the 1 button sends positive power to one logical input of the first AND gate. The other logical input of this gate is also positive, because an inverter is supplying it, and the input of the inverter is being held negative by a pull-down resistor. When an inverter has a negative input, it gives a positive output, so pressing the 1 button activates the AND gate, and makes its output positive. The AND gate locks itself on, as its output cycles back to its switched input via a diode. So the gate output remains high even after you let go of the 1 button.

  The output from the first AND gate also supplies one logical input of the second AND gate. When you press the 4 button, you send positive voltage to the other logical input of this AND gate, so its output goes high, and it locks itself on, just as the first gate did.

  The second AND gate feeds the third AND gate, so when you press the 7 button, the third AND gate changes its output from low to high. This passes through an inverter, so the output from the inverter goes from high to low. This in turn goes to the trigger of a 555 timer wired in monostable mode.

  When the trigger of a 555 timer goes from high to low, the timer emits a positive pulse through its output, pin 3. This runs down to the upper coil of the latching relay, and also flashes an LED to confirm that the code has been accepted and the relay has been activated.

  Two of the contacts in the relay are wired into the power-up button of your computer. A little later in this description I’ll explain why this should be safe with any modern computer.

  Because we’re using a latching relay, it flips into its “on” state and remains there, even when the power pulse from the timer ends. So now you can let go of the asterisk button to disconnect the battery power to your combination lock, and press the power-up button that switches on your computer.

  At the end of your work session, you shut down your computer as usual, then press the pound button on your keypad, which flips the relay into its other position, reactivating the combination lock.

  Incorrect Inputs

  What happens if you enter the wrong code? If you press any button other than 1, 4, or 7, it sends positive voltage to the inverter near the top of the schematic. The positive voltage overwhelms the negative voltage being applied to the inverter through a pull-down resistor, and causes the inverter to output a negative voltage, which it applies to one of the logical inputs of the first AND gate. If the AND gate was locked on, the negative input will switch it off. If it was supplying the second AND gate, it’ll switch that one off too.

  Thus, any error when entering the first, second, or third digit of the secret code will reset the AND gates, forcing you to begin the sequence all over again.

  What if you enter 1, 4, and 7 out of their correct sequence? The circuit won’t respond. The third AND gate needs a high input supplied by the second AND gate, and the second AND gate needs a high input supplied by the first AND gate. So you have to activate the AND gates in the correct sequence.

  Questions

  Why did I use a 555 timer to deliver the pulse to the relay? Because the logical output from an AND gate cannot deliver sufficient power. I could have passed it through a transistor, but I liked the idea of a pulse of a fixed length to flip the relay and illuminate an LED for about 1 second, regardless of how briefly the user presses the 7 button.

  Why do I need three LEDs? Because when you’re punching buttons to unlock your computer, you need to know what’s going on. The Power On LED reassures you that your battery isn’t dead. The Relay Active LED tells you that the system is now unlocked, in case you are unable to hear the relay click. The System Relocked LED reassures you that you have secured your computer.

  Because all the LEDs are driven either directly from the 5-volt supply or from the output of the 555 timer, they don’t have to be low-current LEDs and can be used with 330Ω series resistors, so they’ll be nice and bright.


  How do you connect the keypad with the circuit? That’s where your ribbon cable comes in. You carefully strip insulation from each of the conductors, and solder them to the contact strip or edge connector on your keypad. Push the conductors on the other end of the cable into your breadboard (when you’re test-building the circuit) or solder them into perforated board (when you’re building it permanently). Find a convenient spot inside your computer case where you can attach the perforated board, with double-sided adhesive or small bolts or whatever is convenient. Include a 9-volt battery carrier, and don’t forget your power regulator to step the voltage down to 5 volts.

  Breadboarding

  No doubt you have realized by now that breadboards are very convenient as a quick way to push in some components and create connections, but the layout of their conductors forces you to put components in unintuitive configurations. Still, if you carefully compare the breadboard schematic in Figure 4-83 with the simplified schematic in Figure 4-84, you’ll find that the connections are the same.

  To help it make sense, I’ve shown the logic gates that exist inside the chips. I’ve also colored the power supply wires, as before, to reduce the risk of confusion. The positive side of the supply goes only to the common terminal on your keypad, and you have to press the asterisk key to send the power back down the ribbon cable, to supply the chips.

  If you build the circuit and you can’t understand why everything’s dead, it’s most likely because you forgot to hold down the asterisk button.

 

‹ Prev