logic - 测试台输出意外(总是 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
模拟
解决方案
我在 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上的多个模拟器上尝试您的代码。
推荐阅读
- python - 使用 1 到 100 的不同输入重复一个 python 脚本
- javascript - reactJS:从“yyyy-mm-ddThh-mm-ss.sssZ”转换为“yyyy-mm-dd hh-mm”
- opengl - 如何访问底层 Skia 上下文并运行我自己的 opengl 命令进行绘制?
- php - 在现有的 Laravel 项目上安装 laravel/sail 时如何选择多个服务?
- twig - 如何使用 Twig 检查 Shopware 6 中的当前活动类别?
- python - 用于实现自组织地图的库 sompy
- ios - iOS 应用程序加载器卡在识别控件上
- r - 标题到数据框
- typescript - 如何在 Typescript 中定义具有一些可选指定属性以及一些必需指定属性的类型
- javascript - 以 JSON 格式存储 URL 的 CSS 数组