Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: (vlog-2110) Illegal reference to net "code"

I have tried this code, but it shows the error:

gray_counter\gray_counter.v(2): (vlog-2110) Illegal reference to net "code"

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
like image 723
kaviyarasu s Avatar asked Mar 06 '26 02:03

kaviyarasu s


1 Answers

It is illegal to assign a value to an input port within a module. Change:

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

to:

 input [2:0]code;

You may only drive values from outside the module, for example, in a testbench module.

Some simulators will give you more specific help. I see this with VCS:

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

You can try your code on multiple simulators if you sign up for a free account on edaplayground.

like image 96
toolic Avatar answered Mar 07 '26 22:03

toolic