与verilog斗争的第一天,这里有一个简单的模块:
module example4_23 (x, f);
input [0:6] x;
output f;
assign f = x[0] & x[1] & x[2] & x[3] & x[4] & x[5] & x[6];
endmodule然后我想为它写一个测试台。首先,我对x(没有数组)使用了7位寄存器--一切都正常,但是现在我想用几个测试模式运行它,所以我宣布了一个数组,并希望循环它,每次都用新的输入运行模块。
module test;
reg [0:6] arr [0:1] = {7'b0011111,7'b1100000}; // all patterns
reg [0:1] arr_size; // number of patterns
wire [0:6] x; // current pattern
wire f; // output
initial begin
$write("| TIME | x0 | x1 | x2 | x3 | x4 | x5 | x6 | f |"); // header
$display;
arr_size = $size(arr); // 2
end
// go through all test patterns, assign it to x and run the module
genvar i;
generate
for (i=0; i<2; i=i+1) // if use 'i<arr_size' gives an error
begin
assign x = arr[i]; // change to '..= arr[1]' or '..= arr[0]' successfully makes one test
example4_23 dut (x,f);
end
endgenerate
// anytime there is a change - output on the screen
always @(x,f)
begin
$strobe("%6d %4d %4d %4d %4d %4d %4d %4d %5d", $time, x[0],x[1],x[2],x[3],x[4],x[5],x[6], f);
end
endmodule 目前,编译后,我只看到标题行。除了一个明显的问题,为什么它不工作,我也不明白以下几点:
提前谢谢。
发布于 2015-11-02 16:25:18
我很惊讶您在为f分配多个值时没有出现错误。
记住verilog (或任何其他HDL)创建物理电路,生成块创建给定电路的多个版本。在本例中,您正在创建example4_23模块的两个实例,并且都驱动相同的输出。Generate循环以空间方式工作,而always块中的for循环在添加延迟时是暂时的。
要回答您的问题: 1)使用reg,并在always块中指定延迟值;2)是的!(见下面的例子);3)是的!使用参数!
因此,以下是您可以做的一些更改:
wire arr_size替换为localparam ARR_SIZE = 2 (或酌情)reg [0:6] arr [0:1]更改为reg [0:6] arr [0:ARR_SIZE1-]generate循环替换为initial块中的基本for循环#记录延迟(见下文)always @(*)而不是always @(x,f)以下是我要实施的内容:
module test;
localparam ARR_SIZE = 2; // number of patterns
localparam [0:6] arr [0:ARR_SIZE-1] = {7'b0011111,7'b1100000}; // all patterns
reg[0:6] x; // current pattern
wire f; // output
integer i;
example4_23 dut (x,f);
initial begin
$write("| TIME | x0 | x1 | x2 | x3 | x4 | x5 | x6 | f |"); // header
$display;
for (i=0; i< ARR_SIZE; i=i+1) begin
x = arr[i];
#5; // delay 5 timesteps
end
end
// anytime there is a change - output on the screen
always @(*)
begin
$strobe("%6d %4d %4d %4d %4d %4d %4d %4d %5d", $time, x[0],x[1],x[2],x[3],x[4],x[5],x[6], f);
end
endmodule https://stackoverflow.com/questions/33481531
复制相似问题