Logic Gates

Introduction

Analog and Digital Quantities

Science, technology, business and many other fields involve measuring, monitoring, recording, or manipulating various quantities, the values of which need to be represented efficiently and accurately. There are basically two ways of representing the numerical value of quantities: analog and digital.

  • Analog quantities have continuous values
  • Digital quantities are discrete. Each discrete value then can be represented as a digital code that consists of a set of 0s and 1s.

Why Digitize?

The main benefits of using digital technology over analog are:

  • Information storage, processing and transmission are more efficient and reliable
  • Accuracy and precision are greater
  • Digital circuits are less affected by noise (unwanted voltage fluctuations)
  • Digital circuits are easier to design

There is really only one major drawback when using digital techniques. The real world is mainly analog. This necessitates analog to digital and digital to analog conversion.

Example of a Digital System

Set up a system for detecting fluid levels in a tank. The system should record data for quantity of water consumed every day and perform some statistical calculations. The measured water level should be represented by an LED (Light Emitting Diode) display. Input to the system is controlled by a variable resistor, the value of which is proportional to the movement of the sensor.

Numeric Systems – Decimal System

Many numeric systems are used in digital technology. The most common are the decimal, binary, octal, and hexadecimal systems.

Every numeric system has a base or radix, which specifies how many different digits can be used in each place count. The decimal system is also called the base-10 system because it has 10 digits.

Numbers are positionally coded groupings of digits. Each digit position has a specified weight in the value of the number. The value of the decimal number is the sum of the digits multiplied by their corresponding weights. The subscript indicates that the number is to base 10 (and therefore a decimal number)

Binary System

For binary numbers the base is 2, with 0 and 1 as the only two digits. For binary numbers, the position represents a power of 2, such as 2, 4, 8, 16 etc. Notice that the value, or weight, in each position doubles when moving left, because the base is 2.

Any binary number can be converted to its decimal equivalent simply by adding together the weights of the various positions in the binary number which contain a 1. Note that the subscripts 2 indicate that the number is to base 2 (so it is a binary number).

Bit, Byte, Word

Typically binary numbers are often written as groups of digits. Each digit, either 0 or 1, is referred to as a bit. The rightmost digit is called the least significant digit, or LSD, because its positional value, or weight, is the lowest. The left-most digit is the most-significant digit, or MSD, because its weight is the highest.

An important characteristic of a computer is the word size of its memory, registers, and buses. Word has a specialized meaning in digital design. It refers to a set of bits, usually 2n bits (n is any natural number). A string of eight bits (23) is called a byte.

The Need for Data Conversion

In digital systems the information that is being processed is usually presented in binary form.

In a simple calculator decimal numbers are entered via the keyboard. An encoder is used to convert a calculator keystroke into a binary code. Once converted to binary form, numbers may be easily added, subtracted, and otherwise used in computations. The result is then decoded (converted back) to decimal form for display.

Play and learn with a simple calculator to observe data conversion in action.

Decimal to Binary Conversion

To convert a decimal number to its binary equivalent, repeated division by 2 is used. The quotient and remainder are recorded. The first remainder is the least significant bit of the binary number. Next the quotient is divided by 2 to obtain a new quotient and a remainder. This remainder is the next bit of the resulting binary number. The process continues until a quotient of 0 with a remainder of 1 is obtained. The final remainder of 1 is the most significant bit.

Practice converting decimal numbers to their binary equivalent. Count from zero to fifteen using 4-bit binary code.

Binary Signals

Binary quantities can be represented by any device that has only two operating states. A switch has only open or closed conditions. An open switch represents binary 0 and a closed switch represents binary 1. The voltages used to represent a 1 and a 0 are called logic levels. It is common to refer to a binary 0 as a LOW level, and a binary 1 as a HIGH level.

In digital circuits the exact value of the voltage is not important, only the range (HIGH or LOW) in which it falls. For example any voltage between 2V and 5V may be recognized as binary 1 (HIGH) and between 0V and 0.8 V as binary 0. Voltages between 0.8V to 2V may cause an error in a digital circuit.

