Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4.  
  5. entity elevator_controller is
  6. port ( clk : IN std_logic;
  7. reset : in std_logic;
  8. new_call : in std_logic;
  9. at_call : in std_logic;
  10. -- call_above : inout std_logic;
  11. -- call_below : inout std_logic;
  12. -- timer_accel : inout std_logic;
  13. -- near_call : inout std_logic;
  14. hold_button : in std_logic;
  15. open_button : in std_logic;
  16. close_button : in std_logic;
  17. -- timer_door : inout std_logic;
  18. direction_up : inout std_logic;
  19. direction_down : inout std_logic;
  20.  
  21. reset_timer : out std_logic;
  22. accel : out std_logic;
  23. hold : inout std_logic; -- means the elevator is moving vertically
  24. remove_call : out std_logic);
  25.  
  26. -- elevator_location : out integer;
  27. -- start : in integer);
  28.  
  29. end entity;
  30.  
  31.  
  32.  
  33.  
  34. architecture behav of elevator_controller is
  35. type state_type is (s0,s1,s2,s3,s4,s5,s6,s7);
  36. signal state: state_type;
  37. signal location : integer range 0 to 200;
  38. signal request_floor : integer range 0 to 100;
  39. signal floor_sensors : integer range 0 to 300;
  40. signal timer_accel, timer_door, call_above, call_below, near_call, at_landing, brake, open_door, door_closed : std_logic:='0';-- stopping/starting movement signals to output to corresponding ports
  41. begin
  42.  
  43.  
  44.  
  45. process (clk,reset)
  46.  
  47. begin
  48.  
  49.  
  50.  
  51. --group controller
  52.  
  53.  
  54.  
  55.  
  56. -- timers
  57. if (clk='1' and clk'event and timer_accel='0')
  58. then timer_accel <= '1';
  59. end if;
  60. if (clk='1' and clk'event and timer_door='0')
  61. then timer_door <= '1';
  62. door_closed <= '1';
  63. end if;
  64.  
  65.  
  66.  
  67. -- moving the elevator
  68. if (clk='1' and clk'event and direction_up='1' and hold='1' and (floor_sensors mod 2 = 0) and brake='0')
  69. then location <= location+1;
  70. elsif(clk='1' and clk'event and direction_down='1' and hold='1' and (floor_sensors mod 2 = 0) and brake='0')
  71. then location <= location-1;
  72. end if;
  73.  
  74.  
  75. -- sensors
  76. if (clk='1' and clk'event and direction_up='1' and brake='0')
  77. then floor_sensors <= floor_sensors + 1;
  78. end if;
  79. if (clk='1' and clk'event and direction_down='1' and brake='0')
  80. then floor_sensors <= floor_sensors - 1;
  81. end if;
  82.  
  83. -- call conditions for stopping/starting movement to destination
  84. if (clk='1' and clk'event and new_call = '1' and location > request_floor - 1)
  85. then call_below <= '1';
  86. elsif (clk='1' and clk'event and new_call = '1' and location = request_floor - 1)
  87. then near_call <= '1';
  88. if (floor_sensors mod 2 = 0)
  89. then at_landing <= '1';
  90. end if;
  91. elsif (clk='1' and clk'event and new_call = '1' and location < request_floor - 1)
  92. then call_above <= '1';
  93. end if;
  94.  
  95.  
  96. if (reset ='1') then
  97. state <=s0;
  98. elsif (clk='1' and clk'event) then
  99. case state is
  100. when s0 => -- idle
  101. reset_timer <= '0';
  102. accel <= '0';
  103. hold <= '0';
  104. brake <= '1';
  105. open_door <= '0';
  106. remove_call <= '0';
  107. direction_up <= '0';
  108. direction_down <= '0';
  109. if (new_call='1' and at_call='0' and call_above='1')
  110. then state <= s1; -- set dir up
  111. elsif (new_call='1' and at_call='0' and call_below='1')
  112. then state <= s2; -- set dir down
  113. elsif ((new_call='1' and at_call='1') or open_button='1')
  114. then state <= s6; -- open door
  115. end if;
  116. when s1 => -- set dir up
  117. direction_up <= '1';
  118. reset_timer <= '1';
  119. state <= s3; -- accel
  120. timer_accel <='0';
  121. when s2 => -- set dir down
  122. direction_down <= '1';
  123. reset_timer <= '1';
  124. state <= s3; -- accel
  125. timer_accel <='0';
  126. when s3 => -- accel
  127. brake <= '0';
  128. accel <= '1';
  129. at_landing <= '0';
  130. if (timer_accel <='0')
  131. then state <= s3; -- accel
  132. else
  133. state <= s4; -- hold
  134. accel <= '0';
  135. end if;
  136. when s4 => -- hold
  137. hold <= '1';
  138. if (near_call='0')
  139. then state <= s4; -- hold
  140. else
  141. state <= s5; -- brake
  142. brake <= '1';
  143. end if;
  144. when s5 => -- brake
  145. hold <= '0';
  146. brake <= '1';
  147. reset_timer <= '1';
  148. if (at_landing='0')
  149. then state <= s5; -- brake
  150. else state <= s6; -- open door
  151. end if;
  152. when s6 => -- open door
  153. door_closed <='1';
  154. open_door <= '1';
  155. remove_call <= '1';
  156. if ((timer_door='0' or hold_button='1')and close_button='0')
  157. then state <= s6; -- open door
  158. else state <= s7; -- close door
  159. end if;
  160. when s7 => -- close door
  161.  
  162. open_door <= '0';
  163. if (door_closed='0')
  164. then state <= s7; -- close door
  165. elsif (at_call='1' or hold_button='1' or open_button='1')
  166. then state <= s6; -- open door
  167. elsif (((direction_up='1' and call_above='1') or (direction_down='1' and call_below='0')) and (call_above='1' or call_below='1'))
  168. then state <= s1; -- set dir up
  169. elsif (((direction_down='1' and call_below='1') or (direction_up='1' and call_above='0')) and (call_above='1' or call_below='1'))
  170. then state <= s2;
  171. elsif (call_above='0' and call_below='0')
  172. then state <= s0;
  173. end if;
  174. end case;
  175. end if;
  176. end process;
  177. end behav;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement