[英]verilog testbench component instantiate using generate
I'm new to verilog and learning. 我是Verilog和学习的新手。 I have a testbench questions. 我有一个测试台问题。 Suppose in Verilog testbench I have 8 instances of a module. 假设在Verilog测试平台中,我有8个模块实例。 Is there a way to instantiate them in the testbench using a generate loop like a module can be declared in the HDL part of the code. 有没有一种方法可以使用生成循环在测试台中实例化它们,就像可以在代码的HDL部分中声明模块一样。 For example 例如
module my_test_bench;
reg one_r;
reg two_r;
wire one_w;
wire two_w;
genvar i;
generate
(for i = 0; i < 8; i=i+1)
begin
DDR3_module uut[i]( .clk(), .rst(), );
end
endgenerate
initial begin
... test stimulus
end
end module
Thanks. 谢谢。
Yes, you can. 是的你可以。 Use the following syntax: 使用以下语法:
genvar i;
generate
for (i = 0; i < 8; i = i + 1) begin
DDR3_module uut (.clk(clk[i]), .rst(rst[i]));
end
endgenerate
Note that you need vectors for the clk
and rst
signals for each instance, such as the following preceding declaration lines: 请注意,每个实例的clk
和rst
信号都需要向量,例如以下前面的声明行:
wire [7:0] clk;
wire [7:0] rst;
If you want to drive those directly from within your initial
block however, those need to be reg
s instead of wire
s. 但是,如果要直接从initial
块中驱动它们,则需要使用reg
而不是wire
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.