Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- entity LIFT is
- port(
- iOUT: in std_logic_vector(3 downto 0) := (others => '0'); --outside input
- iIN: in std_logic_vector(3 downto 0) := (others => '0'); --inside elevator car input
- DIR: in std_logic; --FPGA button to switch for outside input (if you either want to go up/down)
- -- 0 down, 1 up
- FLOOR: out std_logic_vector(6 downto 0) :="1111110";
- an: out std_logic_vector(3 downto 0):="1110"; --output lcd
- DOOR: out std_logic := '1'; --output door
- WEIGHT: in std_logic;
- DOOR_SENSOR: in std_logic := '0';
- CLK: in std_logic);
- end LIFT;
- architecture behavioral of LIFT is
- type lift_states is (initial, waiting, check, openDoor, closeDoor, move); --states that the elevator has
- signal curr_state : lift_states;
- signal next_state : lift_states;
- signal INTERIOR : std_logic_vector (13 downto 0) := (others => '0'); -- interior commands
- signal UP : std_logic_vector (13 downto 0) := (others => '0'); -- exterior commands for going up
- signal DOWN : std_logic_vector (13 downto 0) := (others => '0'); -- exterior commands for going down
- signal empty : std_logic_vector (13 downto 0) := (others => '0'); -- empty vector used for comparison
- signal iempty : std_logic_vector (3 downto 0) := (others => '0'); -- empty vector used for input comparison
- signal position : integer := 0; --lift's floor
- signal direction : std_logic := '1'; --direction, up = 1 / down = 0;
- signal GOu, GOd : std_logic; -- checks if there are commands lower/higher relative to position
- signal i,k : natural; -- used to determine commands relative to position
- signal counter : natural;
- signal freq : std_logic := '0';
- begin
- proccy: process(CLK)
- begin
- curr_state <= next_state;
- end process proccy;
- commands: process(CLK)
- begin
- if(iIN /= iempty) then
- INTERIOR(to_integer(unsigned(iIN)))<='1';
- end if;
- if(iOUT /= iempty) then
- if( DIR = '1') then
- UP(to_integer(unsigned(iOUT))) <= '1';
- end if;
- if( DIR = '0') then
- DOWN(to_integer(unsigned(iOUT))) <= '1';
- end if;
- end if;
- INTERIOR(position)<='0';
- UP(position)<='0';
- DOWN(position)<='0';
- end process commands;
- states_lift: process(clk)
- begin
- case curr_state is
- when initial => position <= 1; --initialize everything
- -- +door sensor, weight sensor;
- next_state <= waiting;
- --waiting for stuff
- when waiting => if (UP /= empty or DOWN /= empty or INTERIOR /= empty) then
- next_state <= check;
- end if;
- --rough w8ing process
- when check => GOu <= '0';
- GOd <= '0';
- if(WEIGHT /= '1') then
- if (UP /= empty) then
- next_state <= move;
- end if;
- if (DOWN /= empty) then
- next_state <= move;
- end if;
- if (INTERIOR /= empty) then
- next_state <= move;
- end if;
- end if;
- if(UP(position) = '1' or DOWN(position) = '1' or INTERIOR(position) = '1') then
- next_state <= openDoor;
- end if;
- --the checking state
- when move => if(direction = '1') then
- if(i < 14 and GOu /= '1' and GOd /='1') then
- if(i > position) then
- if(UP(i) = '1' or INTERIOR(i) = '1') then
- GOu <= '1';
- else
- i <= i + 1;
- end if;
- else
- if(UP(i) = '1' or DOWN(i) = '1' or INTERIOR(i) = '1') then
- GOd <= '1';
- else
- i <= i + 1;
- end if;
- end if;
- else if(GOu = '1') then
- if(UP(position) = '1' or INTERIOR(position) = '1') then
- next_state <= openDoor;
- else if(next_state /= openDoor) then
- position <= position + 1;
- end if;
- end if;
- else if(GOd = '1') then
- if(UP(position) = '1' or INTERIOR(position) = '1' or DOWN(position) = '1') then
- next_state <= openDoor;
- else if(next_state /= openDoor) then
- position <= position - 1;
- end if;
- end if;
- else
- direction <= '0';
- i <= 13;
- end if;
- end if;
- end if;
- else
- if(i > 0 and GOd /= '1' and GOu /= '1') then
- if(i < position) then
- if(DOWN(i) = '1' or INTERIOR(i) = '1') then
- GOd <= '1';
- else
- i <= i - 1;
- end if;
- else
- if(DOWN(i) = '1' or INTERIOR(i) = '1') then
- GOu <= '1';
- else
- i <= i - 1;
- end if;
- end if;
- else
- if(GOd = '1') then
- if(DOWN(position) = '1' or INTERIOR(position) = '1') then
- next_state <= openDoor;
- else if(next_state /= openDoor) then
- position <= position - 1;
- end if;
- end if;
- else if(GOu = '1') then
- if(DOWN(position) = '1' or INTERIOR(position) = '1') then
- next_state <= openDoor;
- else if(next_state /= openDoor) then
- position <= position + 1;
- end if;
- end if;
- else
- direction <= '1';
- end if;
- end if;
- end if;
- end if;
- when openDoor => --opens door, checks sensor for weight, waits a period of time
- DOOR <= '1';
- next_state <= closeDoor;
- when closeDoor => --closes door
- DOOR <= '0';
- next_state <= waiting;
- end case;
- end process states_lift;
- display: process(freq)
- begin
- case position is
- when 1 => floor <= "1111110";
- when 2 => floor <= "0110000";
- when 3 => floor <= "1101101";
- when 4 => floor <= "1111001";
- when 5 => floor <= "0110011";
- when 6 => floor <= "1011011";
- when 7 => floor <= "1011111";
- when 8 => floor <= "1110000";
- when 9 => floor <= "1111111";
- when 10 => floor <= "1111011";
- when 11 => floor <= "1110111";--a
- when 12 => floor <= "0011111";--b
- when 13 => floor <= "1001110";--c
- when others => floor <= "1111111";
- end case;
- end process display;
- frequency: process(clk)
- begin
- if(k = 200) then
- k <= 0;
- freq <= not freq;
- else
- k <= k + 1;
- end if;
- end process frequency;
- end architecture behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement