簡體   English   中英

使用 gEDA 和 iVerilog 的 Verilog 測試平台代碼

[英]Verilog testbench code using gEDA and iVerilog

我的任務是編寫一個簡單的 2 到 4 解碼器,然后顯示可能的結果和波形。

我使用 gEDA 套件和 Icarus Verilog (iVerilog) 作為編譯器和 GTKWave 作為波形。

這是我第一次使用 Verilog 編碼或使用 gEDA 套件。 從谷歌搜索看來,我需要遵循這個設計流程:

  1. 想想你想要實現的設計。 在我的情況下,解碼器
  2. 在 VHDL/Verilog 中實現設計。
  3. 在 VHDL/Verilog 中實現一個測試平台。
  4. 使用 iVerilog 編譯設計文件和測試台文件
  5. 使用 testbench 和 .vcd 轉儲文件使用 GTKWave 顯示波形

測試台文件無法編譯,我不知道為什么,我嘗試了幾種變體,但不斷出現錯誤。 任何幫助深表感謝。 謝謝你。

這是我的設計文件代碼:

// 2 to 4 Decoder
// File Name: decoder.v

module decoder(X,Y,E,Z);
    input X,Y,E;
    output [0:3]Z;
    wire [0:3]Z;
    wire X1, Y1;

    not
        inv1(X1,X),
        inv2(Y1,Y);
    and
        and1(Z[0],X1,Y1,E),
        and2(Z[1],Y1,X,E),
        and3(Z[2],Y,X1,E),
        and4(Z[3],X,Y,E);
endmodule

這是我的測試平台代碼:

module decoder_tb;
    input X,Y,E;
    output [0:3]Z;
    //wire [0:3]Z;
    //wire X1, Y1;  

    // should create .vcd dump file for GTKWave
    initial
        begin
            $dumpfile("decoder.vcd");
            $dumpvars();    
        end

    decoder decode(X,Y,E,Z);
    initial 
        begin
            $display($time,"<< Z[0]=%d   Z[1]=%d   Z[2]=%d   Z[3]=%d >>", Z[0] , Z[1] , Z[2] , Z[3] );  
        end 

    initial 
        begin 
         #0
         X = 0; Y = 0; E = 1; 
         #5 
         X = 0; Y = 1; E = 1;
         #10 
         X = 1; Y = 0; E = 1;
         #15 
         X = 1; Y = 1; E = 1;
        end 
endmodule

我正在使用的終端中的命令是:

iverilog -o decoder.vvp decoder.v decoder_tb.v
gtkwave decoder.vcd

編輯:這是確切的錯誤消息

aj@aj:~/verilogCode$ iverilog -o decoder.vvp decoder.v decoder_tb.v
decoder_tb.v:26: error: X is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : X is declared here as wire.
decoder_tb.v:26: error: Y is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : Y is declared here as wire.
decoder_tb.v:26: error: E is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : E is declared here as wire.
decoder_tb.v:28: error: X is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : X is declared here as wire.
decoder_tb.v:28: error: Y is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : Y is declared here as wire.
decoder_tb.v:28: error: E is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : E is declared here as wire.
decoder_tb.v:30: error: X is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : X is declared here as wire.
decoder_tb.v:30: error: Y is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : Y is declared here as wire.
decoder_tb.v:30: error: E is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : E is declared here as wire.
decoder_tb.v:32: error: X is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : X is declared here as wire.
decoder_tb.v:32: error: Y is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : Y is declared here as wire.
decoder_tb.v:32: error: E is not a valid l-value in decoder_tb.
decoder_tb.v:6:      : E is declared here as wire.
12 error(s) during elaboration.

在您的測試平台中,將input更改為reg並將output更改為wire 這為我修復了編譯錯誤(盡管我沒有使用 gEDA 或 iVerilog):

module decoder_tb;
    reg X,Y,E;
    wire [0:3]Z;

在這種情況下,我的模擬器給出了比你更有意義的錯誤信息:

標識符“X”未出現在端口列表中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM