为什么 iverilog 抱怨这个 expression/port 宽度?
Why is iverilog complaining about this expression/port width?
当我尝试使用 STRUCTURAL 代码制作 5 位 2x1 MUX 时,我遇到了一个令人困惑的 Verilog 错误,但我似乎找不到任何关于为什么我的代码会显示错误的信息。错误是:
error: Expression width 5 does not match width 1 of logic gate array port 1.
我知道它是在谈论我的输入之一,但我不知道端口 1 中是哪一个。但是根据其余代码的布局方式,我很确定所有5 位宽输入与 5 位线和 5 位输出相匹配。如有任何帮助,我们将不胜感激!
参考这里是我的.v和tb.v
.v:
{模块 mux_2x1_5bit(in1, in2, gate, out);
input [4:0] in1, in2;
input gate;
output [4:0] out;
wire [4:0] a, b;
and #4 and1(a, {5{gate}}, in1);
and #5 and2(b, {5{~gate}}, in2);
or #4 or1(out, a, b);
endmodule
tb.v:
module mux_2x1_5bitTEST();
wire [4:0] out;
reg [4:0] in1;
reg [4:0] in2;
reg gate;
mux_2x1_5bit DUT(in1, in2, gate, out);
initial
begin
in1 = 5'b00000;
in2 = 5'b00010;
gate = 0;
#20 in1 = 5'b00001;
#20 gate = 1;
#20 in2 = 5'b10101;
#20 in1 = 5'b01101;
#20 gate = 0;
end
always @(in1 or in2 or gate)
#1 $display("| gate = %b | in1 = %b | in2 = %b | out = %b |", gate, in1, in2, out);
endmodule
问题出在这里:
and #4 and1(a, {5{gate}}, in1);
and #5 and2(a, {5{~gate}}, in2);
or #4 or1(out, a, b);
and
门的输入和输出只有宽度为1,但在这里你的输入是5。要解决这个问题你可以这样做:
assign a = {5{gate}} & in1;
assign b = {5{~gate}} & in2;
assign out = a | b;
或者,如果您想像这样使用 and
,您可以将输入分隔为 1 个宽度:
and and_a_1(a[0],gate,in2[0]);
and and_a_2(a[1],gate,in2[1]);
...
and and_a_i(a[i],gate,in2[i];
当我尝试使用 STRUCTURAL 代码制作 5 位 2x1 MUX 时,我遇到了一个令人困惑的 Verilog 错误,但我似乎找不到任何关于为什么我的代码会显示错误的信息。错误是:
error: Expression width 5 does not match width 1 of logic gate array port 1.
我知道它是在谈论我的输入之一,但我不知道端口 1 中是哪一个。但是根据其余代码的布局方式,我很确定所有5 位宽输入与 5 位线和 5 位输出相匹配。如有任何帮助,我们将不胜感激!
参考这里是我的.v和tb.v
.v: {模块 mux_2x1_5bit(in1, in2, gate, out);
input [4:0] in1, in2;
input gate;
output [4:0] out;
wire [4:0] a, b;
and #4 and1(a, {5{gate}}, in1);
and #5 and2(b, {5{~gate}}, in2);
or #4 or1(out, a, b);
endmodule
tb.v:
module mux_2x1_5bitTEST();
wire [4:0] out;
reg [4:0] in1;
reg [4:0] in2;
reg gate;
mux_2x1_5bit DUT(in1, in2, gate, out);
initial
begin
in1 = 5'b00000;
in2 = 5'b00010;
gate = 0;
#20 in1 = 5'b00001;
#20 gate = 1;
#20 in2 = 5'b10101;
#20 in1 = 5'b01101;
#20 gate = 0;
end
always @(in1 or in2 or gate)
#1 $display("| gate = %b | in1 = %b | in2 = %b | out = %b |", gate, in1, in2, out);
endmodule
问题出在这里:
and #4 and1(a, {5{gate}}, in1);
and #5 and2(a, {5{~gate}}, in2);
or #4 or1(out, a, b);
and
门的输入和输出只有宽度为1,但在这里你的输入是5。要解决这个问题你可以这样做:
assign a = {5{gate}} & in1;
assign b = {5{~gate}} & in2;
assign out = a | b;
或者,如果您想像这样使用 and
,您可以将输入分隔为 1 个宽度:
and and_a_1(a[0],gate,in2[0]);
and and_a_2(a[1],gate,in2[1]);
...
and and_a_i(a[i],gate,in2[i];