2014-10-10 74 views
0

我一直試圖在Verilog中實現全加器。我已經實施了它,並且還在Isim上展示了結果。唯一的問題是,當我嘗試使用$ monitor命令查看仿真時,它僅顯示1個結果,並非全部仿真結果。下面是測試平臺代碼:

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:

運行1000 NS

模擬器是做電路初始化過程。

成品電路初始化過程。

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

結束的時刻:410納秒:在文件 「E:/ Namal/FYP /我的作品/ XILINX/Full_adder_s2/Full_adder_s2_testbench.v」 線66

回答

2

$monitor僅僅意味着是建立一次,每次信號改變時都會觸發,請嘗試使用$display,因爲您已經在always @*內部有聲明。

在學習Verilog的時候,我鼓勵大家寬宏地使用begin end。問題是for循環中只有1行,$display/$monitor在外面,所以只在開始時執行一次。

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 Playground完整例子。

注意:最好不要用手動靈敏度列表替代always @ (a, b, cin)always @*。這將導致更快的重構並降低RTL模擬不匹配的機會。

+0

我嘗試了使用$ display的兩個選項,並總是@ *,但結果仍然與上面相同。 – 2014-10-10 06:31:16

+0

謝謝!摩根,我的問題解決了。 :) – 2014-10-10 07:29:02