I'm trying to make a 1:4 Demultiplexer but I keep getting the error about my ports. Every time I try and type the command
iverilog -o Lab12_tb.vvp Lab12_tb.v
to simulate my text bench in the vs code terminal, it pop up the error.
Design
module Lab12 (
W,X,Y,Z, Cin, A, B,
);
input Cin,A,B;
output W,X,Y,Z;
assign W = (Cin) & (~A) & (~B);
assign X = (Cin) & (A) & (~B);
assign Y = (Cin) & (~A) & (B);
assign Z = (Cin) & (A) & (B);
endmodule
Testbench
// Testbench for 1:4 Demultiplexer
`timescale 1ns/1ns
`include "Lab12.v"
module Lab12_tb;
reg Cin,A,B;
wire W,X,Y,Z;
Lab12 uut (Cin, A, B, W, X, Y, Z);
//iverilog -o Lab12_tb.vvp Lab12_tb.v
initial begin
$dumpfile("Lab12_tb.vcd");
$dumpvars(0,Lab12_tb);
Cin = 1; A = 0; B = 0;
#1
Cin = 1; A = 1; B = 0;
#1
Cin = 1; A = 0; B = 1;
#1
Cin = 1; A = 1; B = 1;
$finish();
$display("Completed");
end
initial begin
$monitor("%t| Cin = %d| A = %d| B = %d| W = %d| X = %d| Y = %d| Z = %d",
$time, Cin,A,B, W,X,Y,Z);
end
endmodule
There are five issues total, the first 3 cause errors, the last two are behavioral.
As pointed out in the comments by @Markus Safar, there is an extra comma at the end of the testbench dut instance association list. It makes the tool think there is another port expected there. The correction is obliviously to use
(Cin, A, B, W, X, Y, Z);The 2nd is that you are relying on positional association for the port list, and the ports are out of order WRT the testbench variables. The order in your module is this
W,X,Y,Z, Cin, A, Bthe order in the testbench is thisCin, A, B, W, X, Y, Z. The moduleWport is getting associated with the testbench reg variableCinand so on. The module drivesWand the testbench drivesCin, so the compiler flags this as multiple drivers and produces an error. Same with module portXand testbench variable regA, and so on for each driving variable in the testbench.The best practice to avoid this is to use named association for the port map list, so that the order does not matter. This sample of testbench code fixes both errors. The
.<variable name>specifies the module port name, the parenthesis contain the local testbench variable name. In your case the names should match.Using a vertical style makes it easier to view and maintain without making mistakes.
I think some junk ended up in your post at the end of the
$finishline'your text'Just remove this because it causes an error.You have these two lines at the end of your testbench initial block
The $finish will cause the simulation to stop and the $display will not execute. Swap the order so that "Completed" is printed.
Note that I also removed the junk text.