0
\$\begingroup\$

I'm getting an error in Verilog with an input parameter it's not recognized as a legal reg or a variable lvalue. I had the same problem with the output in the module however it was fixed by labeling it as a reg. It's the only error in my code and it occurs only at the input reset variable in the always block.

module lasersystem(input clk, input reset, output reg click
     );

reg [1:0] next_state = 2'b00;
localparam off = 2'b00, start = 2'b01, on = 2'b10;
reg [32:0] counter;


always @ (clk)
begin
case (next_state)

off: if (clk == 0) begin
        next_state = off;
        reset = 1;
        counter = 32'd0;
        click = 0;
        end

      else if (clk == 1) begin
        next_state = start;
        reset = 1;
        counter = 32'd0;
        click = 0;
        end

start: if (clk == 1) begin
          reset = 0;
          click = 0;
          counter = 32'd0;
          next_state = on;
        end

         else begin
          next_state = on;
          reset = 0;
          counter = 32'd0;
          click = 0;
         end

on: if (clk == 1) begin
        reset = 0;
        click = 1;
        if (counter == 32'd249999999) begin
            next_state = off;
        end
        else if (counter != 32'd249999999)
            next_state = on;
    end

default: next_state = off;
endcase
end

always @ (posedge clk) begin
case (reset)
    1: if (next_state == off) while (counter > 32'd0 && counter <     32'd250000000) counter = counter - 32'd1;

    0: if (next_state == on) while (counter > 32'd0 && counter < 32'd250000000) counter = counter + 32'd1;

default: counter = 32'd0;
endcase
end     
endmodule

Why does this happen?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You've labelled reset as input but then you try and assign a value to it (reset = 1). That's what the error is flagging up. \$\endgroup\$
    – awjlogan
    Mar 5, 2019 at 22:21

1 Answer 1

0
\$\begingroup\$

If your state machine needs to set reset, then you need to specify it as an output reg reset of your module. Outputs default to nets unless you add a data type like reg. Then they are treated like variable that can be procedurally assigned from your `always1 block.

\$\endgroup\$
2
  • \$\begingroup\$ I have never considered the reset reg or wire as an ouput. Most of the time I see in class the reset is used as an input, but I'll configure the code later and see if that worked. \$\endgroup\$
    – user548010
    Mar 5, 2019 at 23:11
  • 1
    \$\begingroup\$ @user548010, If it's not an output, then why is your code setting it to a specific value? (I'm mainly asking because maybe I haven't understood what the code is actually supposed to do) \$\endgroup\$
    – The Photon
    Mar 6, 2019 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.