National University of Computer and Emerging Sciences: EL227-Digital Logic Design Lab-08

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

FAST

‫الذی علم بالقلم۔ علم االنسان ما لم‬


‫يعلم۔‬
National University of Computer and Emerging Sciences
DEPARMENT OF COMPUTER SCIENCE

EL227-Digital Logic Design


Lab-08
Engr. Khuram Shahzad, FAST NUCES Peshawar
EL227-DIGITAL LOGIC DESIGN
LAB-08
(ENCODER & DECODER)

Engr. Khuram Shahzad


(Instructor)

Engr. Khuram Shahzad, FAST NUCES Peshawar 06/12/2021 2


LAB-08 CONTENTS
 Magnitude Comparator
 Design and implement the circuitry for 1-bit magnitude comparator.
 Design and implement the circuitry for 2-bit magnitude comparator.
 Design and implement the circuitry for 4-bit magnitude comparator
1. Truth Table
2. K-Map
3. Equation
4. Circuit Diagram
5. Implement
 Code Converters
 Design and implement the circuitry for a BCD-to-Excess 3 Code Converter.

Engr. Khuram Shahzad, FAST NUCES Peshawar 3


Digital Comparator
• It is a combinational(circuit without memory) logic circuit.
• Digital Comparator is used to compare the value of two binary digits.
• There are two types of digital comparator
(i) Identity Comparator
(ii) Magnitude Comparator.
• IDENTITY COMPARATOR:
• This comparator has only one output terminal for when A=B, either A=B=1 (High) or
A=B=0 (Low)
• MAGNITUDE COMPARATOR:
• This Comparator has three output terminals namely A>B, A=B, A<B. Depending on
the result of comparison, one of these output will be high (1)
• Block Diagram of Magnitude Comparator is shown below in Fig. 1
Engr. Khuram Shahzad, FAST NUCES Peshawar 4
Magnitude Comparator

Engr. Khuram Shahzad, FAST NUCES Peshawar 5


1-Bit Magnitude Comparator
• This magnitude comparator has two inputs A and B and three outputs:
• A<B, A=B and A>B.
• This magnitude comparator compares the two numbers of single bits.
• Truth Table of 1-Bit Comparator
INPUTS OUTPUTS
A B Y1 (A<B) Y2 (A=B) Y3 (A>B)
0 0 0 1 0
0 1 1 0 0
1 0 0 0 1
1 1 0 1 0

Engr. Khuram Shahzad, FAST NUCES Peshawar 6


1-Bit Magnitude Comparator

Inputs Outputs

A B Y1 (A<B) Y2 (A=B) Y3 (A>B)


0 0 0 1 0
0 1 1 0 0
1 0 0 0 1
1 1 0 1 0

Engr. Khuram Shahzad, FAST NUCES Peshawar 7


1-Bit Magnitude Comparator
CIRCUIT DIAGRAM OF ONE BIT COMPARATOR
A
Y1  A  B

B AB
AB
Y2  A B 
AB
AB AB
Y3  A B
AB
Y1  AB
Y2  AB  AB
Y3  AB
Engr. Khuram Shahzad, FAST NUCES Peshawar 8
1-Bit Magnitude Comparator

Engr. Khuram Shahzad, FAST NUCES Peshawar 9


2-Bit Magnitude Comparator
• A comparator which is used to compare two binary numbers each of two
bits is called a 2-bit magnitude comparator.
• Fig. 2 shows the block diagram of 2-Bit magnitude comparator.
• It has four inputs and three outputs.
• Inputs are A0 ,A1,B0 and B1 and Outputs are Y1, Y2 and Y3

A0 Y1
A

A 2-Bit Comparator Y2
B01
B
B1 Y3

Input Output

Engr. Khuram Shahzad, FAST NUCES Peshawar 10


2-Bit Magnitude Comparator

Engr. Khuram Shahzad, FAST NUCES Peshawar 11


2-Bit Magnitude Comparator
INPUT OUTPUT
TRUTH TABLE
A1 A0 B1 B0 Y1=A<B Y2=(A=B) Y3=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
Engr. Khuram Shahzad, FAST NUCES Peshawar 12
K-MAP FOR
A<B: K-Map for A=B:
BB
B 1B 0 A1A 0 1 0
A1A 0 00 01 11 10 00 01 11
00 10
0 1 1 1 00 1 0 0 0

01 0 0 1 1 01 0 1 0 0

11 0 0 0 0 11 0 0 1 0

10 0 0 1 0 10 0 0 0 1

For A<B
Y1  A1 A 0 B 0  A1 B1  A 0 B1
B0 For A=B
Y2  A1 A0 B1 B0  A1 A0 B1 B0  A1A0B1B0  A1 A0 B1 B0
Engr. Khuram Shahzad, FAST NUCES Peshawar 13
K-MAP FOR A>B
B 1B 0
A1A0 10
00 01 11

00 0 0 0 0

01 1 0 0 0

11 1 1 0 1

10 1 1 0 0

