Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 11:10:12 01/28/2020
  6. -- Design Name:
  7. -- Module Name: progetto_TD_vhdl - Bank_entrance
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity progetto_TD_vhdl is
  34. Port ( --Inputs:
  35. buttonA : in STD_LOGIC; --pulsante apertura portaA
  36. buttonB : in STD_LOGIC; --pulsante apertura portaB
  37. sensorA : in STD_LOGIC; --sensore passaggio porta A
  38. sensorB : in STD_LOGIC; --sensore passaggio porta B
  39. sensorC : in STD_LOGIC; --rilevazione persona tra le due porte
  40. md_detection : in STD_LOGIC; --rilevazione metal detector
  41.  
  42. --Outputs:
  43. doorA : out STD_LOGIC; --apertura porta A
  44. doorB : out STD_LOGIC; --apertura porta B
  45. alarm : out STD_LOGIC; --attivazione allarme di sicurezza
  46.  
  47. clk : in STD_LOGIC;
  48. rst : in STD_LOGIC);
  49. end progetto_TD_vhdl;
  50.  
  51. architecture Bank_entrance of progetto_TD_vhdl is
  52. type state is ( s0, s1, s2, s3, s4, s5, s6, s7 ); --dichiarazione stati automa
  53. signal current_state, next_state : state;
  54. signal count, new_count: integer range 0 to 65;
  55. signal timeover : STD_LOGIC := '0';
  56.  
  57.  
  58. begin
  59.  
  60. process(clk)
  61. begin
  62. if ( rising_edge ( clk ) ) then
  63. if ( rst = '1' ) then
  64. current_state <= s0;
  65. count<=0;
  66. else
  67. current_state <= next_state;
  68. count<=new_count;
  69. end if;
  70. end if;
  71. end process;
  72.  
  73.  
  74. --Processo per l'aggiornamento degli stati
  75. next_state_update : process( clk,buttonA, buttonB, current_state,sensorA, sensorB, sensorC, md_detection, timeover )
  76. begin
  77. case current_state is
  78. when s0 => if( buttonB = '1' )then
  79. next_state <= s5;
  80. elsif( buttonB = '0' and buttonA = '1' )then
  81. next_state <= s1;
  82. else
  83. next_state <= s0;
  84. end if;
  85. when s1 => if ( timeover = '1' and (sensorA = '0' or sensorC='0' ) ) then
  86. next_state <= s0;
  87. else
  88. if( timeover='0' and sensorC = '1' and sensorA = '0' ) then
  89. next_state <= s2;
  90. else
  91. next_state <= s1;
  92. end if;
  93. end if;
  94. when s2 => if(md_detection='0')then
  95. next_state<=s3;
  96. else
  97. next_state<=s4;
  98. end if;
  99. when s3 => if (sensorC = '0' and sensorB = '0' ) then
  100. next_state<=s0;
  101. else
  102. next_state<=s3;
  103. end if;
  104. when s4 => if(sensorC = '0' and sensorA = '0' ) then
  105. next_state <= s0;
  106. else
  107. next_state <= s4;
  108. end if;
  109. when s5 => if ( timeover = '1' and (sensorB = '0' and sensorC = '0') ) then
  110. next_state <= s0;
  111. else
  112. if ( sensorC = '1' and sensorB = '0' ) then
  113. next_state <= s6;
  114. else
  115. next_state <= s5;
  116. end if;
  117. end if;
  118. when s6 => -- timeover per aspettare più tempo per chiudere correttamente B e aprire A
  119. if(timeover='1') then
  120. next_state<=s7;
  121. else
  122. next_state<=s6;
  123. end if;
  124. when s7 => if( sensorC = '0' and sensorA = '0' ) then
  125. next_state <= s0;
  126. else
  127. next_state <= s7;
  128. end if;
  129. end case;
  130. end process;
  131.  
  132.  
  133. --Timer per mantenere la porta aperta in caso di entrata/uscita
  134. timer : process ( current_state, count )
  135. begin
  136. if ( current_state = s1 or current_state = s5 or current_state=s6) then
  137. if count = 3 then
  138. new_count <= 0;
  139. timeover <= '1';
  140. else
  141. new_count <= count+1;
  142. timeover <= '0';
  143. end if;
  144. else
  145. new_count <= 0;
  146. timeover <= '0';
  147. end if;
  148. end process;
  149.  
  150.  
  151. --Processo aggiornamento uscite
  152. output_update: process(current_state)
  153. begin
  154. case current_state is
  155. --Uscite per s0
  156. when s0=> doorA<='0';
  157. doorB<='0';
  158. alarm<='0';
  159. --Uscite per s1
  160. when s1=> doorA<='1';
  161. doorB<='0';
  162. alarm<='0';
  163. --Uscite per s2
  164. when s2=> doorA<='0';
  165. doorB<='0';
  166. alarm<='0';
  167. --Uscite per s3
  168. when s3=> doorA<='0';
  169. doorB<='1';
  170. alarm<='0';
  171. --Uscite per s4
  172. when s4=> doorA<='1';
  173. doorB<='0';
  174. alarm<='1';
  175. --Uscite per s5
  176. when s5=> doorA<='0';
  177. doorB<='1';
  178. alarm<='0';
  179. --Uscite per s6
  180. when s6=> doorA<='0';
  181. doorB<='0';
  182. alarm<='0';
  183. --Uscite per s7
  184. when s7=> doorA<='1';
  185. doorB<='0';
  186. alarm<='0';
  187. end case;
  188. end process;
  189.  
  190. end Bank_entrance;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement