Comparator & Decoders: by Dr. Nermeen Talaat
Comparator & Decoders: by Dr. Nermeen Talaat
By
Dr. Nermeen Talaat
Lecture 11
1
Comparator
The basic function of a comparator is to compare the
magnitudes of two binary quantities to determine the
relationship of those quantities. In its simplest form.
A comparator circuit determines whether two numbers
are equal.
2
COMPARATORS
Equality:
As you learned in before the exclusive-OR gate can be used as a
basic comparator because its output is a 1 if the two input bits are
not equal and a 0 if the input bits are equal.
Figure shows the exclusive-OR gate as 2- bit comparator.
As shown in Figure :
If the two numbers are equal, their corresponding bits are the same,
and the output of each exclusive-OR gate is a 0.
If the corresponding sets of bits are not equal. a 1 occurs on that
exclusive-OR gate output.
COMPARATORS
LSB
MSB
A A1A0
B B1B0
The output is 1 when A0 = B0 AND A1 = B1
COMPARATORS
Example 1:
Apply each of the following sets of binary numbers to the comparator inputs in
Figure 3, and determine the output by following the logic levels through the circuit.
(a) 10 and 10 (b) 11 and 10
Figure 3
COMPARATORS
Solution
Example 1, illustrates this operation for two specific cases. The exclusive-OR gate and
inverter are replaced by an exclusive-NOR symbol.
COMPARATORS
4-Bit Comparator
The 7485 is a standard comparator package with the
following attributes:
One of three outputs will be HIGH:
A equal to B (A = B)
decoder encoder
code entity entity code
select select
Decoder background
Given a n-bit binary number there are 2n things it can
represent or lines that can be activated
A decoder detects the presence of a specified combination of
bits (code) on its inputs and indicates the presence of that
code by a specified output level.
In its general form,, a decoder has n input lines to handle n
bits and forms one to 2n output lines to indicate the presence
of one or more n-bits combinations..
n 2n decoder n inputs,, 2n outputs
For each input, one and only one output will be active..
10
1-to-2-line decoders
Circuit has n inputs and m outputs and m = 2n
Start with n=1 and m=2
This a 1-to-2 Line decoder – exactly one of
the output lines will be active.
11
n-to-m-line decoders
A decoder when n=2 and m=4
A 2-to-4 line decoder
Note that only one output is ever active
F0 = X'.Y'
X Y F0 F1 F2 F3 F1 = X'.Y
0 0 1 0 0 0
0 1 0 1 0 0 F2 = X.Y'
1 0 0 0 1 0
1 1 0 0 0 1 F3 = X.Y
X Y
12
Can be seen to create structure
For the 2-to-4 line 2x4
F0 Bulb 0
2-bit X Dec F Bulb 1
1
code Y
F2 Bulb 2
F3 Bulb 3
Contains 2 (2-to-1)
line decoders and
the additional logic.
13
Higher levels of structure
A 3-to-8 line decoder
F1 = x'.y'.z
x y z F0 F1 F2 F3 F4 F5 F6 F7
0 0 0 1 0 0 0 0 0 0 0 F2 = x'.y.z'
0 0 1 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 0 0 F3 = x'.y.z
0 1 1 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0 F4 = x.y'.z'
1 0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 1 0 F5 = x.y'.z
1 1 1 0 0 0 0 0 0 0 1
F6 = x.y.z'
F7 = x.y.z
Application? Binary-to-octal
conversion. x y z
15
In General Decoder
In general, for an n-bit code, a decoder could select up to
2n lines:
n-bit n to 2n up to 2n
code : decoder : output lines
16
Decoders: Implementing Functions
17
Decoders: Implementing Functions
x y z C S
Example: Full adder 0 0 0 0 0
0 0 1 0 1
S(x, y, z) = S m(1,2,4,7) 0 1 0 0 1
0 1 1 1 0
C(x, y, z) = S m(3,5,6,7) 1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
3x8 0
Dec 1 S
2
x S2 3
y S1 4
5 C
z S0 6 18
7
Decoders: Implementing Functions
3x8 0 1
x y z C S
Dec 0 0 0 0 0
1 0 S 0 0 0 1 0 1
2 0
0 x S2 0 1 0 0 1
3 0 0 1 1 1 0
0 y S1 4 0 1 0 0 0 1
5 0 C 0 1 0 1 1 0
0 z S0 6 0 1 1 0 1 0
7 0 1 1 1 1 1
19
Decoders: Implementing Functions
3x8 0 0
x y z C S
Dec 0 0 0 0 0
1 1 S 1 0 0 1 0 1
2 0
0 x S2 0 1 0 0 1
3 0 0 1 1 1 0
0 y S1 4 0 1 0 0 0 1
5 0 C 0 1 0 1 1 0
1 z S0 6 0 1 1 0 1 0
7 0 1 1 1 1 1
20
Decoders: Implementing Functions
3x8 0 0
x y z C S
Dec 0 0 0 0 0
1 0 S 1 0 0 1 0 1
2 0
1 x S2 0 1 0 0 1
3 0 0 1 1 1 0
1 y S1 4 0 1 0 0 0 1
5 0 C 1 1 0 1 1 0
1 z S0 6 0 1 1 0 1 0
7 1 1 1 1 1 1
BRAVO!!!
21
Decoders with Enable
E X Y F0 F1 F2 F3 F1 = EX'Y
1 0 0 1 0 0 0
1 0 1 0 1 0 0 F2 = EXY'
1 1 0 0 0 1 0
1 1 1 0 0 0 1
0 X X 0 0 0 0 F3 = EXY
Circuit:
22
X Y E
Decoders with Enable
E X Y F0 F1 F2 F3 E' X Y F0 F1 F2 F3
1 0 0 1 0 0 0 0 0 0 1 0 0 0
1 0 1 0 1 0 0 0 0 1 0 1 0 0
1 1 0 0 0 1 0 0 1 0 0 0 1 0
1 1 1 0 0 0 1 0 1 1 0 0 0 1
0 X X 0 0 0 0 1 X X 0 0 0 0
23
Decoder with 1-enable Decoder with 0-enable
Larger Decoders
Larger decoders can be 3x8
Dec 0 F0 = w'x'y'
w S2 1 F1 = w'x'y
constructed from x S1 : :
smaller ones. y S0 : :
7 F7 = wxy
follows:
2x4
Dec 0 F4 = wx'y'
S1 1 F5 = wx'y
S0 2 F6 = wxy'
E 3 F7 = wxy
24
Larger Decoders
3x8
Dec 0 F0 = w'x'y'
w S2 1 F1 = w'x'y
2x4
0 w
Dec 0 1 F0 = w'x'y' x S1 : :
0 x S1 1
0 F1 = w'x'y y S0 : :
S0
0 7 F7 = wxy
0 y 2
0
F2 = w'xy'
E 3 F3 = w'xy
1 = enabled
2x4 0
Dec 0 F4 = wx'y'
S1 1
0 F5 = wx'y
S0 2
0 F6 = wxy'
0
E 3 F7 = wxy
0 = disabled
25
Larger Decoders
3x8
Dec 0 F0 = w'x'y'
w S2 1 F1 = w'x'y
2x4 0 : :
0 w 0 F0 = w'x'y' x S1
Dec 1 : :
0 x S1 1 F1 = w'x'y y S0
S0
0 7 F7 = wxy
1 y 2
0
F2 = w'xy'
E 3 F3 = w'xy
1 = enabled
2x4 0
Dec 0 F4 = wx'y'
S1 1
0 F5 = wx'y
S0 2
0 F6 = wxy'
0
E 3 F7 = wxy
0 = disabled
26
Larger Decoders
3x8
Dec 0 F0 = w'x'y'
w S2 1 F1 = w'x'y
2x4 0 F = w'x'y' x S1 : :
1 w 0 0
1 x S1
Dec
1
0 = disabled
0
F = w'x'y y S0 : :
S0
0 F1 = w'xy' 7 F7 = wxy
0 y 2
0 2
E 3 F3 = w'xy
2x4 0 F = wx'y'
Dec 0 4
S1 1
0
1 = enabled
F = wx'y
S0 2
1 F5 = wxy'
6
0
E 3 F7 = wxy
BRAVO!!!
27
Larger Decoders
Construct a 4x16 4x16
Dec 0 F0
w S3
decoder from two x S2
1 F1
3x8 decoders with : :
y S1
: :
1-enable. z S0 15 F15
3x8
w Dec 0 F0
x S2
1 F1
y S1 : :
z S0 7 F7
E
3x8
Dec 0 F8
S2
1 F9
S1 : :
S0 7 F15
E 28
Larger Decoders
29
Decoders: Implementing Functions (2)
Example: Implement the following logic function using
decoders and logic gates
f(Q,X,P) = m(0,1,4,6,7) = M(2,3,5)
We may implement the function in several ways:
Use a decoder (with active-high outputs) with an OR gate:
f(Q,X,P) = m0 + m1 + m4 + m6 + m7
Use a decoder (with active-high outputs) with a NOR gate:
f(Q,X,P) = M(2,3,5) = M2.M3.M5
30
Decoders: Implementing Functions (2)
0 f(Q,X,P) = m(0,1,4,6,7)
3x8 1
Dec 2
Q A 3 f(Q,X,P)
B 4
X
5
P C 6
7
0
3x8 1
Dec 2 f(Q,X,P)
Q A 3
B 4
X
5
P C 6
7
31
(d) Active-low decoder with AND gate.