0% found this document useful (0 votes)
4 views

Comparator Tutorial

The document provides an overview of comparators, which are combinational logic circuits used to compare the magnitudes of two binary numbers. It details the types of comparators, including equality and magnitude comparators, and explains their functionality through truth tables and logic diagrams. Additionally, it discusses the design and implementation of 1-bit and 2-bit comparators, as well as algorithms for determining equality and inequality between binary numbers.

Uploaded by

mentalgear.ha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Comparator Tutorial

The document provides an overview of comparators, which are combinational logic circuits used to compare the magnitudes of two binary numbers. It details the types of comparators, including equality and magnitude comparators, and explains their functionality through truth tables and logic diagrams. Additionally, it discusses the design and implementation of 1-bit and 2-bit comparators, as well as algorithms for determining equality and inequality between binary numbers.

Uploaded by

mentalgear.ha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1

Comparator

1. Comparator
1. Equality or identity comparator
2. Magnitude comparator
3. A 4-bit magnitude comparator
4. Cascading comparator
5. Applications of comparators
2. Summary

Learning Objectives

After learning this module you will be able to

1. Understand the concept of Combinational Circuits


2. Study the classification of Combinational Circuits
3. Learn design and analysis procedure of Combinational Circuits
4. Get familiar with comparators and its applications

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
1. Comparator

Comparator is a combinational logic circuit that compares the magnitudes of two binary
quantities to determine which one has the greater magnitude. In other word, a comparator
determines the relationship of two binary quantities.
quantities An exclusive OR gate can be used as a
basic comparator.

Figure 1: Digital Comparator

Digital comparators are also called as binary or logic comparators. Comparator is a very
useful combinational circuit capable of comparing two numbers as input in binary form and
determines whether one number is greater than, less than or equal to other number. This logic
circuit is used for testing whether the binary number at one input is greater than or less than
or equal to another binary number.

There are two types of comparators:

1. Equality or Identity Comparator


2. Magnitude or inequality comparator.

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
3

Figure 2: Types of Binary comparators

1.1 Equality (or Identity) comparator

Equality comparator requires two input binary numbers A and B for comparison as shown in
fig. 3. There is only one output indicating whether the input numbers are equal or not.

Figure 3: Logic symbol of equality comparator

Output of the comparator is at logic ‘1’ if the two input words A and B match otherwise the
output remains at logic ‘0’. Out of the 2n combinations, there is only one input combination that
is correct and other combinations will result in inequality.
inequality

This comparator can be used for simple circuits like electronic lock and security systems where
binary password consisting of n bits compared with another preset code. Let us discuss the
implementation of simple 1-bit equality comparator.
comparator

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
4

1-bit Equality comparator

Figure 4: 1 bit Equality comparator (Active LOW)

Let us study 1-bit equality comparator using simple XOR circuit. The truth table of XOR
indicates the operation of Identity or Equality comparator. When both the inputs of the
comparator are equal then the output is active LOW indicating matching of the input code, other
wise output is at logic ‘1’ indicating the mismatch.
mismatch

Figure 5: 1 bit Equality comparator (Active HIGH)

Let us study ACTIVE HIGH 1-bit equality comparator using simple XNOR circuit as shown in
fig. 5. The truth table of XNOR indicates the operation of Identity or Equality comparator. If
two inputs are identical then the output of comparator is ‘1’ else provides ‘0’ indicating
mismatch in the input code.

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
5

2-bit Equality comparator Inputs Outputs

A1 A0 B1 BO A=B

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 0

0 1 0 0 0

0 1 0 1 1

0 1 1 0 0
Fig. 6: 2-bit Equality comparator
0 1 1 1 0

1 0 0 0 0
In two bit equality comparator as shown in fig.6,
fig two bit binary
1 0 0 1 0
numbers A and B represented as A1A0 and B11B0 are compared.
1 0 1 0 1
Here A1 and B1 are the most significant bits, and A0 and B0 are
1 0 1 1 0
the least significant bits of numbers A and B respectively.
respectively A1 is
1 1 0 0 0
compared with B1 and A0 is compared the B0.. If A1 is equal to
1 1 0 1 0
B1 and A0 is equal to B0 output of a two bit comparator will be
1 1 1 0 0
HIGH. If A1 is not equal to B1 or A0 is not equal to B0 output
1 1 1 1 1
will be LOW as shown in the table.

1.2 Magnitude comparator

Fig. 7: Magnitude comparator.

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
6

Magnitude comparator as the name suggest compares only the magnitude of the two binary
numbers and not the sign. It can also be used to indicate the equality of the input numbers. In
addition, the magnitude comparators has two additional outputs to indicate whether input A is
greater that input B and whether input A is less than input B as shown in fig.7.

