问题描述
我收到错误:output or inout port "Qout" must be connected to a structural net expression
.我注释了以下代码中发生错误的那一行(代码被修剪/压缩).我搜索了一个答案,似乎无法将输入/输出端口分配给reg.我认为一种解决方案是将Q更改为导线,但是Q是我的threeBitRegister模块中always块的一部分,因此它必须是reg.我该如何解决这个错误?
I'm getting the error: output or inout port "Qout" must be connected to a structural net expression
. I commented the line the error occured in the below code (code is trimmed/condensed). I searched for an answer and it seems I can't assign a input/output port to a reg. I think one solution is to change Q to a wire, but Q is part of an always-block in my eightBitRegister module, so it must be a reg. How can I get around this error?
`timescale 1ns / 1ns
module lab4_3(SW, KEY, LEDR);
input [9:0] SW;
input [3:0] KEY;
output [7:0] LEDR;
eightBitRegister eight1(
.DATA_IN(SW[7:0]),
.parallelloadn(KEY[1]),
.rotateRight(KEY[2]),
.clock(KEY[0]),
.reset(SW[9]),
.Q(LEDR[7:0])
);
endmodule
module eightBitRegister(DATA_IN, parallelloadn, rotateRight, reset, clock, Q);
input [7:0] DATA_IN;
input parallelloadn;
input rotateRight;
input reset;
input clock;
output[7:0] Q;
register reg0(.Qout(Q[0]), //GETTING ERROR HERE
.right(Q[1]),
.left(Q[7]),
.D(DATA_IN[0]),
.loadleft(rotateRight),
.loadn(parallelloadn),
.clk(clock),
.rst(reset));
reg [7:0] Q;
always @(*)
begin
case({parallelloadn,rotateRight})
2'b00: Q = DATA_IN;
2'b01: Q = DATA_IN;
2'b11: Q = Q >> 1;
2'b10: Q = Q << 1;
endcase
end
endmodule
module register(Qout, right, left, D, loadleft, loadn, clk, rst);
input right, left;
input D;
wire datato_dff, rotatedata;
input loadleft, loadn;
input clk, rst;
output Qout;
flipflop F0(
.d(datato_dff),
.q(Qout),
.clock(clk),
.reset(rst)
);
module flipflop(d, q, reset, clock);
input reset, clock;
input d;
output q;
reg q;
always @(posedge clock)
begin
if (reset == 1'b0)
q <= 0;
else
q <= d;
end
endmodule
推荐答案
首先,在flipflop F0
实例化之后,缺少endmodule
. Verilog不支持嵌套模块(这可能是拼写错误).
First of all, endmodule
is missing after flipflop F0
instantiation. Nested modules are not supported by Verilog (This may be a typo error).
第二,Qout
由多个驱动程序驱动.您已从.Qout(Q[0])
,即从寄存器模块和always
块驱动了Qout
.这是非法的.
Secondly, Qout
is driven by multiple drivers. You have driven Qout
from .Qout(Q[0])
, i.e. from register module, and from always
block. This is illegal.
模块的输出必须连接到wire
.即使Qout
是输出端口,它仍被用作驱动Q
的逻辑的输入.因此,您需要从register
模块中拔出电线,并用它来驱动eightBitRegister
模块的Q
.
The output of module must be connected to a wire
. Even though Qout
is an output port, it is used as an input for your logic to drive Q
. So, you need to take a wire from register
module and use it to drive Q
of eightBitRegister
module.
下图显示了输入,输出和inout端口的端口连接规则.
Following image shows the port connection rules for input,output and inout ports.
我已经修改了您的代码.在这里,使用临时导线作为解决方法.可以在 EDAPlayground 中找到该代码.
I've modified your code, a bit. Here, a temporary wire is used as workaround. The code is available at EDAPlayground.
这篇关于Verilog错误:必须连接到结构网络表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!