在 modelsim 中模拟 Verilog 设计时出现未知错误结果

Unknown Wrong result when simulating Verilog design in modelsim

设计:

//structural description of 74151
module s_74151(VCC, GND, D0, D1, D2, D3, D4, D5, D6, D7, A, B, C, STROBE, Y, W);

input D0, D1, D2, D3, D4, D5, D6, D7; //data inputs
input STROBE; //enable
input A, B, C; //Data select
output Y, W; //outputs

input supply1 VCC; // logic 1 vcc supply wire
input supply0 GND; // logic 0 gnd supply wire

wire n1, n2, n3, n4, n5, n6, n7, n8; // temp AND outputs 
wire A1, A2, B1, B2, C1, C2, S1; //address buffers
wire r1; //temp NOR output

not(A1, A);
not(B1, B);
not(C1, C);
not(A2, A1);
not(B2, B1);
not(C2, C1);
not(S1, STROBE);

and(n1, D0, A1, B1, C1, S1);
and(n2, D1, A2, B1, C1, S1);
and(n3, D2, A1, B2, C1, S1);
and(n4, D3, A2, B2, C1, S1);
and(n5, D4, A1, B1, C2, S1);
and(n6, D5, A2, B1, C2, S1);
and(n7, D6, A1, B2, C2, S1);
and(n8, D7, A2, B2, C2, S1);

nor(r1, n1, n2, n3, n4, n5, n6, n7, n8);

not(Y, r1);
buf(W, r1);

endmodule

//74151 using data flow.
module d_74151(VCC, GND, D0, D1, D2, D3, D4, D5, D6, D7, A, B, C, STROBE, Y, W);

input D0, D1, D2, D3, D4, D5, D6, D7; //data inputs
input STROBE; //enable
input A, B, C; //Data select
output Y, W; //outputs

input supply1 VCC; // logic 1 vcc supply wire
input supply0 GND; // logic 0 gnd supply wire

wire n1, n2, n3, n4, n5, n6, n7, n8; // temp AND outputs 
wire A1, A2, B1, B2, C1, C2, S1; //address buffers
wire r; //temp NOR output

assign A1 = !A;
assign B1 = !B;
assign C1 = !C;
assign A2 = !A1;
assign B2 = !B1;
assign C2 = !C1;
assign S1 = !STROBE;

assign n1 = D0 && A1 && B1 && C1 && S1;
assign n2 = D1 && A2 && B1 && C1 && S1;
assign n3 = D2 && A1 && B2 && C1 && S1;
assign n4 = D3 && A2 && B2 && C1 && S1;
assign n5 = D4 && A1 && B1 && C2 && S1;
assign n6 = D5 && A2 && B1 && C2 && S1;
assign n7 = D6 && A1 && B2 && C2 && S1;
assign n8 = D7 && A2 && B2 && C2 && S1;

assign r = !(n1 || n2 || n3 || n4 || n5 || n6 || n7 || n8);

assign Y = !r;
assign W = r;

endmodule

测试平台:

