Digital Electronics - Comparators



In digital electronics, a comparator is a combinational logic circuit that is used to compare the magnitudes of two binary numbers. Comparators are used in several different electronic circuits like analog to digital converters, voltage level detectors, zero-crossing detectors, etc.

The most basic example of a comparator is an XNOR gate which produces a high or logic 1 output only when both its inputs are equal.

In this chapter, we will learn about the basics, types, and applications of comparators in digital electronics. So, lets start with the basic definition of a comparator.

What is a Comparator?

A digital combinational circuit used to compare the magnitude of two binary numbers to determine the equality or non-equality is called a comparator.

Therefore, the main function of a comparator is to compare the values of input numbers and produce an output indicating whether the numbers are equal or specifies which of the numbers is greater.

Let us understand the working of a comparator with the help of an example.

Consider two 3-bit binary numbers A2A1A0 and B2B1B0. These two binary numbers are said to be equal if all their corresponding bits coincide. In other words, these two binary numbers are equal if A2 = B2, A1 = B1, and A0 = B0.

The block diagram of a typical comparator is shown in the following figure −

Comparators Block Diagram

Here, A and B are the input bits, and L, E, and G are the output lines, where L indicates which number is smaller, E indicates equality, and G indicates the greater number.

Types of Comparators

Depending on the number of bits, the following are some main types of comparators used in digital circuits −

  • 1-Bit Magnitude Comparator
  • 2-Bit Magnitude Comparator
  • 4-Bit Magnitude Comparator

Let us discuss each type of comparator in detail.

1-Bit Magnitude Comparator

A 1-bit magnitude comparator is a logic circuit which can compare two binary numbers of one bit each. It produces an output that indicates the relationship between the two input numbers.

In other words, a 1-bit magnitude comparator is one that compares two 1-bit binary numbers and generates an output showing whether one number is equal to or greater than or less than the other.

The block diagram of a 1-bit magnitude comparator is shown in the following figure −

1-Bit Magnitude Comparator

Here, A and B are the 1-bit input numbers, and L, E, and G are the output lines indicating less than or equal to or greater than relationship between A and B respectively.

Let us understand the working this type of comparator.

If A = 0 and B = 0 or if A = 1 and B = 1, then A = B. It indicates that the two binary numbers are equal. Therefore,

$$\mathrm{E \: = \: \overline{A} \: \cdot \: \overline{B} \: + \: A \: \cdot \: B \: = \: A \: \odot \: B}$$

If A = 0 and B = 1, then A < B. This indicates that the binary number A is less than the binary number B. Therefore,

$$\mathrm{L \: = \: \overline{A} \: B}$$

If A = 1 and B = 0, then A > B. It indicates that the binary number A is greater than the binary number B. Therefore,

$$\mathrm{G \: = \: A \: \overline{B}}$$

The 1-bit magnitude comparator compares the corresponding bits of the input numbers A and B. For this, it uses different types of logic gates.

The truth table of the 1-bit magnitude comparators is given below −

Inputs Outputs
A B L (A < B) E (A = B) G (A > B)
0 0 0 1 0
0 1 1 0 0
1 0 0 0 1
1 1 0 1 0

We can use this truth table to obtain the Boolean expression of the 1-bit magnitude comparator.

$$\mathrm{L \: = \: \overline{A} \: B}$$

$$\mathrm{E \: = \: \overline{A} \: \cdot \: \overline{B} \: + \: A \: \cdot \: B \: = \: A \: \odot \: B}$$

$$\mathrm{G \: = \: A \: \overline{B}}$$

The logic circuit diagram of the 1-bit magnitude comparator is shown in the following figure.

1-Bit Magnitude Comparator

It consists of two AND gates, two NOT gate, and an XNOR gate.

2-Bit Magnitude Comparator

A digital combinational circuit used to compare the magnitudes of two 2-bit binary numbers and determine the relationship between them is called a 2-bit magnitude comparator.

Hence, the 2-bit magnitude comparator compares the values represented by two 2-bit binary numbers and then generates an output that indicates whether one number is equal to or greater than or less than the other.

The block diagram of a typical 2-bit magnitude comparator is shown in the following figure −

2-Bit Magnitude Comparator

Here, the lines A0A1 and B0B1 represents two 2-bit binary number inputs and the lines L, E, and G represents the less than, equal to, and greater than output lines.

We can understand the operation of the 2-bit magnitude comparator with the help of its truth table given below −

Inputs Outputs
A1 A0 B1 B0 L (A < B) E (A = B) G (A > B)
0 0 0 0 0 1 0
0 0 0 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 1 0 0 0 0 1
0 1 0 1 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 0
1 0 0 0 0 0 1
1 0 0 1 0 0 1
1 0 1 0 0 1 0
1 0 1 1 1 0 0
1 1 0 0 0 0 1
1 1 0 1 0 0 1
1 1 1 0 0 0 1
1 1 1 1 0 1 0

Let us now derive the Boolean expression for the outputs L, E, and G.

Case 1: A = B

The comparator produces an output A = B which is E, if A0 = B0 and A1 = B1. Therefore, the Boolean expression for the output E will be,

$$\mathrm{E \: = \: (A_{0} \: \odot \: B_{0}) \: (A_{1} \: \odot \: B_{1})}$$

Case 2: A < B