Y3  A 0 B1 B0  A1 B1  A1A0 B0

Engr. Khuram Shahzad, FAST NUCES Peshawar 14


FOR A=B FROM K-MAP

Y2  A1 A 0 B1 B0  A1 A 0 B1 B0  A1A0B1B0  A1 A 0 B1 B0
Y2  A 0 B0 (A1 B1  A1B1 )  A 0 B0 (A1 B1  A1B1 )
Y2  (A1 B1  A1B1 ) (A 0 B0  A 0 B0 )
Y2  (A1  B1 ) (A 0  B0 )

Engr. Khuram Shahzad, FAST NUCES Peshawar 15


LOGIC DIAGRAM OF 2-BIT COMPARATOR:

A1 A0 B1 B0

A1 A 0 B 0
A1 B1 A< B
A 0 B1 B0

A1  B1
A=B
A 0  B0

A 0 B1 B 0

A1 A 0 B 0 A>
B
A 1 B1

Engr. Khuram Shahzad, FAST NUCES Peshawar 16


How to design a 4–bit comparator?
The truth table for a 4-bit comparator would have 4^4 = 256 rows. So we will do things a bit
differently here. We will compare each bit of the two 4-bit numbers, and based on that
comparison and the weight of their positions, we will draft a truth table.

A3B3 A2B2 A1B1 A0B0 A>B A<B A=B


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

Engr. Khuram Shahzad, FAST NUCES Peshawar 17


4 –BIT COMPARATOR
• In a 4-bit comparator the condition of A>B can be possible in the following four cases:

If A3 = 1 and B3 = 0
If A3 = B3 and A2 = 1 and B2 = 0
If A3 = B3, A2 = B2 and A1 = 1 and B1 = 0
If A3 = B3, A2 = B2, A1 = B1 and A0 = 1 and B0 = 0

• Similarly the condition for A<B can be possible in the following four cases:
If A3 = 0 and B3 = 1
If A3 = B3 and A2 = 0 and B2 = 1
If A3 = B3, A2 = B2 and A1 = 0 and B1 = 1
If A3 = B3, A2 = B2, A1 = B1 and A0 = 0 and B0 = 1

• The condition of A=B is possible only when all the individual bits of one number exactly coincide with
corresponding bits of another number. 

A=B: (A3 Ex-Nor B3) (A2 Ex-Nor 82) (Al Ex-Nor BI) (AO Ex-Nor BO) 

Engr. Khuram Shahzad, FAST NUCES Peshawar 18


CIRCUIT DIAGRAM

Engr. Khuram Shahzad, FAST NUCES Peshawar 19


Applications of Comparators

• These are used in the address decoding circuitry in computers and


microprocessor based devices to select a specific input/output device for the
storage of data.
• These 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.
• Process controllers
• Servo-motor control
• Used in password verification and biometric applications.

Engr. Khuram Shahzad, FAST NUCES Peshawar 20


CODE CONVERTERS

 The Code converter is used to convert one type of binary code to another.

 There are different types of binary codes like BCD code, gray code, excess-3 code, etc. Different codes are used for
different types of digital applications.
 To get the required code from any one type of code, the simple code conversion process is done with the help of
combinational circuits.
 A code converter circuit will convert coded information in one form to a different coding form.

Engr. Khuram Shahzad, FAST NUCES Peshawar 21


BCD,EXCESS-3 CODE

Engr. Khuram Shahzad, FAST NUCES Peshawar 22


BCD TO EXCESS 3 CONVERTER

Engr. Khuram Shahzad, FAST NUCES Peshawar 23


BCD TO EXCESS 3 CONVERTER

Engr. Khuram Shahzad, FAST NUCES Peshawar 24


BCD TO EXCESS 3 CONVERTER
Boolean Expression
w=A+BC+BD
x=B' C+B' D+BC' D'
y=CD+C'D'
z=D‘

Note: (A+B)’ = A’.B’ and (A.B)’ = A’+B’

Engr. Khuram Shahzad, FAST NUCES Peshawar 25


Students Task
 Design and implement the circuitry for 3-bit magnitude comparator.
1. Truth Table
2. K-Map
3. Equation
4. Circuit Diagram
5. Implement on logic.ly
 Implement 1 bit, 2 bit, 3 bit and 4 bit comparator on logic lay
 Implement BCD to Excess 3 Converter on logic lay

Engr. Khuram Shahzad, FAST NUCES Peshawar 26


Reference
• https://www.slideshare.net/raiuniversity/b-sc-cs-i-bode-uiii-combitional-logic-circuit
• https://www.slideshare.net/viks100/what-is-comparatorcomparator1bit-2bit-how-its-works-
application
• https://www.geeksforgeeks.org/magnitude-comparator-in-digital-logic/
• https://technobyte.org/2-bit-4-bit-comparator/

Engr. Khuram Shahzad, FAST NUCES Peshawar 27


THANKS 

Engr. Khuram Shahzad, FAST NUCES Peshawar

You might also like