首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于$monitor的verilog仿真

基于$monitor的verilog仿真
EN

Stack Overflow用户
提问于 2014-10-10 04:47:22
回答 1查看 3.2K关注 0票数 0

我一直试图在Verilog实现全加器。我已经实施了它,它也显示了Isim的结果。唯一的问题是,当我尝试使用$monitor命令查看仿真时,它只显示了一个结果,而不是所有的模拟结果。下面是testbench代码:

代码语言:javascript
复制
module Full_adder_s2_testbench;

// Inputs
reg a;
reg b;
reg cin;

// Outputs
wire sum;
wire cout;

// Instantiate the Unit Under Test (UUT)
Full_adder_s2 uut (
    .a(a), 
    .b(b), 
    .cin(cin), 
    .sum(sum), 
    .cout(cout)
);
integer i;

initial begin
    // Initialize Inputs
    a = 0;
    b = 0;
    cin = 0;

    // Wait 100 ns for global reset to finish
    #100;

    end
    always @ ( a, b, cin )
            begin

            // generate truth table
            for ( i = 0; i < 8; i = i + 1 )
                    // every 10 ns set a, b, and cin to the binary rep. of i
                    #10 {a, b, cin} = i;
                    $monitor( "%d ns: a + b + cin = %b + %b + %b = cout sum = %b %b",
                                             $time, a, b, cin, cout, sum );  
            // stop 10ns after last change of inputs
            #10 $stop;
            end


endmodule

ISIM的结果是:

代码语言:javascript
复制
# run 1000 ns 
Simulator is doing circuit initialization process.

Finished circuit initialization process.

                 400 ns: a + b + cin = 1 + 1 + 1 = cout sum = 1 1

Stopped at time : 410 ns :  in File "E:/Namal/FYP/My work/XILINX/Full_adder_s2/Full_adder_s2_testbench.v" Line 66 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-10 05:23:26

$monitor只需要设置一次,每次发生信号更改时都会触发,请尝试使用$display,因为always @*中已经有了语句。

在学习Verilog的同时,我鼓励您自由地使用begin end。问题是,for循环中只有1行,$display/$monitor在外部,因此在开始时只执行一次。

代码语言:javascript
复制
always @* begin
  // generate truth table
  for ( i = 0; i < 8; i = i + 1 ) begin //<-- Added begin
    // every 10 ns set a, b, and cin to the binary rep. of i
    #10 {a, b, cin} = i;
    $display( "%d ns: a + b + cin = %b + %b + %b = cout sum = %b %b", $time, a, b, cin, cout, sum ); 
  end //<--Added end
  // stop 10ns after last input
  #10 $stop;

结束

EDA游乐场上的完整示例。

注意:最好不要再使用手动灵敏度列表,用always @ ( a, b, cin )替换always @*。这将导致更快的重构和降低RTL的机会门模拟错配。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26292123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档