Digital Waveforms

Binary information in digital systems can be seen as waveforms that represent sequences of bits. Each bit in a sequence occupies a defined time interval called the bit time.

A periodic waveform of pulses repeats itself after a fixed time interval called a period (T). The frequency (f) of a digital waveform is the reciprocal of the period.

In digital systems all waveforms are synchronized with a basic timing waveform called the clock. The clock is a periodic waveform in which the interval between pulses equals the time for one bit. The clock waveform itself does not carry information.

Logic Equations

Logic equations are used to show what logic signal should be output in response to changes in one or more input signals. The equals sign (=) is typically used as an assignment operator to indicate how information will flow through a logic circuit.

A simple switch is used to turn on a bulb. The light is on if the switch is closed. This logic statement can be expressed as: Light = Switch. It seems to be a correct statement. In fact, the light is on only if the power is on, and the bulb is not burned out and the switch is on. Here, the AND logic function combines the variables of Switch, Power and Bulb.

Basic Logic Functions

There are three fundamental logical operations, from which all other functions, no matter how complex, can be derived. These functions are named AND, OR, and NOT. Each of these has a clearly defined behavior and a specific symbol.

Switches in series can illustrate the AND operation. The bulb is on if switches A and B are both on. Switches in parallel can represent the OR function. If either switch A OR B is on then the bulb is on. The NOT (or inversion) function reverses the logic state. It is illustrated by a relay. The bulb is on if the switch A is NOT on and vice versa.

Logic Gates and Truth Tables

Devices that implement the basic logic functions are called logic gates. A logic gate is a circuit that has one or more inputs but only one output.

All logic gates can be analyzed by constructing a truth table. The truth table:

  • Lists all possible input combinations and the corresponding output.
  • Each line in a truth table represents a unique value of the input variables.

A truth table with n inputs requires 2n rows to list all possible input combinations.

Basic Logic Gates – NOT Gate

Digital systems are constructed by using three basic logic gates – NOT, AND and OR. The NOT gate (inverter) has only one input and one output. The inverter output is opposite to the input. When the input A is LOW, the output Y is HIGH and vice versa.

The NOT operator is written as a bar above the variable. The circle on the inverter output represents inversion. The circle could have been placed at the input instead, and the logical meaning would still be the same.

Click the input to change the assigned logic value and observe the output.

AND Gate

An AND gate gives a HIGH output (1) only if all its inputs are HIGH. With either input at logic 0, the output will be held to logic 0. A dot (.) is used to indicate the AND operation. Keep in mind that this dot is usually omitted.

There is no functional limit to the number of inputs an AND gate may have. However, for practical reasons, commercial AND gates are most commonly manufactured with 2, 3, or 4 inputs. A standard 14-pin package can contain four 2-input gates, three 3-input gates, or two 4-input gates, and still have room for two pins for power supply connections.

Example Application

Liquid required for a manufacturing process is stored in two tanks which have sensors that detect the liquid level. The sensors produce a HIGH output (5V) when the tanks are more than one-third full and put out a LOW voltage (0V) when the liquid drops below this level. A green light-emitting diode should light up on an indicator panel when both tanks are more than one-third full.

As long as both sensor outputs are HIGH, indicating that both tanks are more than one-third full, the AND gate output is HIGH. The green LED is arranged so that HIGH voltage turns it on.

OR Gate

An OR gate gives a HIGH output if any of its inputs is HIGH. A plus (+) sign is used to represent the OR operation.

As with the AND function, the OR function can have any number of inputs. However, practical commercial OR gates are mostly limited to 2, 3, and 4 inputs, as with AND gates.

Click the inputs to change the assigned logic value and observe the output.

Example Application

A simplified section of an alarm system is shown in the illustration. A magnetic switch produces a LOW output when closed and HIGH when opened. A piezoelectric sensor gives a LOW output until mechanical deformations above it change the output to HIGH.

