You are on page 1of 20

Comparators

Combinational Design
Comparators
• Equality and Magnitude Comparators
• TTL Comparators
• Comparator Networks
• Cascading 1-bit Comparators
Equality Comparator
XNOR
X Y Z
X 0 0 1
Z 0 1 0
Y 1 0 0
1 1 1
Z = !(X $ Y)
4-Bit Equality Comparator
A0 C0
B0
A1 C1
B1 A_EQ_B
A2
B2 C2
A3
B3 C3

FIELD A = [A0..3];
FIELD B = [B0..3];
FIELD C = [C0..3];
4-bit Equality Detector

A[3..0] Equality
Detector A_EQ_B
B[3..0]
4-bit Magnitude Comparator

A[3..0] A_LT_B
Magnitude
Detector A_EQ_B
B[3..0]
A_GT_B
Magnitude Comparator
A0 C0
B0
A1 C1
B1 A_EQ_B
A2
B2 C2
A3
B3 C3

How can we find A_GT_B?

How many rows would a truth table have?

28 = 256!
Magnitude Comparator
A0 C0
B0
A1 C1 Find A_GT_B
B1 A_EQ_B
A2
B2 C2
A3
B3 C3
Because A3 > B3
If A = 1001 and i.e. A3 & !B3 = 1
B = 0111 Therefore, one term in the
is A > B? logic equation for A_GT_B is
Why? A3 & !B3
Magnitude Comparator
A0 C0
B0 A_GT_B = A3 & !B3
A1 C1
B1 A_EQ_B + …..
A2
B2 C2
A3
B3 C3 Because A3 = B3 and
A2 > B2
If A = 1101 and i.e. C3 = 1 and
B = 1011 A2 & !B2 = 1
is A > B? Therefore, the next term in the
Why? logic equation for A_GT_B is
C3 & A2 & !B2
Magnitude Comparator
A0 C0
B0 A_GT_B = A3 & !B3
A1 C1
B1 A_EQ_B + C3 & A2 & !B2
A2 + …..
B2 C2
A3 Because A3 = B3 and
B3 C3 A2 = B2 and
A1 > B1
If A = 1010 and i.e. C3 = 1 and C2 = 1 and
B = 1001 A1 & !B1 = 1
is A > B?
Therefore, the next term in the
Why?
logic equation for A_GT_B is
C3 & C2 & A1 & !B1
Magnitude Comparator
A_GT_B = A3 & !B3
A0 C0
B0 + C3 & A2 & !B2
A1 C1 + C3 & C2 & A1 & !B1
B1 A_EQ_B
A2 + …..
B2 C2
A3
Because A3 = B3 and
B3 C3 A2 = B2 and
If A = 1011 and A1 = B1 and
B = 1010 A0 > B0
is A > B? i.e. C3 = 1 and C2 = 1 and
Why? C1 = 1 and A0 & !B0 = 1
Therefore, the last term in the
logic equation for A_GT_B is
C3 & C2 & C1 & A0 & !B0
Magnitude Comparator
A0 C0
B0
A1 C1
B1 A_EQ_B
A2
B2 C2
A3
B3 C3
A_GT_B = A3 & !B3
+ C3 & A2 & !B2
+ C3 & C2 & A1 & !B1
+ C3 & C2 & C1 & A0 & !B0
Magnitude Comparator
A0 C0
B0
A1 C1 Find A_LT_B
B1 A_EQ_B
A2
B2 C2
A3
B3 C3

A_LT_B = !A3 & B3


+ C3 & !A2 & B2
+ C3 & C2 & !A1 & B1
+ C3 & C2 & C1 & !A0 & B0
Comparators
• Equality and Magnitude Comparators
• TTL Comparators
• Comparator Networks
• Cascading 1-bit Comparators
TTL Comparators
1 P>Q Vcc 20
1 B3 Vcc 16 2 P0 P=Q 19
2 A<Bin A3 15 3 Q0 Q7 18
3 A=Bin B2 14 4 P1 P7 17
4 A>Bin A2 13 5 Q1 Q6 16
5 A1 12 6 15
A>Bout P2 P6
6 A=Bout B1 11 7 Q2 Q5 14
7 A<Bout A0 10 8 P3 P5 13
8 GND B0 9 9 Q3 Q4 12
10 GND P4 11
74LS85
74LS682
Cascading two 74LS85s
A3 A2 A1 A0 A7 A6 A5 A4
10 10
P0 P0
12 12
P1 P1
13 13
P2 P2
15 7 15 7
2
P3 P<Q
2
P3 P<Q A<B
< <
3 6 3 6
+5V 4
= P=Q
4
= P=Q A=B
> >
9 5 9 5
11
Q0 P>Q
11
Q0 P>Q A>B
Q1 Q1
14 14
Q2 Q2
1 1
Q3 Q3

B3 B2 B1 B0 B7 B6 B5 B4
Comparators
• Equality and Magnitude Comparators
• TTL Comparators
• Comparator Networks
• Cascading 1-bit Comparators
1-Bit Magnitude Comparator

x y

Gout 1 - bit Gin


Eout comparator
Lout Lin

The variable Eout is 1 if A = B and Gin = 0 and Lin = 0.


The variable Gout is 1 if A > B or if A = B and Gin = 1.
The variable Lout is 1 if A < B or if A = B and Lin = 1.
4-Bit Magnitude Comparator
x 3 y3 x2 y2 x1 y1 x0 y0

G 4 G G 2 G G
3 1 0
gt G in=0
eq 1-bit comp 1-bit comp 1-bit comp 1-bit comp
lt L in=0
L4 L3 L2 L1 L0

X Y
1101 0110 gt = 1
1110 1011
1011 1011 eq = 1
0101 0111
lt = 1
1010 1011
Tree comparator network

You might also like