library IEEE; use IEEE.std_logic_1164.all; --use work.password_package.all; use work.delay_package.all; entity mainLogic is port ( pass_stat : in std_logic; --password status, 0 incorrect pass or pass not entered, 1 valid pass clk : in std_logic; reset_ext : in std_logic; sensors : in std_logic_vector(3 downto 0); arm : in std_logic; disarm : in std_logic; reset_pass : out std_logic; --signal to reset pass to idle state armed : out std_logic; disarmed : out std_logic; alarm_trip : out std_logic; delay_lgt : out std_logic; sensor_disp : out std_logic_vector(3 downto 0); alarm : out std_logic ); end mainLogic; architecture behaviour of mainLogic is signal system_status : std_logic_vector(2 downto 0); --000 disarmed --001 delay arm --010 armed --011 delay alarm --100 alarmed signal reset_int : std_logic; --internal reset signal reset_delay : std_logic; --signal to reset delay signal delay_status : std_logic; --status of delay: 0 inactive or waiting, 1 delay over; signal activate_delay : std_logic; --signal to start delay signal sensor_trip : std_logic; begin DEL: delay port map(clk, activate_delay, reset_delay, delay_status); process (clk) begin if clk'EVENT and clk='1' then if reset_int='1' or reset_ext='1' then system_status<="000"; --reset system --reset all outputs to disarmed state alarm<='0'; disarmed<='1'; armed<='0'; sensor_disp(3 downto 0)<="0000"; delay_lgt<='0'; activate_delay<='0'; reset_delay<='1'; reset_int<='0'; reset_pass<='1'; alarm_trip<='0'; sensor_trip<='0'; else reset_pass<='0'; reset_delay<='0'; --go to delay arm state if system_status="000" and pass_stat='1' and arm='1' and delay_status='0' then activate_delay<='1'; --start external delay counter system_status<="001"; --system in delay arm state delay_lgt<='1'; --end if; --go to armed state elsif system_status="001" and delay_status='1' and sensors(3 downto 0)="0000" then reset_delay<='1'; system_status<="010"; --system armed armed<='1'; delay_lgt<='0'; activate_delay<='0'; disarmed<='0'; reset_pass<='1'; --end if; --go to delay alarm state elsif system_status="010" and (sensors(0)='1' or sensors(1)='1' or sensors(2)='1' or sensors(3)='1') and delay_status='0' then --activate sensor lights if sensors(0)='1' then sensor_disp(0)<='1'; end if; if sensors(1)='1' then sensor_disp(1)<='1'; end if; if sensors(2)='1' then sensor_disp(2)<='1'; end if; if sensors(3)='1' then sensor_disp(3)<='1'; end if; activate_delay<='1'; system_status<="011"; --delay alarm state delay_lgt<='1'; sensor_trip<='1'; --end if; --go to alarmed state elsif system_status="011" and delay_status='1' and sensor_trip ='1' then system_status<="100"; --in alarmed state alarm<='1'; reset_delay<='1'; alarm_trip<='1'; activate_delay<='0'; delay_lgt<='0'; sensor_trip<='0'; end if; if pass_stat='1' and disarm='1' then reset_int<='1'; end if; end if; end if; end process; end behaviour;