library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity controllore is port ( CLK : in std_logic; RESET : in std_logic; --interfaccia citofono APRIPORTA : in std_logic; CITOFONO : in std_logic; --interfaccia porta CAMPANELLO : in std_logic; APRI : out std_logic; --interfaccia modulo GSM START : out std_logic; CIFRA : out unsigned(3 downto 0); CHIAMATA : out std_logic; CONNESSIONE : in std_logic); end controllore; architecture esame of CONTROLLORE is type stato is(idle,c60,c5,open_door,gsm,attesa,telefonata,primo,secondo,terzo,quarto); signal cs,ns: stato; signal s60,enable60 : std_logic; signal count60,next_count60 : unsigned(15 downto 0); signal s5,enable5 : std_logic; signal count5,next_count5 : unsigned(12 downto 0); signal unlock_door : std_logic; begin -- parte sequenziale della FSM process(clk) begin if clk'event and clk='1' then if reset='1' then cs <= idle; else cs <= ns; end if; end if; end process; process(cs,APRIPORTA,CAMPANELLO, S60, CITOFONO, S5,CONNESSIONE) begin ns <= cs; enable60 <= '0'; enable5 <= '0'; unlock_door <= '0'; chiamata <='0'; start <='0'; cifra <="0000"; case cs is when idle=> if CAMPANELLO = '1' then ns <= C60; else ns <= cs; end if; when c60 => enable60 <='1'; if CITOFONO = '0' then ns <= c5; elsif s60 = '1' then ns <= gsm; else ns <= cs; end if; when c5 => enable5 <= '1'; if CITOFONO = '1' then ns <= idle; elsif s5 = '1' then ns <= open_door; else ns <= cs; end if; when open_door => unlock_door <= '1'; if CITOFONO = '1' then ns <= idle; else ns <= cs; end if; when gsm => start <= '1'; ns <= primo; when primo => start <='0'; cifra <="0001"; ns <=secondo; when secondo => cifra <="0011"; ns<=terzo; when terzo => cifra <="0111"; ns<=quarto; when quarto=> cifra <="0011"; ns<=attesa; when attesa => CHIAMATA <='1'; if connessione ='0' then ns <=cs; else ns <=telefonata; end if; when telefonata => CHIAMATA <='1'; if connessione ='0' then ns <=idle; else ns<=cs; end if; when others => ns <= idle; end case; end process; process(clk) begin if clk'event and clk='1' then if reset='1' then count60 <= (others => '0'); elsif enable60 = '1' then count60 <= next_count60; end if; end if; end process; next_count60 <= count60 + conv_unsigned(1,16); --s60 <='1' when count60 =conv_unsigned(60000,16) else '0'; s60 <='1' when count60 =conv_unsigned(6,16) else '0'; process(clk) begin if clk'event and clk='1' then if reset='1' then count5 <= (others => '0'); elsif enable5 = '1' then count5 <= next_count5; end if; end if; end process; next_count5 <= count5 + conv_unsigned(1,13); --s5 <='1' when count5 =conv_unsigned(5000,13) else '0'; s5 <='1' when count5 =conv_unsigned(5,13) else '0'; APRI <= unlock_door and APRIPORTA; end esame;