---------------------------------------------------------------------------------- -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.NUMERIC_STD.ALL; entity VendingMachine is Port ( clk : in STD_LOGIC; LED1 : out STD_LOGIC; LED2 : out STD_LOGIC; Coin : in STD_LOGIC; Cancel : in STD_LOGIC; Prod1 : in STD_LOGIC); end VendingMachine; architecture Behavioral of VendingMachine is signal cntr: integer; signal CLK1sn: STD_LOGIC; type state is (Idle,A,B,C,E); signal prev_state: state :=Idle; signal next_state: state :=Idle; signal LED1x: STD_LOGIC :='0'; signal LED2x: STD_LOGIC :='0'; begin CLKDIV:process(clk,cntr,CLK1sn) is begin if(rising_edge(clk)) then if(cntr=25000000) then cntr <= 0; CLK1sn<=not(CLK1sn); else cntr<=cntr+1; end if; end if; end process; process(prev_state,Coin,Prod1,Cancel,LED1x,LED2x) is begin case prev_state is when Idle => if(Coin='1') then next_state <= A; LED1x <='1'; LED2x<='0'; else next_state <= prev_state; LED1x <='0'; LED2x<='0'; end if; when A => if(Cancel='1') then next_state <= C; LED1x <='0'; LED2x<='0'; elsif(Prod1='1') then next_state <= B; LED1x <='0'; LED2x<='1'; else next_state <= A; LED1x <='1'; LED2x<='0'; end if; when B => next_state <= E; LED1x <='1'; LED2x<='0'; when E => next_state <= Idle; LED1x <='0'; LED2x<='0'; when C => next_state <= Idle; LED1x <='0'; LED2x<='0'; when others => next_state <= prev_state; LED1x <= '0'; LED2x <= '0'; end case; end process; process(CLK1sn,next_state,LED1x,LED2x) is begin if(RISING_EDGE(CLK1sn)) then prev_state <= next_state; LED1 <= LED1x; LED2 <= LED2x; end if; end process; end Behavioral;