Professional Documents
Culture Documents
Sem II AY 2023-24
Experiment No. : 05
Objective
(i) Design, simulate, and implement a Priority Encoder
Logic Design
A Priority Encoder implements a priority function: If more than one input is 1, the input having highest
priority takes precedence. Here, the input having a higher index will take priority.
Source Description
- Design source module priority_encoder(input [3:0] D, output reg A, output reg B, output reg V);
always @(D) begin if (D[3]==1'b1) begin A = 1'b1; B = 1'b1; V = 1'b1; end
else if (D[2]==1'b1) begin A = 1'b1; B = 1'b0; V = 1'b1; end else if (D[1]==1'b1)
begin A = 1'b0; B = 1'b1;
V = 1'b1;
end else if
(D[0]==1'b1) begin
A = 1'b0; B = 1'b0;
V = 1'b1; end else
if (D==4'b0000)
begin A = 1'bx;
B = 1'bx;
V = 1'b0;
end end
endmodule
- Constraint file
The PYNQ XDC file was updated with the following changes:
Ports Designation Pin Configuration
(from Verilog module) (Input/Output) PYNQ Component Type (from the PYNQ User
(Button/LED/Switch etc. along Manual)
with number, eg. LD01, BTN2, etc.)
The RPI XDC file was updated with the following changes:
- Simulation source
module testbench;
reg [3:0] D; wire A,B,V; priority_encoder
test(D,A,B,V); initial begin for (D = 4'b0000;
D<4'b1111; D=D+4'b0001) begin #20;
end D=4'b1111;
#20;
$finish; end
endmodule
Simulation Results (Timing diagram)
Truth Table
Input Output
D0 D1 D2 D3 A B V
0 0 0 0 X X 0
1 0 0 0 0 0 1
X 1 0 0 0 1 1
X X 1 0 1 0 1
X X X 1 1 1 1
Schematic
Logic Design
A 4 x 16 decoder can be made using five 2 x 4 decoders as shown in Fig.
Source Description
- Constraint file
The PYNQ XDC file was updated with the following changes:
Ports Designation Pin Configuration
(from Verilog module) (Input/Output) PYNQ Component Type (from the PYNQ User
(Button/LED/Switch etc. along Manual)
with number, eg. LD01, BTN2, etc.)
The RPI XDC file was updated with the following changes:
A=4'b0000;
#20;
A=4'b1110;
#20;
A=4'b1011;
#20;
A=4'b0110;
#20;
A=4'b1001;
#20;
A=4'b0010;
#20;
A=4'b1111;
#20;
A=4'b1010;
#20;
$finish;
end
endmodule
Simulation Results (Timing diagram)
Truth Table
Schematic
Complete File
https://drive.google.com/file/d/1lcI2QPEwPlXczKeQ6n3AoABZm3L5WiM6/view?usp=classroom_web
&authuser=0
Objective
(iii) Design, simulate, and implement a Binary-to-Gray Code Converter
Logic Design
A 4-bit Binary-to-Gray converter takes a 4-bit binary number and converts it to corresponding Gray
code.
Source Description
The RPI XDC file was updated with the following changes:
- Simulation source
repeat(2) begin
b3 = ~b3; b2 =
~b2; b1 = ~b1;
b0 = ~b0;
#5;
b0 = ~b0;
#5; b0 =
~b0;
b1=~b1;
#5; b0 =
~b0; #5;
b2 = ~b2;
b0=~b0;
b1=~b1;
#5;
b0=~b0;
#5;
b0=~b0;
b1=~b1;
#5;
b0=~b0;
#5; end
$finish; end
Complete File
https://drive.google.com/file/d/1cGT_-
lbFxYLoI12ipv4nvmLUybGcSANj/view?usp=classroo
m_web&authuser=0