gpt4 book ai didi

verilog - 将模块输出连接到寄存器

转载 作者:行者123 更新时间:2023-12-02 15:22:51 26 4
gpt4 key购买 nike

我尝试将模块输出连接到寄存器,如下所示:

module test
(
input rst_n,
input clk,
output reg [7:0] count
);
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
count <= 7'h0;
end else begin
if(count == 8) begin
count <= count;
end else begin
count <= count + 1'b1;
end
end
end
endmodule

module test_tb;
reg clk;
reg rst_n;
reg [7:0] counter;

initial begin
clk = 1'b0;
rst_n = 1'b0;
# 10;
rst_n = 1'b1;
end
always begin
#20 clk <= ~clk;
end

test test1 (
.rst_n(rst_n),
.clk(clk),
.count(counter) /* This is the problematic line! */
);
endmodule

我在 ModelSim 中收到错误““port 'count'”的非法输出或输入端口连接”。即使该错误与我的代码匹配,我也不明白为什么从根本上讲,我无法连接模块输出到寄存器。

为什么我无法将模块输出连接到 Verilog 中的寄存器?

最佳答案

您只能为 procedural always block 中的 reg 赋值。您无法从模块实例驱动reg。这将是一个持续的分配。

test_tb内使用wire

关于verilog - 将模块输出连接到寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9974531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com