1-bit magnitude comparator

Inputs Outputs
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

Figure 8: 1-bit magnitude comparator

In 1-bit magnitude Comparator, A, B are two 1 bit number and there are three outputs
corresponding to A>B, A=B and A<B respectively as shown in fig. 8 . The Boolean
expressions for 1-bit magnitude comparator are
C AB
DAB
E  AB
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
7

For implementation of this comparator, XNOR gate, AND gates and inverters are also used. It is
very easy to derive the Boolean expressions from the truth table by visual inspection.

2-bit magnitude comparator

A 2-bit comparator compares two binary numbers, each of two bits and produces their relation
such as one number is equal or greater than or less than the other. The figure below shows the
block diagram of a two-bit comparator which has four inputs and three outputs.

Inputs Outputs
A1 A0 B1 BO A>B A=B A<B
0 0 0 0 0 1 0
0 0 0 1 0 0 1
0 0 1 0 0 0 1
0 0 1 1 0 0 1
Figure 9: 2-bit magnitude comparator 0 1 0 0 1 0 0
0 1 0 1 0 1 0
The fig. 9 shows the block diagram of a two--
0 1 1 0 0 0 1
bit comparator which has four inputs and three
0 1 1 1 0 0 1
outputs.
1 0 0 0 1 0 0
The first number A is designated as A = A1A00 1 0 0 1 1 0 0
and the second number is designated as B = 1 0 1 0 0 1 0
B1B0. This comparator produces three outputs 1 0 1 1 0 0 1
as (A>B), (if A = B) and (A<B). 1 1 0 0 1 0 0
1 1 0 1 1 0 0
Let us prepare the K-map for each output so as
1 1 1 0 1 0 0
to implement the 2-bit magnitude comparator.
1 1 1 1 0 1 0

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
11

The K-map and Boolean expression for the outputs A>B, A=B and A>B of comparator are
shown in fig. 10.

B1’B0’ B1’B0 B1B0 B1B0’

A1’A0’ 1

A1’A0 1

A1A0 1

A1A0’ 1

Figure 10: Obtaining Boolean expression for 2-bit magnitude comparator

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
9

Figure 11: Logic diagram for 2-bit magnitude comparator

By using above obtained Boolean equation for each output, the logic diagram can be
implemented by using four NOT gates, seven AND gates, two OR gates and two Ex-NOR gates.
Figure 11 shows the logic diagram of a 2-bit comparator using basic logic gates. It is also
possible to construct this comparator by cascading of two 1-bit comparators.

6.3 A 4-bit magnitude comparator

Figure 12: Logic symbol of 4-bit


4 magnitude comparator

Magnitude comparator can be used to compare two four-bit words. The two 4-bit numbers are A
= A3 A2 A1 A0 and B= B3 B2 B1 B0 where A3 and B3 are the most significant bits. It
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
10

compares each of these bits in one number with bits in that of other number and produces one of
the following outputs as A = B, A < B and A>B.
A>B The output function table of 4-bit magnitude
comparator is shown in Figure 13.

INPUT OUTPUTS
A3 B3 A2 B2 A1 B1 A0 B0 A>B A=B A<B
A3 >B3 X X X 1 0 0

A3 <B3 X X X 0 0 1
A3 =B3 A2>B2 X X 1 0 0
A3 =B3 A2<B2 X X 0 0 1
A3 =B3 A2=B2 A1>B1 X 1 0 0
A3 =B3 A2=B2 A1<B1 X 0 0 1

A3 =B3 A2=B2 A1=B1 A0>B0 1 0 0


A3 =B3 A2=B2 A1=B1 A0<B0 0 0 1
A3 =B3 A2=B2 A1=B1 A0=B0 0 1 0

Figure 13: Function table of 4-bit magnitude comparator

If A3 = 1 and B3 = 0, then A is greater than B (A>B), Or If A3 and B3 are equal, and if A2 = 1


and B2 = 0, then A > B. Or If A3 and B3 are equal & A2 and B2 are equal, and if A1 = 1, and B1
= 0, then A>B. Or If A3 and B3 are equal, A2 and B2 are equal and A1 and B1 are equal, and if
A0 = 1 and B0 = 0, then A > B.

The circuit for comparing two n -bit numbers has 22n entries in the truth table and becomes too
cumbersome, even with n = 3. On the other hand, as one may suspect, a comparator circuit
possesses a certain amount of regularity.
Digital functions that possess an inherent well-defined
well regularity can usually be designed by
means of an algorithm—a procedure which specifies a finite set of steps

Electronic Science
Algorithm (equality)

The algorithm is a direct application of the procedure a person uses to compare the relative magnitudes of
two numbers. Consider two numbers, A and B , with four digits each.

