Uploaded by Arin Sen

Digital Comparator

advertisement
Digital Comparator/Magnitude comparator:
The basic function of a comparator is to compare the magnitudes of two numbers and to indicate
one of its three possible outputs (less than, greater than or equal to). In its simplest form, a
magnitude comparator compares two numbers and indicates whether the two numbers are equal
or not.
We know that an X-OR gate acts like an equality detector. It produces a LOW(0) output if both
its inputs are equal, otherwise it produces a HIGH(1) output (when the inputs are unequal). So an
X-OR gate can be treated as 1-bit comparator.
To compare 2 or more bits, we need additional circuit with X-OR gate. For example, to compare
two 2-bit numbers A and B (A=A1A0 and B=B1B0 where A1, B1 are the MSB and A0, B0 are the
LSB of the two numbers), we need two X-OR gates, two NOT gates and one AND gate. If the
output of the AND gate is 1 (HIGH), then the two numbers(A and B) are equal, otherwise they
are unequal. The circuit can be slightly modified by combining the X-OR and NOT gate into an
X-NOR gate as shown below.
From the above discussion, we can conclude that by using more X-NOR gates, we can design a
comparator for comparing any number of bits.
Study Materials for Students

Design procedure of 1-bit comparator:
Truth table showing all possible output conditions for the two 1-bit numbers
A B A>B A=B A<B
0 0
0
1
0
0 1
0
0
1
1 0
1
0
0
1 1
0
1
0
From the above truth table, we can evaluate expressions for different outputs.
For A>B:
From the truth table, we can write the logic expression for A>B as 𝐺 = 𝐴𝐵̅.
For A=B:
From the truth table, we see that A=B column is actually the output of X-NOR gate. Hence, it
can be written as 𝐸 = 𝐴𝐵 + 𝐴̅𝐵̅ .
For A<B:
From the truth table, we can write the logic expression for A<B as 𝐿 = 𝐴̅𝐵.
Therefore, complete circuit diagram of 1-bit comparator looks like:
Design of 2-bit comparator:
Let us compare two 2-bit numbers A (A1A0) and B (B1B0).
Logic expression for outputs:
For A=B: A will be equal to B if A1 = B1AND A0 = B0.i.e. if both MSBs and LSBs are same.
Hence E = Y1Y0 where Y1=𝐴1 𝐵1 + ̅̅̅
𝐴1 ̅̅̅
𝐵1 and Y0= 𝐴0 𝐵0 + ̅̅̅
𝐴0 ̅̅̅
𝐵0
Hence, E = 1
if Y1 = 1 i.e. A1 = B1
and Y0 = 1 i.e. A0 = B0.
For A>B: A will be greater than B if A1>B1 OR A1=B1 AND A0>B0.( i.e. MSB of A is greater
than B OR MSBs are equal AND LSB of A is greater than B).
Hence, G = 𝐴1 ̅̅̅
𝐵1 + 𝑌1 𝐴0 ̅̅̅
𝐵0
For A<B: A will be less than B if A1<B1 or A1=B1 AND A0<B0.(i.e. MSB of B is greater than
A OR MSBs are equal AND LSB of B is greater than A). Hence, L = ̅̅̅
𝐴1 𝐵1 + 𝑌1 ̅̅̅
𝐴0 𝐵0.
Hence, the complete circuit diagram of 2-bit comparator looks like:
Design of 3-bit comparator:
Let us compare two 3-bit numbers A (A2A1A0) and B (B2B1B0).
Logic expression for outputs:
For A=B:
A will be equal to B if A2 = B2 AND A1 = B1AND A0 = B0.(i.e. if all the corresponding bits of
the two numbers are equal).
Hence E = Y2Y1Y0 where Y2=𝐴2 𝐵2 + ̅̅̅
𝐴2 ̅̅̅
𝐵2 , Y1=𝐴1 𝐵1 + ̅̅̅
𝐴1 ̅̅̅
𝐵1 and Y0=𝐴0 𝐵0 + ̅̅̅
𝐴0 ̅̅̅
𝐵0
Hence, E = 1
if Y2 = 1 i.e. A2 = B2
Y1 = 1 i.e. A1 = B1
and Y0 = 1 i.e. A0 = B0.
For A>B:
A will be greater than B ifA2>B2 ,ORA2 = B2AND A1>B1OR A1 = B1AND A0>B0.
Hence, G =𝐴2 ̅̅̅
𝐵2 + 𝑌2 𝐴1 ̅̅̅
𝐵1 + 𝑌1 𝐴0 ̅̅̅
𝐵0.
For A<B:
A will be less than B ifA2<B2 OR A2 = B2AND A1<B1OR A1 = B1AND A0<B0.
̅̅̅2 𝐵2 + 𝑌2 ̅̅̅
Hence, L =𝐴
𝐴1 𝐵1 + 𝑌1 ̅̅̅
𝐴0 𝐵0.
Hence, the complete circuit diagram of 3-bit comparator looks like:
Download