Search code examples
verilogfpgaxilinx-ise

Why wont Xilinx ISE accept this statement in a state machine?


So i am currently doing a little project involving a hd44780 display. But since i want to write my own init sequence i decided to use a state machine. I am quite new to FPGAs an their programming coming from a Java background.

This is my State machine Block.

I this state it works and the IDE doesnt show any errors.

    always @(posedge reset)
    begin
    en_timeout <= 2'b00;
    timeout <= 14'b00000000000000;
    init <= 4'b000;
    data <= 8'b00000000;
    en <= 1'b1; //active low
    rs <= 1'b0;
    rw <= 1'b0;
    state <= 4'b0000;
    next_state <= 4'b0000;

    debug <= 1'b0;
    end

if(timeout == 0)
    begin //Begin of Initiation state machine
        case(state)
            s0:
                begin
                end

            s1:
                begin
                end
            s2:
                begin
                end
            s3:
                begin
                end
            s4:
                begin
                end
            s5:
                begin
                end
            s6:
                begin
                end
            s7:
                begin
                end
            s8:
                begin
                end
            s9:
                begin
                end
            s10:
                begin
                end
            normal:
                begin
                end
        endcase
    end //End of Initiation state machine

But if i add any assignment between the begin and end of one of the states it shows me "Line n: Syntax error near "<="."

for example:

            case(state)
            s0:
                begin
                state <= s1;
                end

Full code of my DisplayDriver so far:

    module DisplayDriver(
    output reg [8:0] data,
     output reg en,
    output reg rs,
    output reg rw,
     output reg debug,
     input clk,
     input reset
    );

     parameter s0=0,s1=1,s2=2,s3=3,s4=4,s5=5,s6=6,s7=7,s8=8,s9=9,s10=10,normal = 11;

     reg [3:0] state; // 4 bit for max 11 combinations s0-s10 and normal
     reg [3:0] state; // 4 bit for max 11 combinations s0-s10 and normal [next State]
     reg [1:0] en_timeout; // 2 bit for en high to low to high cylce
     reg [13:0] timeout; // 14 bit 

    initial 
    // begin init
        begin
        en_timeout <= 2'b00;
        timeout <= 14'b00000000000000;
        init <= 4'b000;
        data <= 8'b00000000;
        en <= 1'b1; //active low
        rs <= 1'b0;
        rw <= 1'b0;
        state <= 4'b0000;
        next_state <= 4'b0000;

        debug <= 1'b0;
        end
     // end of init

    always @(posedge clk)
    //begin of everything that needs the clock
    begin
        if(en_timeout > 0) //begin timeout stack
            begin
            en_timeout <= en_timeout -1;
            en <= ~en;// if en_timeout = 2 -> en = 0; if en_timeout = 1 -> en = 1;
            end
        else if (timeout > 0) timeout <= timeout -1; //end timeout stack

        if(timeout == 0)state <= next_state;
    end //end of everything that needs the clock


    always @(posedge reset)
        begin
        en_timeout <= 2'b00;
        timeout <= 14'b00000000000000;
        init <= 4'b000;
        data <= 8'b00000000;
        en <= 1'b1; //active low
        rs <= 1'b0;
        rw <= 1'b0;
        state <= 4'b0000;
        next_state <= 4'b0000;

        debug <= 1'b0;
        end

    if(timeout == 0)
        begin //Begin of Initiation state machine
            case(state)
                s0:
                    begin
                    end

                s1:
                    begin
                    end
                s2:
                    begin
                    end
                s3:
                    begin
                    end
                s4:
                    begin
                    end
                s5:
                    begin
                    end
                s6:
                    begin
                    end
                s7:
                    begin
                    end
                s8:
                    begin
                    end
                s9:
                    begin
                    end
                s10:
                    begin
                    end
                normal:
                    begin
                    end
            endcase
        end //End of Initiation state machine
endmodule

Does anyone have an idea why it behaves this way?


Solution

  • I assume that you are trying to synthesize a register for "state", in which case the update "<=" needs to be inside always (@posedge clk).