【问题标题】:Writing testbench in Modelsim在 Modelsim 中编写测试平台
【发布时间】:2015-01-26 03:56:34
【问题描述】:

我正在尝试在 modelsim 中用 verilog 编写一个测试台。我已经为测试平台和被测模块编写了代码。但是在编译它时,我收到一条错误消息,说编译失败。 那么我们是否必须在单独的模块中编写测试台代码,并且对于被测模块也一样?

//Writing a test bench
module test_bench;
wire w1,w2,w3;
xyz(w1,w2,w3);
test_xyz(w1,w2,w3);
endmodule;

//现在我们将定义我们在测试平台模块中实例化的模块

//定义模块xyz

module xyz(f,A,B);
input A,B;
output f;
nor(f,A,B);
endmodule;

//Defining the test module which we are going to apply to the module xyz

module test_xyz(f,A,B); 
input f;
output A,B;
initial 
begin 
$monitor ($time ,"A=%b","B=%b", "f=%b",A,B,f);
#10 A=0;B=0;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $finish ;
end
endmodule;

【问题讨论】:

    标签: verilog modelsim


    【解决方案1】:

    endmodule 不需要分号。

    实例应该有实例名称:

    module test_bench;
      wire          w1,w2,w3;
      xyz      dut (w1,w2,w3);
      test_xyz test(w1,w2,w3);
    endmodule
    

    如果您要从初始块或始终块驱动信号,则它们需要在 localscope* 中为 reg 而不是 wire

    module test_xyz(f,A,B); 
      input f;
      output reg A,B; //A B are regs
    

    *localscope :驱动线的地方是一个 reg,但模块的输出驱动线。 Verilog 类型不跨越端口边界。

    EDA Playground 上的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      相关资源
      最近更新 更多