Professional Documents
Culture Documents
Chapter 6 Combinational Logic - Mod-3
Chapter 6 Combinational Logic - Mod-3
1 + 1 + 0 0 1 B(Cin)
= 1 3 7 5
1 + 1 + 1 1 1 1 `1 1 1 Cin
=
S(A,B,Cin) = Sm(1,2,4,7) B
C-out(A,B,Cin) = Sm(3,5,6,7) C-out = AB + A(Cin) + B(Cin)
Full Adder
Full Adder Circuit Using X-OR:
A B
Full
C-out C-in
Adder
Block diagram
Circuit
Full Adder
Design Full Adder by using Half Adder
S
A
S
B
Cout
Cin
Symbol
n-bit Carry Ripple Adder
A single full adder is capable of adding 1 bit numbers and an input
carry.
An n-bit adder expansion used to add binary numbers with
more than one bit(2 bit, 3 bit, 4 bit…n bit)
If there are 2-bit numbers, two adders are needed; for 4-bit
numbers, four adders are used and so on.
It can built by cascading all the adders.
o Carry input of full adder for least significant position is 0
(grounded).
o The carry output of each adder is connected to the carry
input of the next higher-order adder.
MSB LSB
4-bit Carry Ripple Adder
Inputs to be added
Adds two 4-bit numbers:
A3A2A1A0 B3B2B1B0
A = A3 A2 A1 A0
B= B3 B2 B1 B0
producing the sum S = S3 S2 S1 S0 ,
C-out = C4 from the most significant 4-bit
C4 C-out C-in C0 =0
position j=3 Adder
Sum Output
A3 B3 A2 B2 A1 B1 A0 B0
S3 S2 S1 S0
Sum output
An example of 4-bit addition
• Let’s try our initial example: A=1011 (eleven), B=1110 (fourteen).
1 1 1 0 1 1 0 1
0
1 1 0
1 1 0 0 1
2n Inputs
◦ An n-bit select input S used for control d2
Mux
. Y
.
.
◦ One output Y d2n–1
n
S
The n-bit select input directs one of the data inputs to the output
Multiplexer
Data selector
SELECT input code determines
which input is transmitted to
output Z.
2 inputs multiplexer
Multiplexer
4 inputs multiplexer
Multiplexer
Alternative Implementation
S1 S0
S2
control signals B and C simultaneously choose
one of I0, I1, I2, I3 and one of I4, I5, I6, I7
S2 S0
S1
control signal A chooses which of the upper or
lower mux's output to gate to Z
Building Larger Multiplexers
Larger multiplexers can be built hierarchically using smaller ones
d0 0 d0 0
d0 0 d1 1 d1 1
Mux
Mux
d2 2
8-to-1 Mux
d1 1 d2 2
0 d3 3
d3 3
Mux
S0 Y Y
1 0 d4 4
Mux
d2 0 S1S0 Y d5 5
Mux
S1 1
d3 1 d6 6
d4 0
S2 d7 7
d5 1
Mux
S0
d6 2 S2S1S0
d7 3
8-to-1 Mux
used as select 0 0 1 1
0 3
lines to a Mux. 0 1 0 1 F
0 4
0 1 1 0
An 8-to-1 1 0 0 0 0 5
Mux is used 1 0 1 0 1 6
because there 1 1 0 1 1 7 1
0
2
1 1 1 1
are 3 variables
S2 S1 S0 = a b c
Better Solution with a Smaller Multiplexer
Re-implement F(a, b, c) = ∑(1, 2, 6, 7) using a 4-to-1 Mux
We will use the two select lines for variables a and b
Variable c and its complement are used as inputs to the Mux
4-to-1 Mux
0 1 0 1
F = c' c' 1
0 1 1 0 F
1 0 0 0 0 2
F=0
1 0 1 0
0
1 1 0 1 1 3 1
F=1
1 1 1 1
S1 S0 = a b
Implementing Functions: Example 2
Implement F(a, b, c, d) = ∑(1,3,4,11,12,13,14,15) using 8-to-1 Mux
Inputs Output Comment
a b c d F F
0 0 0 0 0 d 0
0 0 0 1 1
F=d
0 0 1 0 0 1
0 0 1 1 1
F=d
0 1 0 0 1
2
8-to-1 Mux
0 1 0 1 0
F = d'
0 3
0 1 1 0 0 F
0 1 1 1 0
F=0 4
1 0 0 0 0 5
1 0 0 1 0
F=0
1 0 1 0 0 1 6
1 0 1 1 1
F=d
0
1 1 0 0 1
7 1
2
1 1 0 1 1
F=1
1 1 1 0 1
1 1 1 1 1
F=1 S2 S1 S0 = a b c
Multiplexers as general logic purpose
A 2n:1 multiplexer can implement any function of n variables
-with the variables used as control inputs and
-the data inputs tied to 0 or 1
Example
F(A,B,C) = m0 + m2 + m6 + m7 = A'B'C' + A'BC' + ABC’ + ABC
= A'B'C‘(1) + A’B’C(0) + A'BC‘(1) + A’BC(0)
+ AB’C‘(0) + AB’C(0) + ABC’(1) + ABC(1)
– For each minterm mi of the function, connect 1 to mux data input Di.
Each data input corresponds to one row of the truth table.
– Connect the function’s input variables to the mux select inputs. These
are used to indicate a particular input combination.
x y z f
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Multiplexers as general logic purpose
• We can actually implement f(x,y,z) = Sm(1,2,6,7) with x y z f
just a 4-to-1 mux, instead of an 8-to-1. 0 0 0 0
• Step 1: Find the truth table for the function, and 0 0 1 1
group the rows into pairs. Within each pair of rows, x 0 1 0 1
and y are the same, so f is a function of z only. 0 1 1 0
– When xy = 00, f=z 1 0 0 0
– When xy = 01, f=z’ 1 0 1 0
– When xy = 10, f=0 1 1 0 1
– When xy = 11, f=1 1 1 1 1
F(A,B,C) = m0 + m2 + m6 + m7
= A'B'C' + A'BC' + ABC' + ABC
= A'B'(C') + A'B(C') + AB'(0) + AB(1)
Examples of Multiplexers
2-to-1 Multiplexer Inputs Output
d0 0
if (S == 0) Y = d0 ; S d0 d 1 Y
Mux
Y
else Y = d1; d1 1
0 0 X 0 = d0
0 1 X 1 = d0
Logic expression: 1 X 0 0 = d1
′
S 1 X 1 1 = d1
𝑌 = 𝑑0 𝑆 + 𝑑1 𝑆
Mux
𝑌
else if (S1S0 == 01) Y = d1; d2 2 0 0 0 X X X 0 = d0
3 0 0 1 X X X 1 = d0
else if (S1S0 == 10) Y = d2; d3
0 1 X 0 X X 0 = d1
else Y = d3; S1S0 0 1 X 1 X X 1 = d1
1 0 X X 0 X 0 = d2
Logic expression: 1 0 X X 1 X 1 = d2
𝑌 = 𝑑0 𝑆1′ 𝑆0′ + 𝑑1 𝑆1′ 𝑆0 + 𝑑2 𝑆1 𝑆0′ + 𝑑3 𝑆1 𝑆2 1 1 X X X 0 0 = d3
1 1 X X X 1 1 = d3
Implementing Multiplexers
d0
d0 0
Mux
𝑌 = 𝑑0 𝑆 ′ + 𝑑1 𝑆 Y
d1
d1 1
Enabling
S AND Gates
S
d0
d0 0
d1
d1 1
Mux
𝑥 𝑓 𝑥 𝑓 𝑥 𝑓
inverted c inverted f inverted c, f
c x f c x f c x f
0 0 0 0 0 Z 0 0 1
0 1 1 0 1 Z 0 1 0
1 0 Z 1 0 1 1 0 Z
1 1 Z 1 1 0 1 1 Z
Wired Output
Logic gates with 0 and 1 𝑎 This will result in a
𝑏
outputs cannot have their 𝑓 short circuit that
𝑐
outputs wired together 𝑑 will burn the gates
𝑐1 c1 c2 c3 f
3-state gates can wire 0 0 0 Z
their outputs together 𝑥1 1 0 0 x1
𝑐2 0 1 0 x2
At most one 3-state gate 𝑓
0 0 1 x3
𝑥2
can be enabled at a time 0 1 1 Burn
𝑐3 1 0 1 Burn
Otherwise, conflicting 1 1 0 Burn
𝑥3
outputs will burn the circuit 1 1 1 Burn
Implementing Multiplexers with 3-State Gates
A Multiplexer can also d0 0
be implemented using: d1 1
Mux
2
𝑌
1. A decoder d2 3-State
d3 3 Gates
2. Three-state gates
d0
S1S0
3-State
d1
Gates Y
d0 0 d0 d2
Mux
Y Y
d1 1 d1 d3
S 0 1 2 3
S S1 1 2-to-4
1-to-2
Decoder S0 0 Decoder
Demultiplexer
Performs the inverse operation of a Multiplexer
2n Outputs
Demux
2. An n-bit select input S I d2
.
.
.
3. A maximum of 2n data outputs d2n–1
n
S
The Demux directs the data input to one of the outputs
1-line-to-8-line demultiplexer
Demultiplexer
Example: 1- to -4 Demultiplexer
Mux-Demux Application: Example
2 Outputs
if (S == 0) { d0 = I ; d1 = 0; } 0 d0
Demux
I
else { d1 = I ; d0 = 0 ; }
1 d1
Output expressions:
𝑑0 = 𝐼 𝑆 ′ ; 𝑑1 = 𝐼 𝑆 S
1-to-4 Demultiplexer
if (S1S0 == 00) { d0 = I ; d1 = d2 = d3 = 0; } 0 d0
4 Outputs
Demux
else if (S1S0 == 01) { d1 = I ; d0 = d2 = d3 = 0; } I 1 d1
else if (S1S0 == 10) { d2 = I ; d0 = d1 = d3 = 0; } 2 d2
10
else { d3 = I ; d0 = d1 = d2 = 0; } 3 d3
0 d0
0 d0 S1 = a1 1
2-to-4 1 d1
4 Outputs
S0 = a0 0
Demux
1 d1 Decoder 2 d2
I
2 d2 I = EN 3 d3
10
3 d3
Think of a decoder as directing the
S1S0 Enable signal to one output
m m A[m–1:0] 0 m
Mux
A[m-1:0] 2×2 X [m-1:0] m X [m-1:0]
B[m–1:0] 1
Crossbar m
m m S
B[m-1:0] Switch Y [m-1:0]
0 m
Mux
Y [m-1:0]
1
S
Sorting Two Unsigned Integers
Design a circuit that sorts two m-bit unsigned integers A and B
Inputs: Two m-bit unsigned integers A and B
Outputs: X = min(A, B) and Y = max(A, B)
Solution:
We will use a magnitude comparator to compare A with B, and
2×2 crossbar switch implemented using two 2-input multiplexers
B[m–1:0] 0 m
Mux
m X [m-1:0] = min(A, B)
A[m–1:0] m-bit A<B A[m–1:0] 1
m m
Magnitude A=B S
B[m–1:0] Comparator 0 m
Mux
m A>B Y [m-1:0] = max(A, B)
1
Binary Decoders
Given a n-bit binary code, there are 2n possible code values
The decoder has an output for each possible code value
The n-to-2n decoder has n inputs and 2n outputs
Depending on the input code, only one output is set to
logic 1
The conversion of input to output is called decoding
n to 2n
than 2n outputs if some
Decoder
input codes are unused
Decoder
A decoder is a circuit that
creates an output based
on the binary states of a
given input
Do the opposite of
encoder
Decoder
Example: 3 to 8 Binary Decoder
Examples of Binary Decoders
Inputs Outputs
0 d0 a1 a0 d0 d1 d2 d3
4 Outputs
2 Inputs
a1 1 2-to-4 1 d1 0 0 1 0 0 0 Truth
a0 0 Decoder 2 d2 0 1 0 1 0 0
d3 1 0 0 0 1 0 Tables
3
1 1 0 0 0 1
Inputs Outputs
0 d0
a2 a1 a0 d0 d1 d2 d3 d4 d5 d6 d7
1 d1
0 0 0 1 0 0 0 0 0 0 0
2 d2 0 0 1 0 1 0 0 0 0 0 0
a2 2
8 Outputs
3 Inputs
3-to-8 3 d3 0 1 0 0 0 1 0 0 0 0 0
a1 1
Decoder 4 d4 0 1 1 0 0 0 1 0 0 0 0
a0 0
5 d5 1 0 0 0 0 0 0 1 0 0 0
6 d6 1 0 1 0 0 0 0 0 1 0 0
7 d7 1 1 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 1
Decoder Implementation
Inputs Outputs 𝑎2
a1 a0 d0 d1 d2 d3 3-to-8 Decoder
0 0 1 0 0 0 𝑎1
0 1 0 1 0 0 𝑎0 𝑑0 = 𝑎2′ 𝑎1′ 𝑎0′
1 0 0 0 1 0
1 1 0 0 0 1
𝑑1 = 𝑎2′ 𝑎1′ 𝑎0
2-to-4
Decoder 𝑑2 = 𝑎2′ 𝑎1 𝑎0′
𝑎1
𝑎0 𝑑0 = 𝑎1′ 𝑎0′ 𝑑3 = 𝑎2′ 𝑎1 𝑎0
𝑑1 = 𝑎1′ 𝑎0 𝑑4 = 𝑎2 𝑎1′ 𝑎0′
𝑑2 = 𝑎1 𝑎0′ 𝑑5 = 𝑎2 𝑎1′ 𝑎0
𝑑3 = 𝑎1 𝑎0 𝑑6 = 𝑎2 𝑎1 𝑎0′
𝑑7 = 𝑎2 𝑎1 𝑎0
Each decoder output is a minterm
Using Decoders to Implement Functions
A decoder generates all the minterms
A Boolean function can be expressed as a sum of minterms
Any function can be implemented using a decoder + OR gate
Note: the function must not be minimized
Example: Full Adder sum = ∑(1, 2, 4, 7), cout = ∑(3, 5, 6, 7)
Inputs Outputs
d0
a b c cout sum
d1
0 0 0 0 0
d2 sum
0 0 1 0 1 a 2
0 1 0 0 1 3-to-8 d3
b 1
0 1 1 1 0 d
1 0 0 0 1 c 0 Decoder 4 cout
d5
1 0 1 1 0 d6
1 1 0 1 0
1 1 1 1 1
d7
Using Decoders to Implement Functions
Good if many output functions of the same input variables
If number of minterms is large Wider OR gate is needed
Use NOR gate if number of maxterms is less than minterms
Example: f = ∑(2, 5, 6), g = ∏(3, 6) g' = ∑(3, 6), h = ∑(0, 5)
Inputs Outputs
a b c f g h d0
0 0 0 0 1 1 d1 f
d2
0 0 1 0 1 0 a 2
0 1 0 1 1 0 3-to-8 d3
b 1 g
0 1 1 0 0 0
c 0 Decoder d4
1 0 0 0 1 0 d5
1 0 1 1 1 1 d6 h
1 1 0 1 0 0 d7
1 1 1 0 1 0
2-to-4 Decoder with Enable Input
Truth Table
0 d0
a1 1
Inputs Outputs 2-to-4 1 d1
a0 0
d2
EN a1 a0 d0 d1 d2 d3 Decoder 2
EN 3 d3
0 X X 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0 𝑎1
1 1 0 0 0 1 0
𝑎0 𝑑0 = 𝐸𝑁 𝑎1′ 𝑎0′
1 1 1 0 0 0 1
𝑑1 = 𝐸𝑁 𝑎1′ 𝑎0
1-to-2 Decoder
0 1 1 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0
0 d4
1 Bottom
1 d5
1 0 1 0 0 0 0 0 1 0 0 0 2-to-4
Decoder
2 d6
1 1 0 0 0 0 0 0 0 1 0
EN 3 d7
1 1 1 0 0 0 0 0 0 0 1
Building Larger Decoders
a1 1 0 d0
2-to-4
1 d1
a0 0 Decoder
2 d2
A 4-to-16 0
EN 3 d3
decoder with
enable can be 1 2-to-4 0 d4
1 d5
built using five 2- 0 Decoder
2 d6
1
to-4 decoders a3 1 0
EN 3 d7
2-to-4 1
with enables a2 0 Decoder 2
1 0 d8
2-to-4
EN EN 3 1 d9
0 Decoder
2 d10
2
EN 3 d11
a
I3 BCD to b
I2 c
BCD to 7-Segment Decoder I1
7-Segment d
e
Called also a decoder, but not a binary decoder I0 Decoder f
g
Accepts as input a BCD decimal digit (0 to 9)
Generates output to the seven LED segments to display the BCD digit
Each segment can be turned on or off separately
BCD to 7-Segment Decoder
Specification: Truth Table
◦ Input: 4-bit BCD (I3, I2, I1, I0) BCD input 7-Segment Output
I3 I2 I1 I0 a b c d e f g
◦ Output: 7-bit (a, b, c, d, e, f, g) 0 0 0 0 1 1 1 1 1 1 0
◦ Display should be OFF for Non- 0 0 0 1 0 1 1 0 0 0 0
n Outputs
2n Inputs 2n to n
than 2n inputs if some
Encoder
input lines are unused
Encoder
Encoder converts information such as decimal number or
an alphabetical character into some binary coded form
Encoder is usually used for:
oData representation
oData security
oData compression
Example of an 8-to-3 Binary Encoder
8 inputs, 3 outputs, only one input is 1, all others are 0's
Encoder generates the output binary code for the active input
Output is not specified if more than one input is 1
Inputs Outputs
d0 0 d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 a2 a1 a0
d1 1
0 0 0 0 0 0 0 1 0 0 0
d2 2 0 0 0 0 0 0 1 0 0 0 1
8-to-3 2 a2 3 Outputs
8 Inputs
d3 3 0 0 0 0 0 1 0 0 0 1 0
Binary 1 a1
d4 4 0 0 0 0 1 0 0 0 0 1 1
0 a0
d5 5 Encoder 0 0 0 1 0 0 0 0 1 0 0
d6 6 0 0 1 0 0 0 0 0 1 0 1
d7 7 0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
8-to-3 Binary Encoder Implementation
Inputs Outputs d0 0
d1 1
d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 a2 a1 a0 d2 2 8-to-3 2 a2
0 0 0 0 0 0 0 1 0 0 0 d3 3
Binary 1 a1
0 0 0 0 0 0 1 0 0 0 1 d4 4
0 a0
0 0 0 0 0 1 0 0 0 1 0 d5 5 Encoder
d6 6
0 0 0 0 1 0 0 0 0 1 1
d7 7
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1 d4
d5
0 1 0 0 0 0 0 0 1 1 0 d6 a2
1 0 0 0 0 0 0 0 1 1 1 d7
d2
a2 = d4 + d5 + d6 + d7 8-to-3 binary d3
d6 a1
encoder d7
a1 = d2 + d3 + d6 + d7 implemented using
d1
three d3
a0
a0 = d1 + d3 + d5 + d7 4-input OR gates
d5
d7
Binary Encoder Limitations
Exactly one input must be 1 at a time (all others must be 0's)
If more than one input is 1 then the output will be incorrect
For example, if d3 = d6 = 1 a2 = d4 + d5 + d6 + d7
Then a2 a1 a0 = 111 (incorrect) a1 = d2 + d3 + d6 + d7
Two problems to resolve: a0 = d1 + d3 + d5 + d7
1. If two inputs are 1 at the same time, what should be the output?
2. If all inputs are 0's, what should be the output?
Output a2 a1 a0 = 000 if d0 = 1 or all inputs are 0's
How to resolve this ambiguity?
Priority Encoder
Eliminates the two problems of the binary encoder
Inputs are ranked from highest priority to lowest priority
If more than one input is active (logic 1) then priority is used
Output encodes the active input with higher priority
If all inputs are zeros then the V (Valid) output is zero
Indicates that all inputs are zeros
Inputs Outputs
d 3 d 2 d 1 d 0 a1 a0 V
d3 0 0 0 0 X X 0
3 = highest priority
1 a1 Condensed
d2 0 0 0 1 0 0 1
2 4-to-2 Priority Truth Table
0 a0 0 0 1 X 0 1 1
d1 1 Encoder All 16 cases
0 1 X X 1 0 1
d0 0 = lowest priority V are listed 1 X X X 1 1 1
Implementing a 4-to-2 Priority Encoder
𝑑1 𝑑0
K-Map of 𝑎1 𝑑1 𝑑0
K-Map of 𝑎0
Inputs Outputs
𝑑3 𝑑2 00 01 11 10 𝑑3 𝑑2 00 01 11 10
d 3 d 2 d 1 d 0 a1 a0 V
00 X 00 X 1 1
0 0 0 0 X X 0
0 0 0 1 0 0 1 01 1 1 1 1 01
0 0 1 X 0 1 1
11 1 1 1 1 11 1 1 1 1
0 1 X X 1 0 1
1 X X X 1 1 1 10 1 1 1 1 10 1 1 1 1
d3
a1
Output Expressions: d2
𝑎1 = 𝑑3 + 𝑑2 a0
𝑎0 = 𝑑3 + 𝑑1 𝑑2′ d1
𝑉 = 𝑑3 + 𝑑2 + 𝑑1 + 𝑑0 V
d0
Encoder - Example: 8-to-3 Binary Encoder