Lesson 1: Logic Gates: Department of Computing and Information Technology
Lesson 1: Logic Gates: Department of Computing and Information Technology
TECHNOLOGY
1
Definition:
• The logic gate is the basic building block in digital
systems used to implement Boolean function.
• Logic gates operate with binary numbers (1/0).
They are are therefore referred to as binary logic
gates
• Basic logic circuits with one or more inputs and one
output are known as gates
• Gates are used as the building blocks in the design
of more complex digital logic circuits
2
Representing Logic Functions
• There are several ways of representing logic
functions:
– Symbols to represent the gates/ Logic
symbol
– Truth tables
– Boolean algebra
We will now describe commonly used gates
4
NOT Gate (INVERTER)
Symbol
Truth-table Boolean
y=a
a y Input Output
a y
0 1
1 0
5
AND Gate
Symbol Truth-table Boolean
a y a b y
0 0 0 y = a.b
b
0 1 0
1 0 0
1 1 1
a
y=a+b
a b not read as a plus b
b
0 0 0
0 1 1
1 0 1
1 1 1
7
UNIVERSAL GATES
• A universal gate is a gate which can implement any Boolean
function without need to use any other gate type.
• The NAND and NOR gates are universal gates.
• Y=A+B
• In practice, this is advantageous since NAND and NOR gates
are economical and easier to fabricate and are the basic gates
used in all IC digital logic families. In fact, an AND gate is
typically implemented as a NAND gate followed by an inverter
not the other way around!!
• Likewise, an OR gate is typically implemented as a NOR gate
followed by an inverter not the other way around!!
SIT 112_INTRODUCTION TO DIGITAL
8
ELECTRONICS
9
NOT AND (NAND) Gate
y = a.b
0 0 1
0 1 1
1 0 1
1 1 0
11
EXCLUSIVE OR (XOR) Gate
a a b y y=a b
y 0 0 0
b 0 1 1
1 0 1
1 1 0
a a b y y=a b
y 0 0 1
b 0 1 0
1 0 0
1 1 1
• From the truth table when the inputs are not the same the output is
LOW/FALSE otherwise the output will be HIGH/TRUE. This gives
the gate the characteristic equality comparator
13
Lesson 2
14
LAWS AND RULES OF BOOLEAN
ALGEBRA
• Boolean algebra is used to express logic
circuits mathematically.
• It is used to simplify logic circuits thus
minimizes amount of logic gates used to
perform a specific function
15
Rules of Boolean Algebra
• There are 14 basic rules that are useful in
manipulating and simplifying Boolean
expressions. Rules 1 through 9 will be viewed
in terms of their application to logic gates.
Rules 10 through 14 can be derived in terms
of the simpler rules and the laws previously
discussed
13 AB + A’C + BC = AB + A’C
17
14 (A+B)(A’+C)(B+C)=(A+B)(A’+C)
Proof of rules 10,11 & 12
Rule 10
A + AB = A
We use rule 2, 4 and distributive law to prove
the left side
A + AB
=A.1 + A.B
=A(1+B), Distributive law, rule 2
=A.1, rule 2
=A , rule 4
SIT 112_INTRODUCTION TO DIGITAL
18
ELECTRONICS
Rule 11
A + A’B = A + B
Left side A + A’B
= A.1 + A’B, rule 4
= A(1+B) + A’B , rule 2
= A.1 + A.B + A’B, rule 12
= A + B(A +A’), rule 4 and 12
=A + B.1, rule 6
= A + B, rule 4
(A + B) (A+C) = A + BC
A Y= A+B B Y= B+A
B
≡ A
C
D CD
B B+CD
A(B+CD)
A
34
• The cells are arranged in a way so that simplification of
a given expression is simply a matter of properly
grouping the cells.
• Karnaugh maps can be used for expressions with two,
three, four. and five variables.
• The number of cells in a Karnaugh map is equal to the
total number of possible input variable combinations as
is the number of rows in a truth table.
• For three variables, the number of cells is 23 = 8.
• For four variables, the number of cells is 24 = 16.
35
The 3-Variable Karnaugh Map
• The 3-variable Karnaugh map is an array of eight cells. as
shown in Table (a). In this case, A, B, and C are used for the
variables although other letters could be used.
• Binary values of A and B are along the left side (notice the
sequence) and the values of C are across the top.
• The value of a given cell is the binary values of A and B at
the left in the same row combined with the value of C at
the top in the same column. For example, the cell in the
upper left corner has a binary value of 000 and the cell in
the lower right corner has a binary value of 101.
• Table( b) shows the standard product terms that are
represented by each cell in the Karnaugh map.
36
0 1 0 1
AB C AB C
00 00 A’B’C’ A’B’C
A’BC’ A’BC
01 01
ABC’ ABC
11 11
AB’C’ AB’C
10 10
(a) (b)
37
Cell Adjacency
• The cells in a Karnaugh map are arranged so that there
is only a single variable change between adjacent cells.
• Adjacency is defined by a single variable change.
• This ensures that physical neighbours in the array are
logical neighbours as well (i.e neighbouring bit patterns
are nearly the same, differing by only 1 bit)
• In the 3-variable map the 010 cell is adjacent to the
000 cell, the 011 cell, and the 110 cell. The 010 cell is
not adjacent to the 001 cell, the 111 cell, the 100 cell,
or the 101 cell.
38
Adjacent cells on a Karnaugh map are those
that differ by only one variable.
Arrows point between adjacent cells
39
• This one bit change applies at the edges too.
• So the cells in the same row on the left and
right edges of the array also differ by one bit.
40
Rules for the K-map
• Each cell with a 1 must be included in at least one group
• Try to form the largest possible groups
• Try to end with as few groups as possible
• Groups may be in sizes that are powers of 2 i.e 20 , 21,
22,23,24 ……
• Groups may be square or rectangular ONLY (including wrap
around at the grid edges). No diagonals or zigzags can be
used to form groups
• The larger the group is the more redundant inputs there
are
• Allow overlapping and wrap around
• Group may not include any cell containing a zero
41
• Fold up the corners of the map below like it
is a handkerchief to make the four cells
physically adjacent. (WRAPAROUND)
42
Redundant inputs
• If there are two neighbouring 1’s in the grid, it
means that the input bit change between the
two cells has no effect on the output and thus
there is a redundancy.
– A group of 1 has no redundant input
– A group of 2 has 1 redundant input
– A group of 4 has 2 redundant inputs
– A group of 8 has 3 redundant inputs
– A group of 16 has 4 redundant inputs
43
Looping
• The expression for the output can be simplified by
properly combining those squares in the k-map that
contain 1.
• The process of combining these 1’s is called looping.
• Looping a pair of adjacent 1’s in a k-map eliminates the
variable that appears in complemented and
uncomplemented form
• When a variable appears in both complemented and
uncomplemented form within a loop, that variable is
eliminated from the expression.
• Variables that are the same for all squares of the loop
must appear in the final expression
44
The steps below are followed in using the K-map
method for simplifying a Boolean expression:
• Step 1 Construct the K map and place 1s in those
squares corresponding to the 1s in the truth table.
Place 0s in the other squares.
• Step 2 Examine the map for adjacent 1s and loop
those 1s that are not adjacent to any other 1s.
These are called isolated 1s.
• Step 3 Next, look for those 1s that are adjacent to
only one other 1. Loop any pair containing such a 1.
45
• Step 4 Loop any octet even if it contains some 1s
that have already been looped.
• Step 5 Loop any quad that contains one or more
1s that have not already been looped, making
sure to use the minimum number of loops.
• Step 6 Loop any pairs necessary to include any 1s
that have not yet been looped, making sure to
use the minimum number of loops.
• Step 7 Form the OR sum of all the terms
generated by each loop.
46
Example
• We will assume that the map was obtained
from a truth table
0 1 1 0
01
0 1 1 0 BD (2 redundant
11 inputs- A & C)
0 0 1 0
10 ACD (1 redundant input-B)
47
X = A’B’CD’ + ACD + BD
48
Use a K map to simplify y = C’(A’ B’ D’ + D) + AB’C + D’
Solution
•Multiply out the first term to get y = A’ B’ C’ D’ + C’D +
AB’C + D which is now in SOP form.
•For the term A’ B’ C’ D’ , simply put a 1 in the A’ B’ C’ D’
square of the K map (Figure 4-17).
•For the term C’D, place a 1 in all squares with C’D in their
labels, that is A’ B’ C’D, ABC’D, A’BC’D, A B’ C’D,
49
• For the AB’C term, place a 1 in all squares that have
AB’C in their labels, that is A B’ C D’, A B’ C D
• For the D’ term, place a 1 in all squares that have a
D’ in their labels, that is, all squares in the leftmost
and rightmost columns.
• The remaining cell put zeros
50
C’
D’
AB CD 00 01 11 10
00 1 1 0 1
1 1 0 1
01
AB’
1 1 0 1
11
1 1 1 1
10 Y=AB’+ C’+ D’
51
Converting a Boolean Function From Truth
Table to SOP Algebraic Equation
A B C Output (X)
0 0 0 0
0 0 1 0
0 1 0 0 Express the boolean
0 1 1 1 expression for X in
1 0 0 0 the following truth
1 0 1 1 table?
1 1 0 1
1 1 1 1
52
• Write a Boolean product expression for each row where the output column equals 1
• In simple terms, the output is true (or high) if any of the following statements are
true:
– B and C are true, A is NOT true..
– A and C are true, B is NOT true.
– A and B are true. C is NOT true.
– A,B and C are true
Using the chart in the example above, the Boolean expressions would be:
A'BC, AB’C, ABC’ ABC
• Join the product expressions by adding them with a + operator. Continuing the
example, the Boolean equation would be
OUTPUT (X) = A'BC + AB’C + ABC’ + ABC
53
K-MAP
• Consider the expression Z=f(A,B)=A’B’ +
AB’ + A’B plotted on the Karnaugh map:
54
• Pairs of 1's are grouped as shown above, and the simplified
answer is obtained by using the following steps:
Note that two groups can be formed for the example given
above, bearing in mind that the largest rectangular clusters
that can be made consist of two 1s. Notice that a 1 can
belong to more than one group.
55
• For group labelled II corresponds to the area of
the map where A = 0. The group can therefore
be defined as A’. This implies that when A = 0
the output is 1. The output is therefore 1
whenever B = 0 and A = 0
• Hence the simplified answer is
Z=A’+B’
56
• Minimise the following problems using the
Karnaugh maps method
57
• The minimised result obtained is
58
Lesson 4
59
COMBINATIONAL LOGIC CIRCUITS
• Unlike sequential logic circuits whose outputs are
dependant on both their present input and
previous output state giving them some form of
memory, the outputs of combinational logic
circuits are only determined by the logical
function of their current input state Logic “0” or
logic “1” at any instant in time as they have no
feedback and any change to the signals being
applied to their inputs will immediately have an
effect on the output
60
• Combinational circuits have no memory,
timing (clocks) or feedback loops
• Examples of Combinational circuits:
– Decoder, Encoder, Multiplexer, De-multiplexer,
Adders, subtructors and comparator
• Examples of Sequential circuits:
– Flip flops and latches
61
DECODERS
• A decoder is a logic circuit that accepts a set of inputs
that represents a binary number and activates only the
output that corresponds to that input number.
• In other words, a decoder circuit looks at its inputs,
determines which binary number is present there, and
activates the one output that corresponds to that
number; all other outputs remain inactive.
• It is a combinational circuit that converts N bits of
binary information of input lines to a maximum of 2N
unique output lines.
62
• In its general form, a decoder has N input lines to
handle N bits and form one to 2 N output lines to
indicate the presence of one or more N-bit
combinations
• The basic binary function
• An AND gate can be used as the basic decoding
element because it produces a HIGH output only
when all inputs are HIGH
63
General Decoder Diagram
A0
O0
N inputs A1 DECODER
O1
A2 O2
M outputs
AN-1 OM-1
Only one output
input
is HIGH for each
codes
input code
# There are 2N possible input combinations, from A0 to AN1.
SIT 112_INTRODUCTION TO DIGITAL
64
ELECTRONICS
• Because each of the N inputs can be 0 or 1, there 2N are
possible input combinations or codes. For each of these
input combinations, only one of the M outputs will be
active HIGH (1); all the other outputs are LOW (0).
• Many decoders are designed to produce active-LOW
outputs, where only the selected output is LOW while all
others are HIGH. This situation is indicated by the presence
of small circles on the output lines in the decoder diagram.
• Note that for a given input code, the only output that is
active (HIGH) is the one corresponding to the decimal
equivalent of the binary input code (e.g., output O6 goes
HIGH only when CBA = 1102 = 610).
A0
O0 A0 O0
A1
A1
O1 O1
O2 O2
O3 O3
EN EN
O0
O
1
0
2
O3
EN
SIT 112_INTRODUCTION TO DIGITAL
72
ELECTRONICS
• As we can see in the truth table for each input
combination, one output line is activated i.e. the
output line corresponding to the input combination
becomes 1 while other lines remain inactive(LOW).
• For example an input of 01 at the input will activate
line O1.
• Notice also that each output of the decoder is actually
a minterm resulting from certain combination of inputs
i.e. O0 = A1’AO’(Minterm Mo ) corresponds to output 00,
O1= A1’A0 ’(Minterm M1 ) corresponds to output 01
EN
• Solution:
•Each I/O port has a number, called an address, which uniquely identifies it. When
the computer wants to communicate with a particular device, it issues the
appropriate address code for the I/O port to which that particular device is
connected . The binary port address is decoded and appropriate decoder output is
activated to enable the I/O port
•Binary data are transferred within the computer on a data bus, which is a set of
parallel lines
I0
O0
I1 O1
2N inputs only ENCODER
one HIGH at a I2 O2
time N outputs
IM-1 ON-1
Output lines generate the
binary code corresponding to
M= Number of inputs active input
N= Number of outputs
SIT 112_INTRODUCTION TO DIGITAL
83
ELECTRONICS
4 to 2 encoder (active HIGH inputs)
• Accepts 4 inputs lines and produce 2 bits output code
corresponding to the activated input
I0
O0 LSB
I1 O1 MSB
4 to 2
I2 ENCODER
I3
M=4, N=2
LOGIC SYMBOL
84
Truth table
INPUTS OUTPUTS
I3 I2 I1 I0 O1 O0
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
O 0 = I1 + I 3
O 1 = I2 + I 3
I I I I
3 2 1 0
O0 = I + I
1 23
O1 = I + I
2 3
Note that the I0 is not connected to the logic gates because the
encoder outputs will normally be at 0 0 when none of the inputs
I1 to I3 is HIGH
86
An Octal to binary encoder (8 line to 3 line
encoder) with active HIGH inputs
I0
O0 LSB
I1 O1 MSB
8 to 3
I2 ENCODER O2
I7
M=8, N=3
LOGIC SYMBOL
88
Truth table
INPUTS OUTPUTS
I7 I6 I5 I4 I3 I2 I1 I0 O2 O1 O0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
O0 = I1 + I3 + I5 + I7
O1 = I2 + I3 + I6 + I7
O2 = I4 + I5 + I6 + I7
89
8 to 3 line encoder Logic circuit
I I I I I I I1 I0
7 6 5 4 3 2
O0 = I + I + I5 + I
1 3 7
O
1
= I + I + I6 + I
2 3 7
O2
= I + I + I + I
4 5 6 7
91
Priority Encoders
• In this type of encoder, a priority is assigned to
each input so that, when more than one input is
simultaneously active, the input with the highest
priority is encoded
• For example if I5 and I7 are active at the same time
line I5 will be ignored and I7 will be encoded
• Therefore, the output code will be 111
• You will note that with the previous encoders if
two or more inputs are active simultaneously, the
output produces undefined conditions.
SIT 112_INTRODUCTION TO DIGITAL
92
ELECTRONICS
Design 8 line to 3 line priority encoder with active high
inputs
TRUTH TABLE
2N (input source) 1
MUX
Output Destination
N (Select lines)
Laptop sound D0
card D1
D2 Y Surround sound
Digital satellite D3 system
Digital cable TV
(MSB)A B (LSB)
D
1
2 Y
D2
3
D3
4
A B
SELECT LINES
DEMUX
1 2N
Input source Output (destination)
Select lines
O1 Fax machine
DEMUX
I
Computer O2
Pen plotter
O1
O
2
O3
A B
SELECT LINES
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
113
• Where S is the sum and C is the carry
• We can also say that
S=X YY
(Using XOR and AND Gates)------------2
C = XY
115
Implementation of half adder using equation 1
X Y
X Y
00 0 1 00 0 0
1 0 0 1
01 01
0 1 1 1
11 11
1 0 0 1
10 10
C
out
C
out
S Q
_
R Q
R Q
S Q
_
R Q
Q'
S
S
Q S Q
R Q’
Q'
R
Logic circuit Logic symbol
0 0 Qn
0 1 0
1 0 Qn
1 1 1
Q
Control inputs
Clock CLK
Q’
Edge detector
CLK
RESET' IV Q'
R III
Control Gates SR NAND latch
CLK
Q’
Logic symbol
D SET' Q
I II
Edge detector
CLK
RESET' IV Q'
III
SET' Q
J I
II
Edge detector
CLK
RESET' IV Q'
K III
Control Gates SR NAND latch
CLK
In the truth table you can use or to represent negative edge triggering