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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With