首页 > 解决方案 > 测试台输出意外(总是 stx 和红线)

问题描述

我想尝试实现 16x1 多路复用器的功能实现。一切似乎都很好,但是当我在 testbench 上测试我的项目时,输出m是一条红线,并且总是写 stx. 我需要已知结果而不是 stx。

2x1 多路复用器

module mux_2x1(y,d0,d1,s);

input d0,d1,s;
output y;
wire t0,t1;

and(t0,d0,~s);
and(t1,d1,s);
or(y,t1,t2);

endmodule

4x1 多路复用器

module mux_4x1(y,d0,d1,d2,d3,s0,s1);

input d0,d1,d2,d3,s0,s1;
output y;
wire t0,t1;

mux_2x1 m1(t0,d0,d1,s0);
mux_2x1 m2(t1,d2,d3,s0);

mux_2x1 m3(y,t0,t1,s1);

endmodule

8x1 多路复用器

module mux_8x1(y,d,s0,s1,s2);

input [0:7]d;
input s0,s1,s2;
output y;

wire [0:5]t;

mux_2x1 m1(t[0],d[0],d[1],s0);
mux_2x1 m2(t[1],d[2],d[3],s0);
mux_2x1 m3(t[2],d[4],d[5],s0);
mux_2x1 m4(t[3],d[6],d[7],s0);

mux_2x1 m5(t[4],t[0],t[1],s1);
mux_2x1 m6(t[5],t[2],t[3],s1);

mux_2x1 m7(y,t[4],t[5],s2);

endmodule

16x1 多路复用器

module mux_16x1(y,d,s0,s1,s2,s3);

input [0:15]d;
input s0,s1,s2,s3;
output y;

wire [0:3]t;

mux_8x1 m1(t[0],d,s1,s2,s3);

mux_4x1 m2(t[1],d[8],d[9],d[10],d[11],s2,s3);
mux_4x1 m3(t[2],d[12],d[13],d[14],d[15],s2,s3);

mux_2x1 m4(t[3],t[1],t[2],s1);

mux_2x1 m5(y,t[0],t[3],s0);

endmodule

Verilog代码,功能实现

module mux_16x1_imp(m,a,b,c,d);

input a,b,c,d;
output m;

//module mux_16x1(y,d,s0,s1,s2,s3);
mux_16x1 m1(m,{1'b0,1'b0,1'b1,1'b1,1'b0,1'b1,1'b0,1'b1,1'b1,1'b1,1'b1,1'b1,1'b0,1'b0,1'b0,1'b0},a,b,c,d);

endmodule

这是我的测试台代码

module mux_16x1_imp_test();

reg a,b,c,d;
wire m;

mux_16x1_imp TestBench(m,a,b,c,d);

initial begin

a=1'b0; b=1'b0; c=1'b0; d=1'b0; #100    
a=1'b0; b=1'b0; c=1'b0; d=1'b1; #100
a=1'b0; b=1'b0; c=1'b1; d=1'b0; #100
a=1'b0; b=1'b0; c=1'b1; d=1'b1; #100
a=1'b0; b=1'b1; c=1'b0; d=1'b0; #100
a=1'b0; b=1'b1; c=1'b0; d=1'b1; #100
a=1'b0; b=1'b1; c=1'b1; d=1'b0; #100
a=1'b0; b=1'b1; c=1'b1; d=1'b1; #100
a=1'b1; b=1'b0; c=1'b0; d=1'b0; #100    
a=1'b1; b=1'b0; c=1'b0; d=1'b1; #100
a=1'b1; b=1'b0; c=1'b1; d=1'b0; #100
a=1'b1; b=1'b0; c=1'b1; d=1'b1; #100
a=1'b1; b=1'b1; c=1'b0; d=1'b0; #100
a=1'b1; b=1'b1; c=1'b0; d=1'b1; #100
a=1'b1; b=1'b1; c=1'b1; d=1'b0; #100
a=1'b1; b=1'b1; c=1'b1; d=1'b1; 

end

endmodule

模拟

在此处输入图像描述

标签: logicverilogtest-bench

解决方案


我在 2 个不同的模拟器上收到了编译警告,他们将我指向这 2 行代码。

mux_2x1中,您使用了未声明的t2而不是t0. 改变:

or(y,t1,t2);

至:

or(y,t1,t0);

mux_16x1中,改变:

mux_8x1 m1(t[0],d,s1,s2,s3);

至:

mux_8x1 m1(t[0],d[0:7],s1,s2,s3);

这些更改修复了警告并消除了 x。

如果您没有收到任何警告,您可以在edaplayground上的多个模拟器上尝试您的代码。


推荐阅读