---------------------------------------------------------------------------------- -- Engineer: Benjamin Yee amd Hasham Ali -- -- Create Date: 11/29/2015 07:15:11 PM -- Design Name: -- Module Name: Source - Behavioral -- Project Name: Tally Counter -- Target Devices: -- Tool Versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx leaf cells in this code. --library UNISIM; --use UNISIM.VComponents.all; entity FSM is Port ( PressureA : in STD_LOGIC; PressureB : in STD_LOGIC; clk : in STD_LOGIC; Clear : in STD_LOGIC; Binary_state : out STD_LOGIC_vector(1 downto 0); Sequence : out STD_LOGIC); end FSM; architecture Behavioral of FSM is type state is (ST0,ST1,ST2,ST3); signal PS,NS : state; begin Clear_process: process (clk,NS,Clear) --Clear button begin if (Clear = '1') then PS <= ST0; elsif (rising_edge(clk)) then PS <= NS; end if; end process Clear_process; Proc2: process (PS,PressureA,PressureB) begin case PS is when ST0 => Sequence <= '0'; if (PressureA = '1') then NS <= ST1; --when the person enters the doorway and steps on the first else NS <= ST0; --stay ST0 if no one comes through the door end if; when ST1 => Sequence <= '0'; if (PressureB = '1' and PressureA = '0') then NS <= ST2; --The person steps off the first pressure pad else NS <= ST1; --stay ST1 if the person does not move on end if; when ST2 => Sequence <= '1'; --sends out enable signal after the completion of sequence NS <= ST3; when ST3 => Sequence <= '0'; if(PressureA = '0' and PressureB = '0') then NS <= ST0; --Goes back ST0 for the cycle to happen again else NS <= ST3; end if; when others => NS <= ST0; Sequence <= '0'; end case; end process Proc2; with PS select Binary_state <= "01" when ST0, --LED encoding "10" when ST1, "11" when ST2, "00" when others; end Behavioral;