设计
//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位多路复用器/选择器的结构和数据流描述,包括使能。
答案 0 :(得分:0)
您的d7
个实例正在使用2个输出端口Wd
和Y
驱动相同的线路(W
)。 Yd
电线未被驱动。要摆脱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));
使用允许跟踪信号到波形的调试工具来调试这些错误更容易。
答案 1 :(得分:0)
变量不能包含多个连续驱动程序。调试这些更好的使用基于波形的方法
例如,考虑以下实例化
例如:
module top ( input a,b, output y,y1);
assign y = a & b;
assign y1 = a | b;
endmodule
testbench代码段:
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值驱动,但当传递给已经驱动某些其他逻辑输出的y1时,该y值会导致矛盾,从而导致X'。例如EDA Playground
在您的代码中,您已连接" wire Wd
"在d_74151的测试平台实例化中输出Y,W,导致' X'在输出中如预期的那样。解决在Y和W的每个端口连接单独的电线。