Write the coefficients of the numbers in descending order of significance:


A = A3 A2 A1 A0
B = B3 B2 B1 B0

Each subscripted letter represents one of the digits in the number. The two numbers are equal if all pairs
of significant digits are equal: A3 = B3, A2 = B2, A11 = B1, and A0 = B0. When the numbers are binary,
the digits are either 1 or 0, and the equality of each pair of bits can be expressed logically with an
exclusive-NOR function as
xi = AiBi + Ai’Bi’ for i = 0, 1, 2, 3
where xi = 1 only if the pair of bits in position i are equal (i.e., if both are 1 or both are 0).

One bit Magnitude comparator

A=1, B=0 => A>B,


A=0, B=1 => A<B,
A=0, B=0 => A=B,
A=1, B=1 => A=B,

A<B

A=B

A>B

The equality of the two numbers A and B is displayed in a combinational circuit by an output
binary variable that we designate by the symbol (A = B) . This binary variable is equal to 1 if the
input numbers, A and B , are equal, and is equal to 0 otherwise.
For equality to exist, all xi variables must be equal to 1, a condition that dictates an AND
operation of all variables:
(A = B) = X3X2X1X0
The binary variable (A = B) is equal to 1 only if all pairs of digits of the two numbers are equal.
Algorithm (inequality)
To determine whether A is greater or less than B , we inspect the relative magnitudes of pairs of
significant digits, starting from the most significant position. If the two digits of a pair are equal,
we compare the next lower significant pair of digits.
digits The comparison continues until a pair of
unequal digits is reached. If the corresponding digit of A is 1 and that of B is 0, we conclude that
A > B. If the corresponding digit of A is 0 and that of B is 1, we have A < B. The sequential
comparison can be expressed logically by the two Boolean functions
A > B = A3B3’ + x3 A 2B2’ + x3x2A1B11’ + x3x2x1A0B0’
A < B = A3’B3 + x3A2’B2 + x3x2A1’B1 + x3x2x1A0’B0
The symbols (A > B) and(1A < B) are binary output variables that are equal to 1 when A > B
and A < B, respectively.
11
IC 7485

ICs are available in TTL as well as CMOS logic family ICs and some of these ICs include
IC 7485 (4-bit comparator), IC 4585 (4-bit comparator in CMOS family) and IC 74AS885
(8-bit comparator). Fig. 14 indicates an IC for 4-bit magnitude comparator. The 74LS85
compares two unsigned 4-bit binary numbers , the unsigned numbers are A3, A2, A1, A0
and B3, B2, B1, B0.

Figure 14: IC 7485- a 4 bit magnitude comparator.

1.4 Cascading comparators


Cascading inputs provide a means for expanding the comparison operation to more than four bits
by cascading two or more 4-bit comparators. When two comparators are to be cascaded, the
outputs of the lower-order comparator are connected to corresponding inputs of the higher-order
comparator. The comparator on the left is comparing lower 4 bits and right comparator compare
higher order nibble.

Figure 15: Cascading o0f Magnitude comparator

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
Function Table of 7485 4-Bit Comparator

Cascading Magnitude comparator 7485


12

1.5 Applications of comparators

Comparators are used in control applications in which the binary numbers representing physical
variables such as temperature, position, etc. are compared with a reference value. Then the
outputs from the comparator are used to drive the actuators so as to make the physical variables
closest to the set or reference value. In addition, comparators are also used in following
applications.

1. Arithmetic logic unit (ALU)

2. Compare two binary words in microprocessors, computers for interfacing the external
devices.

3. Analog to digital converters (ADC)

4. In Process Control Applications & for Servo-motor


Servo control

5. Password verification, biometric applications, for searching and surfing

Summary

Combinational circuits are the logic circuits in which the outputs at any instant of time depend on
the inputs present at that instant only. In Combinational circuit, for n input variables, there are 2n
possible combinations of binary input values. There are 3 types of combinational circuits: Data
processing, Data transfer and code converters.

The design of combinational circuits begins with problem definition and ends with a logic circuit or set of
Boolean expressions. In many applications, logic diagram is available but correlation between
input and output is not known. The analysis of combinational circuits is the reverse process of
design.

Comparator is a combinational logic circuit that compares the magnitudes of two binary
quantities to determine which one has the greater magnitude. An exclusiveOR gate can be used
as a basic comparator. There are two types of comparators:
comparators Equality or Identity Comparator and
Magnitude or inequality comparator.

Cascading inputs provide a means for expanding the comparison operation to more than four bits
by cascading two or more 4-bit comparators.

Digital Electronics
Electronic Science
9. Combinational circuits & Comparator

You might also like