Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Lab 4: Comparators circuit using Logic Gates

1. Introduction

Digital comparators circuit is combinational logic circuits that could be used to verify whether
the values of 2 input (1-bit or multiple-bit) is greater than, less than, or equal to each other or not.
Equality comparator and Magnitude comparator are the two basic types of comparator which
commonly used.

The application of comparator are:

• Comparators are used in central processing units (CPUs) and microcontrollers (MCUs).
• They are also used in control applications in which the binary number representing
physical variables such as temperature, position, etc. are compared with a reference
value.
• Comparators are also used as process controllers and for servo motor control.
• Used in password verification and biometric application.

2. Objective

The objective of this laboratory is to provide the student with a basic understanding of the
functionality of comparator circuit by the following task:

• To build and simulate the Equality comparator circuit by logic gate


• To build and simulate the Magnitude comparator circuit by logic gate

• To build several types of comparator circuits such as one-bit, two bits, or 4 bits circuits.

3. Simulation

3.1. Equality Comparator

The equality comparator is the simplest form of a comparator circuit for determining whether
two numbers are equal.

1
Practice

a. Verify with a 2-bit Equality comparator circuit by implementing and simulating on Quartus
Prime software for input as in Figure 2 below.

Figure 1:The 2-bit Equality comparator

Figure 2:The 2-bits equality comparator circuit with waveform of 2-bits input

3.2. Magnitude Comparator

The magnitude comparator is a combinational circuit that compares two digital or binary
numbers to find out whether one binary number is equal, less than, or greater than the other binary
number. We logically design a circuit for which we will have two inputs, one for A and the other
for B, and have three output terminals, one for A>B condition, one for A=B condition, and one for
A<B condition.

Figure 3:The magnitude comparators which have two inputs and three output for each of three comparison results.

1-bit magnitude comparator


A comparator used to compare two bits is called a single-bit comparator. It consists of two inputs,
each for two single-bit numbers, and three outputs to generate less than, equal to, and greater than
between two binary numbers.

2
We got the following relationship between output and input through the following conditions:

For A>B: G=AB’

For A<B: L=A’B

For A=B: E=A’B’+AB

Practice

a. Use the truth table to verify the operation of the 1-bit magnitude comparator.
b. Implement and simulate a 1-bit magnitude comparator in the Quartus Prime.

2-bit magnitude comparator

It is used to compare two binary numbers with each of the two bits. The input data are represented
by A1A0 and B1B0 and three outputs are represented as G (for A greater than B), L (for A less
than B), E (for A equal to B).

We get the following logic formula:

G= A1B1’ + A0B1’B0’ + A1A0B0’

L= A1’B1 + A0’B1B0 + A1’A0’B0

E= (A0 Xnor B0) (A1 Xnor B1)

3
Practice

a. Use the truth table to verify the operation of the 2-bit magnitude comparator.
b. Implement and simulate a 2-bit magnitude comparator in the Quartus Prime.

4-bit magnitude comparator with cascading inputs

The following figure shows the 4-bit magnitude comparator with cascading input. This circuit can
be cascaded together for building a comparator with more than 4-bit data.

Practice:

a. Write the logic for each condition (A>B, A<B, A=B) from the figure above.
b. Build the 4-bit magnitude comparator and simulate it by Quartus Prime with inputs as in
Figure below.

You might also like