Advertisement
SergioRP

Untitled

Dec 5th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Use ieee.numeric_std.all;
  4.  
  5. entity elevador IS
  6. PORT (ck,
  7. clk_button,
  8. rst_button, -- SW[0]
  9. rst_db, -- SW[1]
  10. botoes_andar_switch0, --SW[9]
  11. botoes_andar_switch1, --SW[8]
  12. botoes_andar_switch2, --SW[7]
  13. botoes_andar_switch3 --SW[6]
  14. : IN STD_LOGIC;
  15.  
  16. ANDAR_REQUISITADO_LED, -- LED[9-6]
  17. ANDAR_ATUAL_LED -- LED[5-2]
  18. : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
  19.  
  20. STATE_RESPONSE -- LED[1-0] -- diz se o elevador esta parado "00", subindo "01" ou descendo "11"
  21. : OUT STD_LOGIC_VECTOR(1 DOWNTO 0)
  22. );
  23. end elevador;
  24.  
  25. ARCHITECTURE arch OF elevador IS
  26. COMPONENT debouncer
  27. PORT(
  28. clk, rst_n, inb : in STD_LOGIC;
  29. outb : OUT STD_LOGIC
  30. );
  31. END COMPONENT;
  32.  
  33. TYPE st IS (parado, subindo, descendo);
  34. SIGNAL estado : st;
  35. SIGNAL out_clk_db,
  36. out_rst_db,
  37. botoes_andar0,
  38. botoes_andar1,
  39. botoes_andar2,
  40. botoes_andar3
  41. : STD_LOGIC;
  42. SIGNAL andar_atual, andar_requisitado : STD_LOGIC_VECTOR (3 downto 0);
  43.  
  44. BEGIN
  45. D1 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => clk_button, outb => out_clk_db);
  46. D2 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => rst_button, outb => out_rst_db);
  47. D3 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch0, outb => botoes_andar0);
  48. D4 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch1, outb => botoes_andar1);
  49. D5 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch2, outb => botoes_andar2);
  50. D6 : debouncer PORT MAP(clk => ck, rst_n => rst_db, inb => botoes_andar_switch3, outb => botoes_andar3);
  51.  
  52. PROCESS(out_clk_db, out_rst_db)
  53. BEGIN
  54.  
  55. IF out_rst_db = '1' THEN
  56. estado <= parado;
  57. andar_atual <= "0000";
  58. ANDAR_ATUAL_LED <= "0000";
  59. ANDAR_REQUISITADO_LED <= "0000";
  60. STATE_RESPONSE <= "00";
  61. ELSIF rising_edge(out_clk_db) THEN
  62. CASE estado IS
  63.  
  64. ------------------------------------------------------------------------------------
  65. WHEN parado =>
  66. STATE_RESPONSE <= "00";
  67. andar_requisitado <= "0000";
  68. IF (botoes_andar0 = '1') THEN
  69. andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0001");
  70. END IF;
  71. IF (botoes_andar1 = '1') THEN
  72. andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0010");
  73. END IF;
  74. IF (botoes_andar2 = '1') THEN
  75. andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "0100");
  76. END IF;
  77. IF (botoes_andar3 = '1') THEN
  78. andar_requisitado <= std_logic_vector(unsigned(andar_requisitado) + "1000");
  79. END IF;
  80.  
  81. ANDAR_REQUISITADO_LED <= andar_requisitado;
  82.  
  83. IF (to_integer(unsigned(andar_requisitado)) > to_integer(unsigned(andar_atual))) THEN
  84. estado <= subindo;
  85. ELSIF (to_integer(unsigned(andar_requisitado)) < to_integer(unsigned(andar_atual))) THEN
  86. estado <= descendo;
  87. ELSE
  88. estado <= parado;
  89. END IF;
  90. ------------------------------------------------------------------------------------
  91. WHEN subindo =>
  92. STATE_RESPONSE <= "01";
  93. IF (to_integer(unsigned(andar_requisitado)) > to_integer(unsigned(andar_atual))) THEN
  94. andar_atual <= std_logic_vector(unsigned(andar_atual) + "0001");
  95. ANDAR_ATUAL_LED <= andar_atual;
  96. ELSE
  97. estado <= parado;
  98. END IF;
  99. ------------------------------------------------------------------------------------
  100. WHEN descendo =>
  101. STATE_RESPONSE <= "11";
  102. IF (to_integer(unsigned(andar_requisitado)) < to_integer(unsigned(andar_atual))) THEN
  103. andar_atual <= std_logic_vector(unsigned(andar_atual) - "0001");
  104. ANDAR_ATUAL_LED <= andar_atual;
  105. ELSE
  106. estado <= parado;
  107. END IF;
  108. ------------------------------------------------------------------------------------
  109.  
  110.  
  111. END CASE;
  112. END IF;
  113. END process;
  114.  
  115. END arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement