实验目的
熟悉 Vivado 开发环境,掌握设计流程,包括如何用 Verilog 语言设计电
路、仿真、综合、实现与下载。
实验内容
门电路设计:
使用 Verilog HDL 语言的数据流描述方法设计一个数据宽度可在 1~32
之间变化的 2 输入与门 andgate(或门、非门、与非门等基本门电路),利
用仿真来验证设计。并将该与门封装成可变数据宽度参数的 IP 核。
代码如下
and_notgate.xpr
`timescale 1ns / 1ps
module and_notgate #(parameter WIDTH=8)(
input [(WIDTH-1):0]a,
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=~(a&b);
endmodule
仿真文件:
and_notgate_sim2
`timescale 1ns / 1ps
module and_notgate_sim2( );
//input
reg a=0;
reg b=0;
//output
wire c;
and_notgate #(1) u(a,b,c);
initial begin
#100 a=1;
#100 begin a=0; b=1;end
#100 a=1;
end
endmodule
仿真波形图:
andgate.xpr
`timescale 1ns / 1ps
module andgate #(parameter WIDTH=8) //指定数据宽度参数,缺省值是8
(
input [(WIDTH-1):0]a, //出具位数由参数WIDTH决定
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=a&b; //2输入与门
endmodule
仿真文件:
andgate_sim2
`timescale 1ns / 1ps
module andgate_sim2( );
//input
reg a=0;
reg b=0;
//output
wire c;
andgate #(1) u(a,b,c); //实例化与门的时候,设定宽度为1
initial begin
#100 a=1;
#100 begin a=0;b=1;end
#100 a=1;
end
endmodule
仿真波形图:
notgate.xpr
`timescale 1ns / 1ps
module notgate #(parameter WIDTH=8)(
input [(WIDTH-1):0]a,
output [(WIDTH-1):0]b
);
assign b=~a;
endmodule
仿真文件:
notgate_sim2
`timescale 1ns / 1ps
module notgate_sim2( );
//input
reg a=0;
//output
wire b;
notgate #(1) u(a,b); //实例化非门的时候,设定宽度为1
initial begin
#100 a=1;
#100 begin a=0;end
#100 a=1;
end
endmodule
仿真波形图:
nxorgate.xpr
`timescale 1ns / 1ps
module nxorgate #(parameter WIDTH=8)(
input [(WIDTH-1):0]a,
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=~(a^b);
endmodule
仿真文件:
nxorgate_sim2
`timescale 1ns / 1ps
module nxorgate_sim2( );
//input
reg a=0;
reg b=0;
//output
wire c;
nxorgate #(1) u(a,b,c); //传入参数为1,设置宽度WIDTH=1
initial begin
#100 a=1;
#100 begin a=0; b=1;end
#100 a=1;
end
endmodule
仿真波形图:
or_notgate.xpr
`timescale 1ns / 1ps
module or_notgate #(parameter WIDTH=8)(
input [(WIDTH-1):0]a,
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=~(a|b);
endmodule
仿真文件:
or_notgate_sim2
`timescale 1ns / 1ps
module or_notgate_sim2( );
//input
reg a=0;
reg b=0;
//output
wire c;
or_notgate #(1) u(a,b,c);
initial begin
#100 a=1;
#100 begin a=0; b=1;end
#100 a=1;
end
endmodule
仿真波形图:
orgate.xpr
`timescale 1ns / 1ps
module orgate #(parameter WIDTH=8) //指定数据宽度参数,缺省值是8
(
input [(WIDTH-1):0]a, //出具位数由参数WIDTH决定
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=a|b; //2输入或门
endmodule
仿真文件:
orgate_sim
`timescale 1ns / 1ps
module orgate_sim( );
reg [31:0]a=32'h00000000;
reg [31:0]b=32'h00000000;
wire [31:0]c;
orgate #(32) u(a,b,c);
initial begin
#100 a=32'hffffffff;
#100 begin a=32'h00000000;b=32'hffffffff;end
#100 a=32'h007fa509;
#100 a=32'hffffffff;
end
endmodule
仿真波形图:
xorgate.xpr
`timescale 1ns / 1ps
module xorgate #(parameter WIDTH=8)(
input [(WIDTH-1):0]a,
input [(WIDTH-1):0]b,
output [(WIDTH-1):0]c
);
assign c=a^b;
endmodule
仿真文件:
xorgate_sim2
`timescale 1ns / 1ps
module xorgate_sim2( );
//input
reg a=0;
reg b=0;
//output
wire c;
xorgate #(1) u(a,b,c); //传入参数为1,设置宽度WIDTH=1
initial begin
#100 a=1;
#100 begin a=0; b=1;end
#100 a=1;
end
endmodule
仿真波形图: