library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; use IEEE.std_logic_signed.all; entity controllore is port(clk : in std_logic; reset : in std_logic; start : in std_logic; -- cameras interface alfa : out unsigned(4 downto 0); beta : out unsigned(4 downto 0); alarm1 : in std_logic; alarm2 : in std_logic; -- control panel interface alarm : out std_logic; camera : out std_logic; angle : out unsigned(4 downto 0); code : in unsigned(5 downto 0) ); end controllore; architecture Esame of controllore is type stato is (idle,conta1,conta2,scatta1,scatta2); signal cs, ns : stato; signal enable,scatta,avanti,trentasecondi, finecorsa1, finecorsa2 : std_logic; signal count, next_count : unsigned(18 downto 0); signal angleint, next_angleint : unsigned(4 downto 0); signal alarm_active, next_alarm_active : std_logic; signal alarm_camera, next_alarm_camera : std_logic; signal angle_camera, next_angle_camera : unsigned(4 downto 0); signal ripristina : std_logic; begin -- GESTIONE TELECAMERE process(clk) -- contatore 30 sec per T1 => con Tck=0.1 ms => N=19 bit begin if clk'event and clk='1' then if reset='1' or trentasecondi='1' then count <= (others => '0'); elsif enable='1' then count <= next_count; end if; end if; end process; next_count <= count + conv_unsigned(1,19); trentasecondi <= '1' when count = conv_unsigned(3,19) else '0'; -- nella realtà: trentasecondi <= '1' when valore_temp = conv_unsigned(299999,19) else '0'; process(clk,reset) begin if reset='1' then angleint <= (others => '0'); else if clk'event and clk='1' then angleint <= next_angleint; end if; end if; end process; process(avanti,scatta,angleint) begin if scatta ='0' then next_angleint <= angleint; else if avanti='1' then next_angleint <= angleint + conv_unsigned(1,5); else next_angleint <= angleint - conv_unsigned(1,5); end if; end if; end process; finecorsa1 <= '1' when angleint = conv_unsigned(6,5) else '0'; finecorsa2 <= '1' when angleint = conv_unsigned(1,5) else '0'; --finecorsa1 <= '1' when angleint = conv_unsigned(26,5) else '0'; process(clk) -- parte sequenziale della FSM per T1 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, start,finecorsa1,finecorsa2,trentasecondi,alarm1,alarm2) -- parte combinatoria della FSM_A begin case cs is when idle => enable <= '0'; scatta <= '0'; avanti <= '0'; if start='1' then ns <= conta1; else ns <= cs; end if; when conta1 => enable <= '1'; scatta <= '0'; avanti <= '1'; if trentasecondi='1' then ns <= scatta1; else ns <= cs; end if; when scatta1 => enable <= '1'; scatta <= '1'; avanti <= '1'; if finecorsa1 ='1' then ns <= conta2; else ns <= conta1; end if; when conta2 => enable <= '1'; scatta <= '0'; avanti <= '0'; if trentasecondi='1' then ns <= scatta2; else ns <= cs; end if; when scatta2 => enable <= '1'; scatta <= '1'; avanti <= '0'; if finecorsa2 ='1' then ns <= conta1; else ns <= conta2; end if; when others => ns <= idle; end case; end process; alfa <= angleint; beta <= angleint; -- GESTIONE ALLARME process(clk,reset,ripristina) begin if reset='1' or ripristina ='1' then alarm_active <= '0'; else if clk'event and clk='1' then alarm_active <= next_alarm_active; end if; end if; end process; next_alarm_active <= '1' when alarm1='1' or alarm2='1' else alarm_active; process(clk,reset,ripristina) begin if reset='1' or ripristina ='1' then alarm_camera <= '0'; else if clk'event and clk='1' then alarm_camera <= next_alarm_camera; end if; end if; end process; next_alarm_camera <= '1' when alarm2 = '1' else alarm_camera; process(clk,reset,ripristina) begin if reset='1' or ripristina ='1' then angle_camera <= (others => '0'); else if clk'event and clk='1' then angle_camera <= next_angle_camera; end if; end if; end process; next_angle_camera <= angleint when alarm1 = '1'or alarm2='1' else angle_camera; ripristina <= '1' when code = conv_unsigned(42,6) else '0'; alarm <= alarm_active; camera <= alarm_camera; angle <= angle_camera; end ESAME;