`include "C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/74151.v"

module m74151_tb();

reg D0, D1, D2, D3, D4, D5, D6, D7, A, B, C, STROBE;

wire VCCs, GNDs, VCCd, GNDd, Ys, Ws, Yd, Wd;

s_74151 s7(.VCC(VCCs), .GND(GNDs), .D0(D0), .D1(D1), .D2(D2), .D3(D3), .D4(D4), .D5(D5), .D6(D6), .D7(D7), .A(A), .B(B), .C(C), .STROBE(STROBE), .Y(Ys), .W(Ws));

d_74151 d7(.VCC(VCCd), .GND(GNDd), .D0(D0), .D1(D1), .D2(D2), .D3(D3), .D4(D4), .D5(D5), .D6(D6), .D7(D7), .A(A), .B(B), .C(C), .STROBE(STROBE), .Y(Wd), .W(Wd));


  initial begin

  $display("simulation started");

$monitor("Input: D0 = %b, D1 = %b, D2 = %b, D3 = %b, D4 = %b, D5 = %b, D6 = %b, D7 = %b, A = %b, B = %b, C = %b, STROBE = %b\nStructural: Y = %b, W = %b\nData Flow: Y = %b, W = %b\n", 
  D0, D1, D2, D3, D4, D5, D6, D7, A, B, C, STROBE, Ys, Ws, Yd, Wd);

  D0 = 1;
  D1 = 0;
  D2 = 1;
  D3 = 1;
  D4 = 0;
  D5 = 1;
  D6 = 0;
  D7 = 0;
  A = 0;
  B = 0;
  C = 0;
  STROBE = 1;
  #1 STROBE = 0; 

  #8  begin
  $display("simulation ended");
  $stop;
end

end

 always  #1 A = !A;
 always  #2 B = !B;
 always  #4 C = !C;

endmodule

输出结果:

# simulation started
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 0, B = 0, C = 0, STROBE = 1
# Structural: Y = 0, W = 1
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 1, B = 0, C = 0, STROBE = 0
# Structural: Y = 0, W = 1
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 0, B = 1, C = 0, STROBE = 0
# Structural: Y = 1, W = 0
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 1, B = 1, C = 0, STROBE = 0
# Structural: Y = 1, W = 0
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 0, B = 0, C = 1, STROBE = 0
# Structural: Y = 0, W = 1
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 1, B = 0, C = 1, STROBE = 0
# Structural: Y = 1, W = 0
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 0, B = 1, C = 1, STROBE = 0
# Structural: Y = 0, W = 1
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 1, B = 1, C = 1, STROBE = 0
# Structural: Y = 0, W = 1
# Data Flow: Y = z, W = x
# 
# Input: D0 = 1, D1 = 0, D2 = 1, D3 = 1, D4 = 0, D5 = 1, D6 = 0, D7 = 0, A = 0, B = 0, C = 0, STROBE = 0
# Structural: Y = 1, W = 0
# Data Flow: Y = z, W = x
# 
# simulation ended

我不知道为什么或如何得到 d_74151 模块的 Y 和 W 输出的 x 和 y 值。虽然我测试并看到 r 得到了 0 或 1 的正确输出,但依赖于 r 的 Y 和 W 仍然在模拟中显示这些值。关于这个以及如何解决它的任何想法?提前致谢。

P.S。这些是包含启用的 8 位 multiplexer/selector 的结构和数据流描述。

您的 d7 实例正在驱动同一条线路 (Wd) 和 2 个输出端口:YWYd 线未驱动。要删除 Wd 上的 x,请将 Yd 连接到 Y 输出端口。

变化:

d_74151 d7(.VCC(VCCd), .GND(GNDd), .D0(D0), .D1(D1), .D2(D2), .D3(D3), .D4(D4), .D5(D5), .D6(D6), .D7(D7), .A(A), .B(B), .C(C), .STROBE(STROBE), .Y(Wd), .W(Wd));

至:

d_74151 d7(.VCC(VCCd), .GND(GNDd), .D0(D0), .D1(D1), .D2(D2), .D3(D3), .D4(D4), .D5(D5), .D6(D6), .D7(D7), .A(A), .B(B), .C(C), .STROBE(STROBE), .Y(Yd), .W(Wd));

使用允许将信号跟踪到波形的调试工具更容易调试这些错误。

一个变量不能有一个以上的连续驱动。要调试这些更好的使用基于波形的方法

例如考虑以下实例化

例如:

module top ( input a,b, output y,y1);
  assign y = a & b;
  assign y1 = a | b;
endmodule

测试台代码段:

 wire y,y1;

  top u0(.a(a),
         .b(b),
         .y(y),
         .y1(y) // y should be replaced with y1 or else 'X' will be seen in the bus
        );

此处 y 和 y1 连接到 y,通常 wire 的默认值为 "High Impedance(Hi-Z)" 因此 "wire y" 将根据实例化 .y(y) 使用 y 值驱动,但是 y传递给已经驱动其他逻辑输出的 y1 的值会导致矛盾,从而导致 'X'。例如 EDA Playground

在您的代码中,您已将“wire Wd”连接到 d_74151 的测试台实例化中的两个输出 Y、W,这导致了输出中的 'X',这是预期的。要解决在 Y 和 W 的每个端口连接单独的电线。