library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity buzz is port ( clk,reset : in std_logic; engine : in std_logic; seat : in std_logic; belt : in std_logic; buzzer : out std_logic ); end buzz; architecture behavioral of buzz is type stato is (eoff,idle,seated,belted,buzzing); signal cs,ns : stato; signal timeover : std_logic; signal count,ncount : integer range 0 to 20; begin process(clk,reset) begin if reset='1' then count<=0; cs <= idle; elsif clk'event and clk='1' then count <= ncount; cs <= ns; end if; end process; process(ns,engine,seat,belt,timeover) begin case cs is when eoff => if engine='1' then ns <= seated; else ns <= eoff; end if; when idle => if seat='1' then ns <= seated; elsif engine='0' then ns <= eoff; else ns <= idle; end if; when seated => if belt='1' then ns <= belted; elsif seat='0' then ns <= idle; elsif engine='0' then ns <= eoff; elsif timeover='1' then ns <= buzzing; else ns <= seated; end if; when belted => if belt='0' then ns<= seated; elsif seat='0' then ns <= idle; elsif engine='0' then ns <= eoff; else ns <= belted; end if; when buzzing => if belt='1' then ns<= belted; elsif seat='0' then ns <= idle; elsif engine='0' then ns <= eoff; else ns <= buzzing; end if; when others => ns <= idle; end case; end process; Bzz:process(cs) begin if cs=buzzing then buzzer <= '1'; else buzzer <= '0'; end if; end process; Timer:process(cs,count) begin if cs=seated then if count=10 then ncount<=0; timeover<='1'; else ncount<=count+1; timeover<='0'; end if; else ncount<=0; timeover <= '0'; end if; end process; end behavioral;