--------------------------------------------------------------------------------------------------- -- -- Title : vending_machine -- Design : vending_machine -- Author : Jamie Byun -- Company : JMJS -- --------------------------------------------------------------------------------------------------- -- -- File : vending_machine.vhd -- Generated : Thu Dec 12 10:31:01 2002 -- From : interface description file -- By : Itf2Vhdl ver. 1.20 -- --------------------------------------------------------------------------------------------------- -- -- Description : -- --------------------------------------------------------------------------------------------------- --{{ Section below this comment is automatically maintained -- and may be overwritten --{entity {vending_machine} architecture {JMJS_Logic}} library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; entity vending_machine is port( rst : in STD_LOGIC; clk : in STD_LOGIC; coin_500 : in STD_LOGIC; coin_100 : in STD_LOGIC; coin_50 : in STD_LOGIC; coin_10 : in STD_LOGIC; coffee_button : in STD_LOGIC; tea_button : in STD_LOGIC; orange_button : in STD_LOGIC; change_return : in STD_LOGIC; change : out STD_LOGIC_VECTOR(7 downto 0); coffee_out : out STD_LOGIC; tea_out : out STD_LOGIC; orange_out : out STD_LOGIC ); end vending_machine; architecture JMJS_Logic of vending_machine is type state is (no_return_state, change_return_state); signal pstate : state; signal sum : std_logic_vector(7 downto 0); begin process(clk, rst, change_return, sum) begin if (rst = '1') then pstate <= no_return_state; elsif (clk'event and clk = '1') then case pstate is when no_return_state => if (change_return = '1') then pstate <= change_return_state; end if; when change_return_state => if (sum = "00000000") then pstate <= no_return_state; end if; end case; end if; end process; process (clk) begin if (rst = '1') then sum <= "00000000"; elsif (clk'event and clk = '1') then case pstate is when no_return_state => if (coin_500 = '1') then sum <= sum + 50; elsif (coin_100 = '1') then sum <= sum + 10; elsif (coin_50 = '1') then sum <= sum + 5; elsif (coin_10 = '1') then sum <= sum + 1; elsif (coffee_button = '1' and sum >= 30)then sum <= sum - 30; elsif (tea_button = '1' and sum >= 15) then sum <= sum - 15; elsif (orange_button = '1' and sum >= 10) then sum <= sum - 10; end if; when others => if (sum >= 50) then sum <= sum - 50; elsif (sum >= 10) then sum <= sum - 10; elsif (sum >= 5) then sum <= sum - 5; elsif (sum >= 1) then sum <= sum - 1; end if; end case; end if; end process; process (clk) begin if (rst = '1') then coffee_out <= '0'; elsif (clk'event and clk = '1') then if ((pstate = no_return_state) and (coffee_button = '1') and (sum >= 30)) then coffee_out <= '1'; else coffee_out <= '0'; end if; end if; end process; process (clk) begin if (rst = '1') then tea_out <= '0'; elsif (clk'event and clk = '1') then if ((pstate = no_return_state) and (tea_button = '1') and (sum >= 15)) then tea_out <= '1'; else tea_out <= '0'; end if; end if; end process; process (clk) begin if (rst = '1') then orange_out <= '0'; elsif (clk'event and clk = '1') then if ((pstate = no_return_state) and (orange_button = '1') and (sum >= 10)) then orange_out <= '1'; else orange_out <= '0'; end if; end if; end process; process (clk) begin if (clk'event and clk = '1') then case pstate is when change_return_state => if (sum >= 50) then change <= "00110010"; elsif (sum >= 10) then change <= "00001010"; elsif (sum >= 5) then change <= "00000101"; elsif (sum >= 1) then change <= "00000001"; else change <= "00000000"; end if; when others => change <= "00000000"; end case; end if; end process; end JMJS_Logic;