Hi,
I am trying to impelement vending machine with Moore output logic. My machine has coin input and I have these states;
Idle, AcceptMoney, Calculate, Ready.
Machine starts at idle state. If someone has pressed to request button, machine jumps to AcceptMoney state. In this state, if someone press coin button, my coin should be increment by one but, it behaves strange, increases too much.
my code is like these:
signal MyMoney : unsigned (3 downto 0) := x"0";
signal MyPrize : std_logic_vector (3 downto 0) := x"0";
begin
-- my state machine!!
process(clk, reset)
begin
if(reset = '1') then
state_reg <= idle;
elsif(clk'event and clk = '1') then
state_reg <= state_next;
end if;
end process;
--my FSM
process(state_reg, one_tl, request, MyMoney)
begin
case state_reg is
when idle =>
digit2 <= "0000";
ready <= '0';
if(request = '1') then
state_next <= acceptMoney;
end if;
when acceptMoney =>
digit2 <= "0001";
ready <= '0';
if(one_tl = '1') then
state_next <= calculate;
end if;
when calculate =>
digit2 <= "0010";
ready <= '0';
if(MyMoney = unsigned(MyPrize)) then
state_next <= myReady;
else
state_next <= acceptMoney;
end if;
when myReady =>
digit2 <= "0011";
ready <= '1';
if(take_item = '1') then
state_next <= idle;
end if;
end case;
end process;
digit1 <= std_logic_vector(MyMoney);
MyPrize <= "0001" when(item_select = "00") else
"0010" when(item_select = "01") else
"0011" when(item_select = "10") else
"0100" when(item_select = "11");