As long as the door and the window are secured, the sensors are inactive and both OR gate inputs are LOW. If either the window is broken or the door is opened, a HIGH is produced at that input to the OR gate and the gate output goes HIGH. It then activates the alarm circuit to warn of the intrusion.

Derived Logic Gates – NAND Gate

While the three basic functions AND, OR, and NOT are sufficient to accomplish all possible logical functions of any level of complexity, some combinations are used so commonly that they have been given names and logic symbols of their own.

A NAND gate is a NOT-AND circuit, which is equivalent to an AND gate followed by a NOT gate. The output of a NAND gate is HIGH unless both inputs are HIGH. Then the output will be LOW.

The circle at the output of the NAND gate denotes the logical inversion, just as it did at the output of the inverter. Note that the bar is over both input values at once.

NOR Gate

A NOR gate is a NOT-OR circuit, which is equivalent to an OR gate followed by a NOT gate. The output of a NOR gate is LOW if any of the inputs are HIGH. The circle at the output of the NOR symbol denotes the logical inversion. Note that the bar is over both input values at once.

NAND and NOR gates are called "universal logic gates" as any digital circuit can be designed by using just these gates. The gates can have any number of inputs. In practice, commercial NAND and NOR gates are manufactured with 2,3, or 4 inputs.

XOR or Exclusive-OR Gate

An XOR (exclusive-OR) gate is a circuit which will give a HIGH output if either, but not both, of its two inputs are HIGH. An XOR gate produces a logic 1 if its two inputs are different. If the inputs are the same, the output is a logic 0.

An encircled plus sign is used to indicate an XOR function. This symbol is a variation on the standard OR symbol.

Unlike standard OR/NOR and AND/NAND functions, the XOR function always has exactly two inputs. Four XOR gates fit on a standard 14-pin IC package.

XNOR or Exclusive-NOR Gate

An XNOR gate (exclusive-NOR) is a combination of an XOR gate followed by an inverter. Its output is high if the inputs are the same and low if the inputs are different.

Like the XOR function, the XNOR function always has exactly two inputs. Four XNOR gates fit on a standard 14-pin IC package.

Example Application

Set-up a logic circuit, which indicates with a red light when at least one of the tanks falls to the one-third full level. A sensor puts out a LOW voltage if the volume in its tank goes to one-third full or less. The red LED circuit is arranged so that a LOW voltage turns it on.

Equivalence Gates

The diagram shows the standard and the alternative equivalent symbol for each logic gate. The term negative means that the inputs are defined to be in the active state when LOW. A circle indicates an active-LOW state. The alternative symbols are derived as follows:

1. Each input and output of the standard symbol is inverted by adding circles to input and output lines that do not have circles or by removing circles that are already there.

2. The operation symbol is changed from AND to OR, or from OR to AND.

Play and Learn – Gates with Multiple Inputs

Using your knowledge about the behavior of 2-input gates, select the right output levels for each input combination of the corresponding 3-input gate.

Logic Families

CMOS (Complementary Metal Oxide Semiconductor) and TTL (Transistor-Transistor Logic) are the dominant digital IC technologies used to implement logic gates. TTL is built with bipolar junction transistors. CMOS is built with MOS field-effect transistors.

A TTL IC can be distinguished from a CMOS IC by the letters that follow the 74 prefix. For example 74HC00 means high-speed CMOS, while 74LS00 – low-power TTL. The types of logic gates in IC packages are identified by the last two or three digits in the series designation – 00 (NAND), 02 (NOR), 04 (inverter) etc.

Gallery

CMOS – Inside Logic Gates

CMOS ICs combine both n-channel and p-channel MOSFETs. When one device is on, the other is off, and vice versa. Because both devices are in series, the current is determined by the leakage in the off device. So the key advantage of CMOS is its extremely low power dissipation, but this depends on the frequency of operation.

TTL chips need a 5 V dc supply voltage (VCC). CMOS can use 5 V, 3.3 V, 2.5 V and 1.8 V. CMOS can tolerate a wider range of variations in supply than TTL.

Play and learn with CMOS gates. Observe the gate schematics and gate behavior.

Performance Characteristics