Practical Electronics/Logic

In the sense of electronics, logic means that the circuit works using only two voltage levels - high and low (or on/off, true/false or 1/0). These voltage levels are sometimes called logic levels and digital circuits use only these logic levels to represent information.

Logic Gates
Logic gates are devices that can combine multiple inputs at independent logic levels and come up with an output accordingly. There are many kinds of logic gates, and the distinction lies in that each kind processes the inputs differently, and may give different outputs for the same inputs.

The way the logic gate processes different inputs is given in a truth table for that gate, which lists all the possible combinations of inputs next to their outputs. An example is given for a simple one-input gate with the function of giving the opposite logic level at the output to the one at the input. The inputs are given on the left, and the outputs are on the right. Generally, the inputs are called A, B, C, etc., and the output is labelled Q. In this case, there are only two possible inputs, 1 or 0, but logic gates can have any number of inputs.

There are seven kinds of logic gates, each kind of logic gate has a circuit symbol associated with it. In fact, there are several conflicting standards defining the symbols for logic gates. The standard symbols are ANSI symbols, sometimes called the MIL symbols. These are the most distinctive and are widely used and recognised. It is recommended to use these symbols for basic logic circuits, and this wikibook will use them to the exclusion of the others. It is better to use the IEC (rectangular) symbols for advanced logic designs, but this is at a higher level that this book. The comparison between the three symbol sets is given here.

Boolean Algebra
In 1847, George Boole invented a shorthand method of writing logical statement that are either true or false. Boole proved that binary (2 valued nature of his logic) is applicable for symbols, letters and even words itself. His branch of logic is now an integral part of Mathematics. His mathematical analysis of logic statements became known as Boolean Algebra.

It wasn't until 1940 when Claude Shannon notice the characteristic of the Boolean Algebra which only has 2 values True and False are also applicable to the design of telephone switching circuits. His paper A Symbolic Analysis of Relay and Switching Circuits is considered as the most significant master’s theses of the 20th century.

Boolean algebra is a way to mathematically express logical operations performed on data. There are symbols for the operations performed by each logic gate, and these are given in the relevant sections below. It uses several symbols that are not generally used anywhere else, and the use of these will be also be explained below. Boolean algebra can be used to represent several logical operations done at once, and this is explained in this section.

Each kind of gate has its own symbol used when writing the functions down, but ideally, only the symbols for NOT, AND, OR and XOR are used, to reduce confusion, and to ease simplification.

NOT


A NO gate or a inverter is the simplest kind of logic gate. Its function is to give the opposite output to its input - if it gets high, it gives a low, and vice versa. This is equivalent to saying that the output is not the input.

The circuit symbol for a NOT gate is a triangle with the point facing towards the output, and a circle at the output.

The Boolean symbol for the NOT operator is either a line over the relevant input. Thus, Boolean expression output, Q, is not the input, A, is


 * $$\bar{A}=Q$$

NOT gates can be implemented in a variety of ways. See the following for more information:


 * 4049 - The standard CMOS inverter. This IC contains six independent inverters.
 * Alternatives to an inverter. This page details methods other than using a 4049 for achieving a logical NOT operation.



AND


An AND gate gives an output of logic 1 only when both inputs are 1. If either one or all inputs are 0, then the output is also 0. This is equivalent to saying that the output is high when one input and the other one are high. Thus, the AND gate is also known as 'all-or-nothing' gate.

The circuit symbol for an AND gate is a box with one rectangular end (inputs) and one semi-circular end (output).

