Files
verilog/testbench.v
2024-12-30 16:19:10 +08:00

52 lines
1007 B
Verilog
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 时间尺度 以1ns为时钟单位 / 1ns为时钟精度
`timescale 1ns/1ns
// 包含文件 main_module.v 编译的时候就不需要指定这个文件了
`include "main_module.v"
// 定义模块 此模块没有输入输出
module testbench();
reg clk;
reg rst;
wire dout;
wire [31:0] sum;
// 指定参数
parameter CYCLE = 2;
parameter END_TIME = 200;
// 实例化模块
test mod(
.clk(clk),
.rst(rst),
.dout(dout),
.sum(sum)
);
// 初始化块 此块用于生成波形文件
// initial 语句为仿真语句通常在testbench中使用
initial begin
$dumpfile("wave.vcd");
$dumpvars(0,testbench);
end
// 寄存器初始化,只有初始化之后才会产生波形
initial begin
clk = 0;
rst = 0;
end
initial begin
#5 rst = 1;
end
// 每隔一个时钟周期取反
always begin
#(CYCLE / 2) clk = ~clk;
end
// 在END_TIME个时钟周期之后结束
initial begin
#END_TIME;
$stop;
end
endmodule