[英]Verilog testbench code using gEDA and iVerilog
我的任務是編寫一個簡單的 2 到 4 解碼器,然后顯示可能的結果和波形。
我使用 gEDA 套件和 Icarus Verilog (iVerilog) 作為編譯器和 GTKWave 作為波形。
這是我第一次使用 Verilog 編碼或使用 gEDA 套件。 從谷歌搜索看來,我需要遵循這個設計流程:
測試台文件無法編譯,我不知道為什么,我嘗試了幾種變體,但不斷出現錯誤。 任何幫助深表感謝。 謝謝你。
這是我的設計文件代碼:
// 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.