Case statement choices cover only 6 out of 10 cases for my vending machine code I am getting this error after execution of my very long program in VHDL. However its said that When others => can be used only at the last statement of the code to avoid this particular error however there are many when statements used in the program. How to solve this issue?
library ieee;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
entity FSMM is
port (CLK : in std_logic; --Clock, active high
RSTn : in std_logic; --Async. Reset, active low
CoinIn : in std_logic_vector (1 downto 0); --Which coin was inserted
gum : out std_logic; --Is Soda dispensed ?
CoinOut : out std_logic_vector (1 downto 0) --Which coin is dispensed?
);
end entity;
architecture behavior of FSMM is
-- add your code here
type state_type is (idle, --start state/reset
put_money, --waiting to enter money
in_5c,in_10c,in_15c,in_20c,in_25c,in_30c,in_35c, --represent the current sum of money after returning change
gum_out --dispence soda can.
); --type of state machine.
signal current_s,next_s: state_type; --current and next state declaration.
begin
process(CLK,RSTn)
begin
if(RSTn = '0') then
current_s <= idle; --defualt state is on RESET
elsif(clk'event and clk = '1') then
current_s <= next_s;
end if;
end process;
--------------------
--FSM process:
process(current_s,CoinIn)
begin
case current_s is
when idle => --state reset or idle
gum <= '0';
CoinOut <= "00";
next_s <= put_money;
------------------------------------------------------
when put_money => --wait for money to be entered
if(CoinIn = "00")then
gum <= '0';
CoinOut <= "00";
next_s <= put_money;
elsif(CoinIn = "01")then --insert 5$
gum <= '0';
CoinOut <= "00";
next_s <= in_5c;
elsif(CoinIn = "10")then --insert 10$
gum <= '0';
CoinOut <= "00";
next_s <= in_10c;
elsif(CoinIn = "11")then --insert 25$
gum <= '0';
CoinOut <= "00";
next_s <= in_25c;
end if;
------------------------------------------------------
when in_5c =>
if(CoinIn = "00") then--stay on the same state
gum <= '0';
CoinOut <= "00";
next_s <= in_5c;
elsif(CoinIn = "01") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= in_10c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= in_15c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= in_20c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= in_25c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= in_30c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= in_35c;
elsif(CoinIn = "01") then--inserted another 2$
gum <= '0';
CoinOut <= "00";
next_s <= gum_out;
end if;
------------------------------------------------------
when in_10c =>
if(CoinIn = "00") then--stay on the same state
gum <= '0';
CoinOut <= "00";
next_s <= in_10c;
elsif(CoinIn = "10") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= in_20c;
elsif(CoinIn = "10") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= in_30c;
elsif(CoinIn = "10") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= gum_out;
end if;
------------------------------------------------------
when in_25c =>
if(CoinIn = "00") then--stay on the same state
gum <= '0';
CoinOut <= "00";
next_s <= in_25c;
elsif(CoinIn = "01") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= in_30c;
elsif(CoinIn = "01") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= in_35c;
elsif(CoinIn = "01") then--inserted another 1$
gum <= '0';
CoinOut <= "00";
next_s <= gum_out;
end if;
------------------------------------------------------
when gum_out =>
gum <= '1';
CoinOut <= "00";
next_s <= put_money;
end case;
end process;
end behavior;
Your
state_type
is defined as an enumeration of 10 different values.But your
case
statement covers only 6 of them. According to chapter 10.9 of the standard IEEE Std 1076-2008 you need to cover all cases.This is what the error message tells you.
The solution is to cover all other cases, too, or to insert
when others
to catch these all together.