verilog 4bit mux测试台代码给出x

时间:2016-12-14 20:28:29

标签: verilog mux test-bench

无法理解为什么它不起作用,我在eda操场上进行了模拟,我得到了一个" x"每次选择变为0时输出。我正确得到" 1"当sel是" 1"虽然。谢谢!

代码:

 module mux8_2(input [3:0]a,[3:0]b,sel,output [3:0]out);   
 assign out=(sel)?a:b;  
 endmodule

和测试台:

 module mux8_2_tb; 

 reg [3:0]A;  

 reg [3:0]B;  

 reg SEL;  

 wire [3:0]OUT;  

 mux8_2 UUT(A,B,SEL,OUT);  

 initial  
  begin  

 $dumpfile("dump.vcd");  

 $dumpvars(1);  

 A=4'b1; B=4'b0; SEL=1'b1;

 #1 SEL=1'b0;  
 #1 SEL=1'b1;  
 #1 SEL=1'b0;  
 #1 SEL=1'b1;  
 #1 SEL=1'b0;  
 #1 SEL=1'b1;  
 #1;
 end

 endmodule

1 个答案:

答案 0 :(得分:1)

我无法重现你的结果;我总是知道OUT信号。

但是,我收到了编译警告:

The following 1-bit expression is connected to 4-bit port "sel" of module 
  "mux8_2", instance "UUT"

这可以修复:

module mux8_2(input [3:0]a,[3:0]b, input sel,output [3:0]out);   

在您的代码中sel继承了上一个信号([3:0]b)的宽度。您的代码相当于:

module mux8_2(input [3:0]a,[3:0]b,[3:0]sel,output [3:0]out);   

input之前添加另一个sel关键字会强制它使用默认宽度1位。