The comparator produces an output A < B which is L, if

  • A1 = 0 and B1 = 1, OR
  • A1 = B1 and A0 = 0 and B0 = 1.

From these statements, we can write the Boolean expression for the output L as follows −

$$\mathrm{L \: = \: \overline{A_{1}} \: B_{1} \: + \: (A_{1} \: \odot \: B_{1}) \: \overline{A_{0}} \: B_{0}}$$

Case 3: A > B

The output of the comparator will be A > B i.e., G, if

  • A1 = 1 and B1 = 0, OR
  • A1 = B1 and A0 = 1 and B0 = 0.

From these statements, the Boolean expression for the output G will be,

$$\mathrm{G \: = \: A_{1} \: \overline{B_{1}} \: + \: (A_{1} \: \odot \: B_{1}) \: A_{0} \: \overline{B_{0}}}$$

The following figure shows the logic circuit diagram of the 2-bit magnitude comparator −

2-bit Magnitude Comparator

4-Bit Magnitude Comparator

The 4-bit magnitude comparator is used in more complex digital circuits like microprocessors, microcontrollers, and many more.

It is a type of comparator that can compare the values or magnitudes of two 4-bit binary numbers and produce an output indicating whether one number is equal to or less than or greater than the other.

The block diagram of the 4-bit magnitude comparator is shown in the following figure −

4-Bit Magnitude Comparator

Let us now understand the working of this 4-bit magnitude comparator. For that consider A = A3A2A1A0 is the first 4-bit binary number and B = B3B2B1B0 is the second 4-bit binary number.

The comparator will show the results as follows −

Case 1: A = B

The comparator will produce an output A = B which is E, if all the corresponding bits in the two numbers are equal i.e., A3 = B3 and A2 = B2 and A1 = B1 and A0 = B0.

In this case, the Boolean expression of the output will be,

$$\mathrm{E \: = \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: (A_{0} \: \odot \: B_{0})}$$

Case 2: A < B

The comparator will produce an output A < B which is L, if

  • A3 = 0 and B3 = 1, OR
  • A3 = B3 and if A2 = 0 and B2 = 1, OR
  • A3 = B3 and if A2 = B2 and if A1 = 0 and B1 = 1, OR
  • A3 = B3 and if A2 = B2 and if A1 = B1 and if A0 = 0 and B0 = 1.

From these statements, we can derive the Boolean expression for the output L, which is given below.

$$\mathrm{L \: = \: \overline{A_{3}} \: B_{3} \: + \: (A_{3} \: \odot \: B_{3}) \: \overline{A_{2}} \: B_{2} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: \overline{A_{1}} \: B_{1} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: \overline{A_{0}} \: B_{0}}$$

Case 3: A > B

The comparator produces an output A > B which is G, if

  • A3 = 1 and B3 = 0, OR
  • A3 = B3 and if A2 = 1 and B2 = 0, OR
  • A3 = B3 and if A2 = B2 and if A1 = 1 and B1 = 0, OR
  • A3 = B3 and if A2 = B2 and if A1 = B1 and if A0 = 1 and B0 = 0.

Hence, from these statements, we can write the Boolean expression for the output G which is,

$$\mathrm{G \: = \: A_{3} \: \overline{B_{3}} \: + \: (A_{3} \: \odot \: B_{3}) \: A_{2} \: \overline{B_{2}} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: A_{1} \: \overline{B_{1}} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: A_{0} \: \overline{B_{0}}}$$

The logic circuit implementation of the 4-bit magnitude comparator is shown in the following figure −

4-bit Magnitude Comparator

Comparator IC

A comparator IC is an integrated circuit which is designed to compare two binary numbers and produce an output based on the comparison results.

A commonly used comparator IC is IC 7485 which is a 4-bit magnitude comparator IC. It is widely in digital electronic applications to compare two 4-bit binary numbers.

The IC 7485 compares corresponding bits of the two input numbers and determines whether one number is equal to or greater than or less than the other. The pin diagram of the IC 7485 is depicted in the following figure.

Comparator IC

This IC is widely used in various digital circuits such as microprocessors, microcontrollers, control systems, and arithmetic logic units.

Applications of Comparators

The comparators are fundamental components in various digital circuits. They provide capabilities to compare voltage levels and make decisions.

Some of the key applications of comparators in the field of digital electronics are listed below −

  • Comparators are used to detect changes in voltage levels in electronic circuits.
  • Comparators are also used temperature monitoring systems.
  • Comparators are used as zero-crossing detector in various power circuits like phase control circuits, motor and power control circuits, etc.
  • Comparators are key components in analog to digital converters (ADCs).
  • In signal conditioning circuits, the comparators are used for amplification and filtering of signals before processing.

Conclusion

In conclusion, a comparator is a combinational logic circuit used in various digital electronic applications to compare two similar quantities like two 2-bit binary numbers or two voltage levels, etc.

Comparators help us to make decisions based on a comparison of two input values. They are widely used in several different electronic devices and systems such as arithmetic logic units, microprocessor-based systems, control systems, automation systems, and telecommunication systems.

Depending on the number of input bits required for a particular application, we can design a 1-bit, 2-bit, or 4-bit comparator. Also, comparators are available in the form of integrated circuit. The most commonly used IC comparator is IC 7485 which is a 4-bit magnitude comparator.

Advertisements