首页 > 解决方案 > 错误:(vlog-2110)非法引用网络“代码”

问题描述

我试过这段代码,但它显示错误:

gray_counter\gray_counter.v(2): (vlog-2110) 非法引用网络“代码”

module gray_counter(code,clk,rst,count);//module declaration
 input [2:0]code=3'b000;
 input clk,rst;
 output reg count;
 reg [2:0]conv_code;
always@(posedge clk , posedge rst)
 begin
if(rst)
 begin
 count=0;
 end
 else
 begin
 conv_code={code[0],code[0]^code[1],code[1]^code[2]};//converting binary code to gray 
 case(conv_code)
 3'b000:count=count+1;
 3'b001:count=count+1;
 3'b011:count=count+1;
 3'b010:count=count+1;
 3'b110:count=count+1;
 3'b100:count=count+1;
 3'b101:count=count+1;
 3'b111:count=count+1;
 default:count=count+0;
 endcase
 end
 end
endmodule

标签: verilogsystem-verilogvlsi

解决方案


input给模块内的端口赋值是非法的。改变:

 input [2:0]code=3'b000;

至:

 input [2:0]code;

您只能从模块外部驱动值,例如,在测试平台模块中。

一些模拟器会给你更具体的帮助。我在 VCS 中看到了这一点:

Error-[V2KIIAD] Invalid initialization at declaration
  Source info:  input [2:0]code=3'b000;
  Non-output port 'code' cannot be initialized at declaration.

如果您在 edaplayground 上注册一个免费帐户,您可以在多个模拟器上试用您的代码。


推荐阅读