Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops verilogtestbench中的循环测试模式_Loops_Verilog - Fatal编程技术网

Loops verilogtestbench中的循环测试模式

Loops verilogtestbench中的循环测试模式,loops,verilog,Loops,Verilog,使用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 然后我想为它写一个测试台。首先,我使用了7bit register for x(没有数组)——一切都正常,但现在我想用几个测试模式运行它,所以

使用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
然后我想为它写一个测试台。首先,我使用了7bit register for x(没有数组)——一切都正常,但现在我想用几个测试模式运行它,所以我宣布了一个数组,并希望在它上面循环,每次都用新的输入运行模块

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 
模块测试;
reg[0:6]arr[0:1]={7'b0011111,7'b1100000};//所有模式
reg[0:1]arr_size;//图案数量
导线[0:6]x;//当前模式
导线f;//输出
初始开始
$write(“| TIME | x0 | x1 | x2 | x3 | x4 | x5 | x6 | f |”);//标题
$display;
arr_size=$size(arr);//2.
结束
//检查所有测试模式,将其分配给x并运行模块
genvar i;
生成

对于(i=0;i我很惊讶您在为
f
分配多个值时没有出现错误

记住verilog(或任何其他HDL)创建物理电路,生成块创建给定电路的多个版本。在这种情况下,您正在创建
example4\u 23
模块的两个实例,并且两个实例驱动相同的输出。
generate
循环以空间方式运行,而对于
中的循环,添加时总是
块是时间的耽搁

回答您的问题:1)使用
reg
,并在
始终
块中延迟赋值;2) 对!!(见下面的示例);3) 对!!使用参数

下面是您可以做的一些更改:

  • localparam arr_size=2
    替换
    wire arr_size
    (或视情况而定)
  • reg[0:6]arr[0:1]
    更改为
    reg[0:6]arr[0:arr\u SIZE1-]
  • 初始
    块中将
    生成
    循环替换为基本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 
模块测试;
localparam ARR_SIZE=2;//图案数量
localparam[0:6]arr[0:arr_SIZE-1]={7'b0011111,7'b1100000};//所有模式
reg[0:6]x;//当前模式
导线f;//输出
整数i;
示例4_23 dut(x,f);
初始开始
$write(“| TIME | x0 | x1 | x2 | x3 | x4 | x5 | x6 | f |”);//标题
$display;
对于(i=0;i
谢谢!还有一个问题。。。初始先开始,分配x,在延迟期间,始终块对更改作出反应并打印数据。然后再次更改、延迟和打印。您能解释一下测试模块是在什么时候执行的吗?我读过,所有代码都应该包含在初始语句或ALYST语句中。但这里不是这样,请记住verilog描述了物理电路,这意味着模块总是存在的。同样地,测试模块将不断地评估输入,并且没有什么像编程中那样被“执行”。但是,只有当输入或输出改变时,选通才会显示,每5个时间步(#5)一次。