Boolean multiplication is equivalent to the AND function (see why here Thus, the AND gate can be represented by a multiplication dot &middot; or just putting the two terms together.


 * $$A \cdot B=Q$$ or $$AB=Q \,$$.

See the following for more information on the implementation of AND gates:


 * 4081 - The standard CMOS AND gate. This IC contains four independent AND gates.
 * Alternatives to an AND Gate. This page details methods other than using a 4081 for achieving a logical AND operation.



NAND


A NAND gate gives a low output only when both inputs are high. If one or more inputs is low, then the output is high. This is equivalent to saying that the output is NOT the output of an AND gate presented with the same inputs. This NOT AND combination is shortened to just NAND.

The circuit symbol, left, for an NAND gate is a box with one rectangular end (inputs) and one semi-circular end (output). This output end has a small circle, denoting an inversion.

The Boolean symbol for the NAND operator is a vertical line (the Sheffer Stroke). Thus, the NAND gate can be represented by the Boolean statement


 * $$A | B=Q \,$$

NAND can also be written as the negation (NOT) of the AND:


 * $$\overline {A \cdot B}=Q$$ or $$\overline {A B}=Q \,$$.

This is the preferred notation, as it is easier to see what is happening in terms of the basic functions.

See the following for more information on the implementation of AND gates:


 * 4011 - The standard CMOS NAND gate. This IC contains four independent NAND gates.
 * Alternatives to an NAND Gate. This page details methods other than using a 4011 for achieving a logical NAND operation.

NAND gates have the property that any other logic gate can be mode from just NAND gates. For the method of achieving this, see NAND Logic(NAND logic).



OR


An OR gate gives a high output if any input is high. If all inputs are low, then the output is low. This is equivalent to saying that the output is high only when one OR the other OR both inputs are high.

The circuit symbol, left, for an OR gate is similar to that of an AND gate, but with a pointed end (outputs) and a concave end (inputs).

Boolean addition is equivalent to the OR function (see why here Thus, the OR gate can be represented by a plus sign (+):


 * $$A + B=Q \,$$

A V-shaped symbol can also be used, but it is not common and should not generally be used.


 * $$A \lor B=Q \,$$

See the following for more information on the implementation of OR gates:


 * 4071 - The standard CMOS OR gate. This IC contains four independent OR gates.
 * Alternatives to an OR Gate. This page details methods other than using a 4071 for achieving a logical OR operation.



NOR


A NOR gate gives a high output only if no inputs are high. If an input is high, then the output is low. This is equivalent to saying that the output is high only when when neither one NOR the other input is high. It is the opposite to an OR gate.

The circuit symbol, left, for a NOR gate is similar to that of an OR gate, but for the addition of a circle to denote the inversion from an OR gate.

NOR can also be written as the negation (NOT) of the OR:


 * $$\overline {A + B}=Q$$.

This is the preferred notation. Another symbol for the NOR operator is a symbol like "⊥", which can be used when the line over the top cannot easily be drawn (e.g. in normal text like this):


 * $$A \perp B=Q \,$$

See the following for more information on the implementation of NOR gates:


 * 4001 - The standard CMOS NOR gate. This IC contains four independent NOR gates.
 * Alternatives to an NOR Gate. This page details methods other than using a 4001 for achieving a logical NOR operation.

NOR gates have the property that any other logic gate can be mode from just NOR gates. For the method of achieving this, see NOR Logic.

XOR


An XOR gate short for "exclusive-OR", gives a high output if one input is high and the other is low. If both inputs are the same, the output is low. This is equivalent to saying that the output is high only when one OR the other but not both inputs are high.

The circuit symbol, left, for an XOR gate is similar to that of an OR gate, but with a double line at the concave input end.

The Boolean symbol for the XOR operator is a plus-sign in a circle or, because it only returns a high when the inputs are different, a not-equal-to sign (not generally used). Thus, the XOR gate can be represented by the Boolean statements


 * $$A \oplus B=Q \,$$ or $$(A \ne B)=Q \,$$

See the following for more information on the implementation of XOR gates:


 * 4030 - The standard CMOS XOR gate. This IC contains four independent XOR gates.
 * Alternatives to an XOR Gate. This page details methods other than using a 4030 for achieving a logical XOR operation.

XNOR


An XNOR gate short for "exclusive-NOR", gives a high output if both outputs are the same - it is the opposite of the XOR gate.

The circuit symbol, left, for an XNOR gate is similar to that of an XOR gate, but it has a circle representing the inversion at the output.

XNOR is written as the negation of the XOR function:


 * $$\overline{A \oplus B}=Q$$

As the XNOR function only returns a "one" when both inputs are the same, the Boolean symbol for the XNOR operator is an equivalent-to sign (≡) sign (not equals) in normal text. Because this looks very much like an equals sign it is easily mistaken and should not be used where possible.


 * $$(A \equiv B)=Q \,$$

See the following for more information on the implementation of XNOR gates:


 * 4077 - The standard CMOS XNOR gate. This IC contains four independent XNOR gates.
 * Alternatives to an XNOR Gate. This page details methods other than using a 4077 for achieving a logical XNOR operation.

Uses of Logic Gates
Logic gates underpin most of the digital electronics, indeed the entire on-board computer in the Apollo spacecraft was made entirely out of NOR gates. It just consists of contained just six transistors and eight resistors, implementing two 3-input NOR gates. (See diagram on right).

It is a very simple logic gate: if all inputs are low, the output is high. However, NOR is a universal gate meaning that you can make any other logic gate out of NOR gates. For instance, the inputs of a NOR gate are wired together forms an inverter. Putting an inverter on the output of a NOR gate produces an OR gate. Putting inverters on the inputs of a NOR gate produces an AND gate.

We start out by trying out very simple examples.

Example 1: Washing Machine
Imagine you are tasked with designing a washing machine that only functions when that it fulfils 3 conditions: The water sources are turned on, the washing machine is loaded with clothes and the door is closed.

This can be done by ANDing the first two conditions and ANDing the third. Now, AND these together, and you get a high only when all three conditions are satisfied.

The Boolean equations can be summarised as followed:
 * Washing Machine (S) can be started if
 * Water Sources are turned on (A)
 * AND Washing machine is loaded with clothes (B)
 * AND The door is closed (C)

or it can be summarised as S=A.B.C

Hence the truth table for Boolean equation contains eight possible scenarios are as followed, where 0 denotes FALSE and 1 denotes TRUE



By using just three logic AND gates, the problem has been solved.

Example 2: Security Alarm
You need to design a security alarm to protect a bank vault from unauthorized entry through the door and window when keyswitch is armed. The security alarm will be triggered when the keyswitch is armed and if either door or window is opened.

We assume 0 is FALSE and 1 is TRUE.

The Boolean equations can be summarised as when Keyswitch is armed, if door OR window is opened, the alarm will be triggered


 * The alarm system (S) activated if keyswitch (K) is armed AND
 * The window (W) is opened OR
 * The door (D)is opened OR
 * Both door and window are opened

or it can be summarised as S=K.(W+D) Hence the truth table for Boolean equation contains eight possible scenarios are as followed, where 0 denotes FALSE and 1 denotes TRUE



Other Applications
However, logic gates are also used to make flip-flops and other vital electronic components.

One convenient use of them is as transmission gates which allow a signal to pass only under certain conditions.