简体   繁体   English

Verilog Testbench的输出均为x或z

[英]Outputs of verilog testbench are all x or z

I do not understand verilog terribly well so this may be some simple issue with the way I have things set up, but I cannot seem to identify why my simulation waveform yields either x or z for my testbench outputs. 我对Verilog的理解不是很好,所以这可能是我设置方式的一个简单问题,但是我似乎无法确定为什么我的仿真波形为我的测试台输出产生x或z的原因。 Here is the module I am simulating: 这是我正在模拟的模块:

module addsub_4bit (Sum, Ovflw, A, B, sub);
input [3:0] A, B;
input sub;
output [3:0] Sum;
output Ovflw;

wire cin, c0, c1, c2, c3;

assign B[3:0] = (sub) ? (~B + 1) : B;
assign cin = 0;
assign Ovflw = (c3 ^ c2);

full_adder_1bit fa0 (.sum(Sum[0]), .cout(c0), .a(A[0]), .b(B[0]), .cin(cin));
full_adder_1bit fa1 (.sum(Sum[1]), .cout(c1), .a(A[1]), .b(B[1]), .cin(c0));
full_adder_1bit fa2 (.sum(Sum[2]), .cout(c2), .a(A[2]), .b(B[2]), .cin(c1));
full_adder_1bit fa3 (.sum(Sum[3]), .cout(c3), .a(A[3]), .b(B[3]), .cin(c2));

endmodule

and my testbench: 和我的测试台:

module addsub_4bit_tb();
reg [7:0] stim;
reg sub;
wire [3:0] Sum;
wire Ovflw;
integer i;

addsub_4bit DUT(.Sum(Sum), .A(stim[3:0]), .B(stim[7:4]), .Ovflw(Ovfw), 
.sub(sub));

initial begin

stim = 0;
sub = 0;
#100;
for(i=0; i<16; i=i+1) begin
stim = stim + 1;
#100;
end 

stim = 0;
sub = 1;
#100;
for(i=0; i<16; i=i+1) begin
stim = stim + 1;
#100;
end

end

initial $monitor("A= %d\tB= %d\nAdd/Sub= %b\nSum= %d\tOvflw= 
%b",stim[3:0],stim[7:4],sub,Sum,Ovflw);

endmodule

My output gives that Sum = x and Ovflw = z. 我的输出给出Sum = x和Ovflw = z。 The single bit full adder module that I use to compose my 4 bit adder works fine and was tested. 我用来构成4位加法器的一位完全加法器模块可以正常工作并经过测试。 I appreciate any feedback. 我感谢任何反馈。

For overflow bit,there is a typo in testbench : 对于溢出位, testbench中有一个错字

.Ovflw(Ovfw),

For Sum vector getting x issue, the input B has multiple drivers , one in testbench and another in RTL itself: 对于求和向量x问题,输入B具有多个驱动程序 ,一个在testbench中,另一个在RTL中:

.B(stim[7:4]) // TB driver
assign B[3:0] = (sub) ? (~B + 1) : B; // RTL driver

So, to avoid this, take some intermediate wire in RTL and assign value of B or ~B to it. 所以,为了避免这种情况, 需要一定的中间线在RTL和分配的值B~B给它。 Here I have used wire X to drive single bit adders. 在这里,我使用线X驱动一位加法器。

wire [3:0] X;
//...
assign X[3:0] = (sub) ? (~B + 1) : B;
//...
full_adder_1bit fa0 (.sum(Sum[0]), .cout(c0), .a(A[0]), .b(X[0]), .cin(cin));
//... 

Refer to this link for more information on multiple drivers. 有关更多驱动程序的更多信息,请参考此链接 If you are using SystemVerilog, then you can use logic datatype to avoid multiple driver issue. 如果使用SystemVerilog,则可以使用逻辑数据类型来避免出现多个驱动程序问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM