2.1实验目的
熟悉Vivado软件开发环境,学会设计组合逻辑电路。学会查看RTL原理图。实现并仿真:
1)五输入优先编码器;
2)带使能信号的2-4译码器;
3)带使能信号的四裁判打分器。
2.2实验内容
(1)参照课件中的四输入优先编码器代码,改成五输入优先编码器,实现并仿真。真值表如下:
(2)参照课件中的代码实现并仿真带使能信号的2-4译码器。
(3)使用Verilog HDL设计带使能信号(en)的四裁判打分器并仿真。要求:使能信号(en)为1,才进行结果判断,否则结果为0。裁判3个以上给了1,结果才为1。
提示:可以使用if-else加case语句实现,或者使用casex语句实现。
撰写实验报告,版面排版要求:
2.3五输入优先编码器
(1)设计代码
`timescale 1ns / 1ps
module prior_encoder(r,y);
input[4:0] r;
output reg[2:0] y;
always@ *
casex(r)
5'b1????: y=3'b111;
5'b01???: y=3'b110;
5'b001??: y=3'b101;
5'b0001?: y=3'b100;
5'b00001: y=3'b011;
default: y=3'b010;
endcase
endmodule
(2)RTL原理图
(3)testbench代码
`timescale 1ns / 1ps
module test;
reg [4:0] r;
wire [2:0] y;
prior_encoder unit(r,y);
initial
begin
r=0;
end
always #11 r[4]=~r[4];
always #9 r[3]=~r[3];
always #7 r[2]=~r[2];
always #3 r[1]=~r[1];
always #6 r[0]=~r[0];
initial #200 $finish;
endmodule
(4)仿真波形
2.4带使能信号的2-4译码器
(1)设计代码
`timescale 1ns / 1ps
module decoder_2_4(en,a,y);
input en;
input[1:0] a;
output reg[3:0] y;
always@ *
case({en,a})
3'b100: y=4'b0001;
3'b101: y=4'b0010;
3'b110: y=4'b0100;
3'b111: y=4'b1000;
default: y=4'b0000;
endcase
endmodule
(2)RTL原理图
(3)testbench代码
`timescale 1ns / 1ps
module testbench;
reg en;
reg[1:0] a;
wire[3:0] y;
decoder_2_4 unit(en,a,y);
initial
begin
en=1'b0; a=0;
end
always #6 en=~en;
always #10 a[1]=~a[1];
always #5 a[0]=~a[0];
initial #200 $finish;
endmodule
(4)仿真波形
2.5带使能信号的四裁判打分器模块设计
(1)设计代码
`timescale 1ns / 1ps
module Score4(en,A,B,C,D,F);
input en,A,B,C,D;
output reg F;
always @*
begin
if(!en)
F=1'b0;
else
case({en,A,B,C,D})
5'b10111,5'b11011,5'b11101,5'b11110,5'b11111: F=1'b1;
default: F=1'b0;
endcase
end
endmodule
(2)RTL原理图
(3)testbench代码
`timescale 1ns / 1ps
module test3;
reg en,A,B,C,D;
wire F;
Score4 unit1(en,A,B,C,D,F);
initial
begin
en=0; A=1; B=1; C=1; D=1;
end
always #20 en=~en;
always #5 A=~A;
always #7 B=~B;
always #4 C=~C;
always #9 D=~D;
initial #200 $finish;
endmodule
(4)仿真波形