--Shane and Ben --PC300/319 combined project --Control unit for a parking lot management system library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity carlot is port(carin,carout,clk,reset :in std_logic; --inputs from system full, gatein, gateout :out std_logic; --outputs to system count :out std_logic_vector(6 downto 0));--7 segment display end carlot; architecture manager of carlot is signal gatetempin,gatetempout :std_logic; --temporary variables to tell if gate is open signal timein,timeout :std_logic_vector(3 downto 0); --timing variables signal statechange,statechange2 :std_logic; --changestates signal state :std_logic_vector(3 downto 0); --current state in binary begin controlgatein: gatetempin<= (timein(0) or timein(1) or timein(2) or timein(3)); --controls the in gate controlgateout: gatetempout<=(timeout(0) or timeout(1) or timeout(2) or timeout(3)); --controls the out gate statein: statechange<= not state(3) and carin and not gatetempin; --controls state change in stateout: statechange2<=carout and not gatetempout and (state(0) or state(1) or state(2) or state(3)); --controls state change out controlcount0: count(0)<=not((state(0) and not state(1) and not state(2) and not state(3)) or (not state(0) and not state(1) and state(2) and not state(3)) or (state(0) and state(1) and state(2) and not state(3))); --change the value of state to output to 7 segment display controlcount1: count(1)<=not(not state(0) and state(1) and not state(2)); controlcount2: count(2)<=not ((state(0)) or (not state(0) and not state(1) and state(2) and not state(3))); controlcount3: count(3)<=not((not state(0)and not state(1) and not state(2) and not state(3)) or (state(0) and not state(1) and not state(2) and not state(3)) or (state(0) and state(1) and state(2) and not state(3))); controlcount4: count(4)<=not((state(0) and not state(1) and state(2) and not state(3)) or (not state(0) and state(1) and state(2) and not state(3))); controlcount5: count(5)<= (not state(0) and not state(1) and not state(2)) or (not state(0) and not state(1) and state(2) and not state(3)) or (state(0) and not state(1) and state(2) and not state(3)) or (not state(0) and state(1) and state(2) and not state(3)); controlcount6: count(6)<=not((state(0) and not state(1) and not state(2) and not state(3)) or (not state(0) and not state(1) and state(2) and not state(3))); controlfull: Full<=state(3); --controls full lot light process(clk) begin if clk'Event and clk='1' then --if timer --side program if reset='1' then --reset parking lot state<="0000"; gatein<='0'; --turn off gates program gateout<='0'; timein<="0000"; timeout<="0000"; elsif statechange='1' then --does not deal with two state changes at once state<=state+'1'; --this is the car in case gatein<='1'; timein<="0001"; if timeout >"0000" and timeout <"1000" then --continue to count time out timeout<=timeout+'1'; gateout<='1'; else timeout<="0000"; gateout<='0'; end if; elsif statechange2='1' then --car out case state<=state - '1'; gateout<='1'; timeout<= "0001"; if timein>"0000" and timein <"1000" then --continue to count time in timein<=timein + '1'; gatein<='1'; else timein<="0000"; gatein<='0'; end if; else --if not state change if timein>"0000" and timein <"1000" then --if timein is counting timein<=timein + '1'; --gate is open gatein<='1'; else timein<="0000"; --reset timein if not counting or count is done gatein<='0'; end if; if timeout >"0000" and timeout <"1000" then --same as above but with timeout timeout<=timeout+'1'; gateout<='1'; else timeout<="0000"; gateout<='0'; end if; end if; end if; end process; end manager; --end program.