The basic unit of a digital circuit is the logic gate. Gates like AND, OR, and NOT are electronic circuits for decisions such as "on only when both switches are pressed" or "on when either is pressed". On perfboard, they are most often used in the form of a 14-pin logic IC such as the 74LS00 or 74HC00 with four gates in one chip. This article covers the basic gates and truth tables, the difference between 74LS and 74HC, logic levels, and how to handle unused inputs and gates.
The six basic gates
| Gate | Operation | A=0, B=0 | A=0, B=1 | A=1, B=0 | A=1, B=1 |
|---|---|---|---|---|---|
| AND | 1 if both are 1 | 0 | 0 | 0 | 1 |
| OR | 1 if either is 1 | 0 | 1 | 1 | 1 |
| NAND | The opposite of AND | 1 | 1 | 1 | 0 |
| NOR | The opposite of OR | 1 | 0 | 0 | 0 |
| XOR | 1 if they differ | 0 | 1 | 1 | 0 |
NOT (an inverter) is a gate with a single input that outputs 1 if the input is 0 and 0 if it is 1.
NAND and NOR are "universal gates", so you can make any logic with just one of them. For example, tying the two inputs of a NAND makes a NOT, and putting a NOT after a NAND makes an AND. That is why a single 74LS00 (four NANDs) lets you do many experiments.
Logic levels
A digital circuit interprets voltage as two ranges, 0 and 1.
| Item | 74LS (TTL) | 74HC (CMOS) |
|---|---|---|
| Supply | 5 V (4.75 – 5.25 V) | 2 – 6 V |
| Input read as Low | 0.8 V or below | About 30% of supply or below |
| Input read as High | 2.0 V or above | About 70% of supply or above |
| Output Low | 0.5 V or below (up to 8 mA) | Nearly 0 V |
| Output High | 2.7 V or above (up to 0.4 mA) | Nearly the supply voltage |
| Input behavior | Some current flows at the input | Very high impedance input (mind static) |
| Power consumption | Relatively large | Very small |
Always use the 74LS at 5 V ±5%. At a 3.3 V supply, normal operation is not guaranteed. The 74HC can also be used at 3.3 V.
Lighting an LED from the output
On the 74LS family, the ability to pull Low (8 mA) is much greater than the ability to output High (0.4 mA). So it is usual to put the LED in series with a resistor between +5 V and the output pin, lit when the output is Low. The 74HC is similar in both directions but the current is small, about 4 mA, so lower the LED current or use a transistor (Transistor Switch Circuits).
Unused inputs and gates
Never leave an input pin floating. On CMOS (74HC, CD4000) especially, a floating input wobbles at an in-between voltage, the current rises, and it misbehaves. TTL (74LS) reads a floating input as High, but it is very weak to noise, so it must be handled too.
- Spare inputs of AND and NAND: connect to +V (through 1 kΩ to 10 kΩ if needed). Or tie them together with another input that is in use.
- Spare inputs of OR and NOR: connect to GND.
- Unused gates: tie the inputs to a firm level and leave the output open. Leaving the inputs alone makes the gate switch needlessly and waste current.
- If you need the same signal on several inputs, tie the input pins together.
74LS00 pinout
The pins of the 14-pin quad NAND IC are as follows. Most quad gates (the 74LS08 AND, the 74LS32 OR, and so on) use the same positions.
| Pin | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Signal | 1A | 1B | 1Y | 2A | 2B | 2Y | GND |
| Pin | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
|---|---|---|---|---|---|---|---|
| Signal | 3Y | 3A | 3B | 4Y | 4A | 4B | VCC |
A and B are inputs and Y is the output. Note that pin 14 is +V and pin 7 is GND. Some ICs have a different pinout depending on the gate type (such as the 74LS02 NOR), so check the datasheet (Reading DIP IC Pin Numbers, How to Read a Datasheet).
Power and layout tips
- Put a 100 nF close to the power pins of every IC. Digital ICs draw large momentary currents when switching, so the effect is big (Power Rails, Grounding, and Decoupling Capacitor Placement).
- When mixing 74LS and 74HC, a 74LS output (minimum High of 2.7 V) may not satisfy a 74HC input (which needs 3.5 V or more with a 5 V supply). In that case add a pull-up resistor or use a 74HCT (TTL-compatible) part.
- Do not forget pull-ups, pull-downs, and debounce on switch inputs (Tact Switches and Pull-Up/Pull-Down Resistors).
Checking in Patterndo
Patterndo's built-in ICs include gate ICs such as the 74LS00 (NAND), 74LS02 (NOR), 74LS04 (NOT), 74LS08 (AND), 74LS32 (OR), 74LS86 (XOR), 74HC00, and CD4011. Put two switches on the inputs and an LED on the output, and check by simulation that it behaves as the truth table says. A combined example is in A 0–9 Digit Counter with a 74LS90, 74LS47, and Seven-Segment Display.
Summary
The basic gates are AND, OR, NAND, NOR, XOR, and NOT, and NAND alone can make them all. The 74LS is 5 V only, and when driving an LED from the output it is better to pull with a Low output. Never leave an input floating, and connect unused inputs to +V for AND and NAND and to GND for OR and NOR.