Piotror
Piotror

Reputation: 115

VHDL: Case Statement choices must cover all possible values of expression

I'm working on project which should convert data from analog to digital with approximation and I have error when i try compile code in Quartus II 9.1sp2 Web Edition which is shown in title with Case Statement in the code below:

architecture behavior of adc is
type state is (reset, state1, state2, state3, state4, state5, state6, state7, state8, state9, state10);
signal nx_state : state;

begin
    process (in_clk, rst_n, start)
begin
    if(rst_n'event and rst_n='0') then
        B_hold <= "1111";
        D_out <= "0000";
        data_out <= "0000";
        hold <= '1';
        sample <= '0';
        eoc <= '0';
        
        if start = '1' then
            nx_state <= state1;
        else
            nx_state <= reset;
        end if;

    elsif(in_clk'event and in_clk='1') then
        case nx_state is
            when state1 => nx_state <= state2;
                B_hold <= "0000";
                hold <= '0';
                sample <= '1';
            
            when state2 => nx_state <= state3;
                B_hold <= "1111";
                D_out <= "0000";
            
            when state3 => nx_state <= state4;
                B_hold(3) <= '0';
                D_out(3) <= '1';
                data_out(3) <= '1';
            
            when state4 => nx_state <= state5;
                if comp_in = '1' then
                    B_hold(3) <= '0';
                    D_out(3) <= '1';
                    data_out(3) <= '1';
                else
                    B_hold(3) <= '1';
                    D_out(3) <= '0';
                    data_out(3) <= '0';
                end if;
            
            when state5 => nx_state <= state6;
                B_hold(2) <= '0';
                D_out(2) <= '1';
                data_out(2) <= '1';
            
            when state6 => nx_state <= state7;
                if comp_in = '1' then
                    B_hold(2) <= '0';
                    D_out(2) <= '1';
                    data_out(2) <= '1';
                else
                    B_hold(2) <= '1';
                    D_out(2) <= '0';
                    data_out(2) <= '0';
                end if;
            
            when state7 => nx_state <= state8;
                B_hold(1) <= '0';
                D_out(1) <= '1';
                data_out(1) <= '1';
            
            when state8 => nx_state <= state9; 
                if comp_in = '1' then
                    B_hold(1) <= '0';
                    D_out(1) <= '1';
                    data_out(1) <= '1';
                else
                    B_hold(1) <= '1';
                    D_out(1) <= '0';
                    data_out(1) <= '0';
                end if;
                
            when state9 => nx_state <= state10; 
                B_hold(0) <= '0';
                D_out(0) <= '1';
                data_out(0) <= '1';
            
            when state10 => nx_state <= reset;
                if comp_in = '1' then
                    B_hold(0) <= '0';
                    D_out(0) <= '1';
                    data_out(0) <= '1';
                else
                    B_hold(0) <= '1';
                    D_out(0) <= '0';
                    data_out(0) <= '0';
                end if;
                eoc <= '1';
        end case;
    end if;
end process;
end behavior;

I'm new newbie at vhdl and I don't know what exactly is wrong with the conditions shown above.

Upvotes: 0

Views: 1338

Answers (2)

Dan
Dan

Reputation: 41

Your type includes a state named reset. You need a when for that state.

case nx_state is
    when reset =>

Upvotes: 3

Jim Lewis
Jim Lewis

Reputation: 3973

Reset is level sensitive. So change

if(rst_n'event and rst_n='0') then

to

if(rst_n='0') then

It is also unusual to have a condition within the reset condition

    if start = '1' then
        nx_state <= state1;
    else
        nx_state <= reset;
    end if;

Hence, you probably just want:

    nx_state <= reset;

Upvotes: 2

Related Questions