Lesson 9: Introduction to digital logic
Digital, or Boolean, logic is the fundamental concept underpinning all modern computer systems.
It is the system of rules that allow us to make extremely complicated decisions based on simple
"yes/no" questions.
Digital circuitry
Digital logic circuits can be broken down into two subcategories- combinational and sequential.
Combinational logic changes "instantly"- the output of the circuit as soon as the input changes
(with some delay, of course, since the propagation of the signal through the circuit elements takes
a little time).
Sequential circuits have a clock signal, and changes propagate through stages of the circuit on
edges of the clock. Typically, a sequential circuit will be built up of blocks of combinational logic
separated by memory elements that are activated by a clock signal.
Digital logic is important in programming, as well. Understanding digital logic makes complex
decision making possible in programs.
Combinational Logic
Combinational circuits are built of five basic logic gates:
AND gate - output is 1 if BOTH inputs are 1
OR gate - output is 1 if AT LEAST one input is 1
XOR gate - output is 1 if ONLY one input is 1
NAND gate - output is 1 if AT LEAST one input is 0
NOR gate - output is 1 if BOTH inputs are 0
There is a sixth element in digital logic, the inverter (sometimes called a NOT gate). Inverters are
not truly gates, as they do not make any decisions. The output of an inverter is a 1 if the input is a
0, and vise versa. In other sources it is mentioned that there are seven gates: the NOT, AND, OR,
NAND, NOR, XOR, and XNOR gates.
Digital logic circuits are usually represented using these six symbols; inputs are on the left and
outputs are to the right. While inputs can be connected together, outputs should never be connected
to one another, only to other inputs. One output may be connected to multiple inputs, however.
Truth Tables
The descriptions above are suitable to describe the functionality of single blocks, but there is a
more useful tool available: the truth table. Truth tables are simple plots, which explain the output
of a circuit in terms of the possible inputs to that circuit.
In Boolean logic, there are only two values, true and false, represented by 1 and 0, respectively.
These values are combined in equations to yield results that also have these two values. The
equations are represented by truth tables that show the inputs to the equation and the outputs
produced for those inputs. The rows of the table contain all the combinations of 1s and 0s for the
inputs. The number of rows is determined by the number of combinations.
Here are truth tables describing the six main elements:
Truth tables can be expanded out to an arbitrary scale, with as many inputs and outputs as you can
handle before your brain melts. Here is what a four-input circuit and truth table look like:
Written Boolean Logic
It is, of course, useful to be able to write in a simple mathematical format an equation representing
a logical operation. To that end, there are mathematical symbols for the unique operations: AND,
OR, XOR, and NOT.
A AND B should be written as AB (or sometimes A • B)
A OR B should be written as A + B
A XOR B should be written as A ⊕ B
NOT A should be written as A' or A
You will note that there are two missing elements on that list: NAND and NOR. Typically, those
are simply represented by complementing the appropriate representation:
A NAND B is written as (AB)' , (A • B)' , or (AB)
A NOR B is written as (A + B)' or (A + B)
To illustrate a truth table and additional concepts that will be introduced, think of an ATM that has
three options: print a statement, withdraw money, or deposit money. The ATM will charge a fee to
(1) withdraw money or (2) print a statement without depositing money. The intent of the problem
is to develop a Boolean equation and logic circuit that will determine the combinations of actions
will result in a fee being charged. First, a truth table should be made for all the combinations of
inputs. The inputs are the ATM's three functions. Let variable P stand for printing a statement, W
for withdrawing money, and D for depositing money. A “1” indicates the user has taken that action
and a “0” indicates the user has not taken that action. There are two outputs -- charge a fee (1) or
do not charge a fee (0). The output column will be denoted by C. The following truth table shows
all the combinations of the inputs and their corresponding outputs.
Boolean Equations
A truth table is used to write a Boolean equation for a problem. All the combinations that yield an
output of 1 are kept, and the equation is written. This is called a Sum of Products solution. Only
the combinations that yield an output of 1 are kept because the Boolean equation intends to
represent a quantitative function when the output will be true (when a fee is charged in the example
of the ATM machine). The combinations that yield an output of 0 are discarded because there is
no interest in when the result has a false value. The Boolean equation for the ATM example can be
seen in Equation 1.
For each of the combinations (rows) resulting in true in Table 1, the terms of the Boolean equation
are determined by multiplying the variables together (the AND operation). If an input is true, the
variable can be used as-is; for an input that is false, the variable is inverted using the horizontal bar
(the NOT operation). Since the output is true if any of the combinations are true, the equation is
formed by using addition operations (the OR operation) on all the terms formed by the product of
each combination.
Karnaugh Maps (K-Maps)
A truth table showing every combination of inputs and their corresponding outputs yields a Boolean
equation that is the solution to a problem in digital logic. This equation can be simplified using
a Karnaugh map (K-map). A K-map identifies and eliminates all the conditions that do not
contribute to the solution. The resulting simplified Boolean equation is used to build the digital
circuit and will be a combination of the logic gates described earlier.
A K-map is a two-dimensional representation of the truth table that shows the common
characteristics of the inputs. For an equation with three inputs, usually all the combinations of the
first two inputs are shown as four columns and the values for the third input are shown as two rows.
For four inputs, all the combinations of the third and fourth inputs are shown as four rows. Only
one value can change at a time in adjacent rows or columns. For example, in Table 5, the columns
change from 00 to 01 to 11 to 10. Table 5 illustrates the K-map for the ATM example.
Simplified Boolean Equations
To develop the simplified Boolean equation, look for the cells that have the 1 value in common.
Look for cells that can physically be boxed together, where the number of cells in the box is a
power of 2 (1, 2, 4, or 8 and so on). The boxes are allowed to overlap so the same cells can be used
more than once. Look for the biggest boxes first, and keep finding smaller boxes until all the cells
with a 1 in them are used. This means that sometimes just single cells will remain at the end. The
cells in the K-map for the ATM example can be grouped like what is shown in Table 6.
Table 6: K-Map Boxes for the ATM Example
In this example, all the cells containing a 1 were covered with two boxes. This means that if the
conditions for either box are true, the output will be true. This also means that the simplified
Boolean equation will only have two terms. The term for each box can be determined by
observing which variables are constant throughout each cell of that box. For the red box, only W
remains constant through the four cells. D switches from the top row to the bottom row, and P
switches from the left column to the right column. For the blue box, P and remains constant
through the two cells, while W switches from the left cell to the right cell. The two boxes yield
the simplified Boolean equation shown in Equation 2.
This equation meets the conditions in the truth table in Table 1 and achieves the desired result with
the minimum number of logic elements.
Lastly, a combinational logic circuit can be created using the simplified equation. First, a NOT
operation is performed on D by inputting and outputting D through a NOT gate. Then, the P and
inverted D are inputted into an AND gate, as denoted by them being multiplied in Equation 2.
Finally, the result of the AND operation between the P and inverted D and the W is inputted into
an OR gate, as denoted by the addition function in Equation 2. The final combinational logic circuit
can be seen in the following figure.
Figure 2: Combinational Logic Circuit for ATM Example
Integrated Circuits
Integrated circuits (IC) can be used to prototype a combinational logic circuit on a breadboard.
These devices are small assemblies of electronic components that have been combined into a
single unit. The IC chips consist of logic gates that can be wired to prototype the logic circuit.
Figure 3: An IC Chip
Each chip consists of multiple logic gates. A 7408 chip consists of four AND
gates, a 7432 chip consists of four OR gates, and a 7404 chip consists of six
NOT gates. These gates can be wired to inputs and outputs to create a
combinational logic circuit. The IC chips must also be connected to a power
source and ground to operate.
The following figure shows how the IC chips can be used to wire the circuit for
the ATM problem. In this circuit in Tinkercad, a piezo buzzer represents the
output. Slide switches control the Print, Withdraw, and Deposit inputs. The
pink wire represents the Print (P) input, the blue wire represents the Withdraw
(W) input, and the yellow wire represents the Deposit (D) inputs.
The input is wired to a NOT gate (Chip 7404) to get a output. This is
wired to an AND gate input (Chip 7408), along with a input to get
a output. This output is wired to an OR gate (Chip 7432), along with a W
input to get the final output of .
https://manual.eg.poly.edu/index.php/Introduction_to_Digital_Logic
https://learn.sparkfun.com/tutorials/digital-logic/all
Exercises:
Answer the following questions:
1. What are the main sub-categories of digital logic circuits?
2. What is the main difference between them?
3. List the basic logic gates.
4. What is a truth table?
5. How to write a boolean equation?
6. What is the role of a K-map?
7. For the gate in the following figure the output is:
Fill in the gaps using the following words:
tablets, electronic, inputs, gates, device, functions, decisions, circuits, combination, switch,
type, represents, used.
A logic gate is a --------- that acts as a building block for digital ----------. They perform basic
logical ----------- that are fundamental to digital circuits. Most--------- devices we use today will
have some form of logic gates in them. For example, logic gates can be used in technologies such
as smartphones,---------- or within memory devices.
In a circuit, logic gates will make -----------based on a combination of digital signals coming from
its inputs. Most logic gates have two -------- and one output. Logic ------- are based
on Boolean algebra. At any given moment, every terminal is in one of the
two binary conditions, false or true. False --------- 0, and true represents 1. Depending on the -----
----- of logic gate being used and the --------- of inputs, the binary output will differ. A logic gate
can be thought of like a light ---------, wherein one position the output is off -- 0, and in another, it
is on -- 1. Logic gates are commonly -------- in integrated circuits (IC).
Translate from French to English:
Les fonctions logiques combinatoires directement issues des mathématiques (algèbre de Boole)
sont les outils de base de l'électronique numérique. Elles sont mises en œuvre en électronique sous
forme de portes logiques. Ainsi les circuits électroniques calculent des fonctions logiques de
l'algèbre de Boole. Ces portes électroniques sont construites à partir de
plusieurs transistors connectés de manière adéquate.