Advertisement
Guest User

Untitled

a guest
Jun 10th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.NUMERIC_STD.ALL;
  4. use work.TIMER_PKG.ALL;
  5.  
  6. entity CONTROLLER is
  7. port (
  8. -- Clocks and Reset
  9. sysclk_in : in std_logic;
  10. clk10hz_in : in std_logic;
  11. reset_in : in std_logic;
  12.  
  13.  
  14.  
  15.  
  16. -- Alu
  17. alu_instruction_out : out ALU_INSTRUCTION_TYPE;
  18. timer_is_zero_in : in std_logic;
  19.  
  20. -- Key Controls
  21. keyUp_in : in std_logic;
  22. keyDown_in : in std_logic;
  23. keyLeft_in : in std_logic;
  24. keyRight_in : in std_logic;
  25. keySet_in : in std_logic;
  26.  
  27. -- 7 Segment Display
  28. disp_highlight_out : out std_logic_vector(3 downto 0);
  29. disp_dots_out : out std_logic_vector(3 downto 0);
  30.  
  31. -- Alarm
  32. alarm_out : out std_logic
  33. );
  34. end CONTROLLER;
  35.  
  36. architecture Behavioral of CONTROLLER is
  37.  
  38. type fsm_type is ( IDLE, START, WAIT10HZ, CNTDWN, TIMER_END, RESTORE,
  39. SEL_MIN, INC_MIN, DEC_MIN,
  40. SEL_SEC10, INC_sec10, DEC_SEC10,
  41. SEL_SEC, INC_SEC, DEC_SEC);
  42.  
  43. signal state, next_state : fsm_type;
  44. state <= idle;
  45.  
  46. begin
  47.  
  48. P1:process is begin
  49. wait until rising_edge(sysclk_in);
  50. state <= next_state;
  51. end process;
  52.  
  53.  
  54. P2:process(sysclk_in, reset_in, keyup_in, keydown_in, keyleft_in, keyright_in, keyset_in,
  55. timer_is_zero_in) is begin
  56. next_state <= state;
  57. case state is
  58. when IDLE =>
  59. if (keyright_in or keyup_in or keydown_in or keyleft_in) = '1' then
  60. next_state <= start;
  61. elsif keyset_in = '1' then
  62. next_state <= sel_min;
  63. end if;
  64.  
  65. when Start =>
  66. next_state <= wait10hz;
  67.  
  68. when wait10hz =>
  69. if clk10hz_in = '1' then
  70. next_state <= cntdwn;
  71. end if;
  72.  
  73. when cntdwn =>
  74. if timer_is_zero_in = '1' then
  75. next_state <= timer_end;
  76. elsif (keyright_in or keyup_in or keydown_in or keyleft_in or keyset_in) ='1' then
  77. next_state <= restore;
  78. end if;
  79.  
  80. when restore =>
  81. next_state <= start;
  82.  
  83. when timer_end =>
  84. if (keyright_in or keyup_in or keydown_in or keyleft_in or keyset_in) ='1' then
  85. next_state <= idle;
  86. end if;
  87.  
  88. when sel_min =>
  89. if keyup_in = '1' then
  90. next_state <= inc_min;
  91. elsif keydown_in ='1' then
  92. next_state <= dec_min;
  93. elsif keyright_in ='1' then
  94. next_state <= sel_sec10;
  95. end if;
  96.  
  97. when sel_sec10 =>
  98. if keyleft_in = '1' then
  99. next_state <= sel_min;
  100. elsif keyright_in ='1' then
  101. next_state <= sel_sec;
  102. elsif keyup_in = '1' then
  103. next_state <= inc_sec10;
  104. elsif keydown_in = '1' then
  105. next_state <= dec_sec10;
  106. end if;
  107.  
  108. when sel_sec=>
  109. if keyleft_in ='1' then
  110. next_state <= sel_sec10;
  111. elsif keyright_in ='1' then
  112. next_state <= start;
  113. elsif keydown_in ='1' then
  114. next_state <= dec_sec;
  115. elsif keyup_in ='1' then
  116. next_state <= inc_sec;
  117. end if;
  118.  
  119. when inc_min =>
  120. next_state <= sel_min;
  121.  
  122. when dec_min =>
  123. next_state <= sel_min;
  124.  
  125. when inc_sec10 =>
  126. next_state <= sel_sec10;
  127.  
  128. when dec_sec10 =>
  129. next_state <= sel_sec10;
  130.  
  131. when inc_sec =>
  132. next_state <= sel_sec;
  133.  
  134. when dec_sec =>
  135. next_state <= sel_sec;
  136.  
  137. when others => null;
  138.  
  139.  
  140. end case;
  141.  
  142. if reset_in = '1' then
  143. next_state <= idle;
  144. end if;
  145.  
  146. disp_highlight_out <= "1111";
  147. disp_dots_out <= "0101";
  148. alarm_out <= '0';
  149. alu_instruction_out <= alu_none;
  150.  
  151.  
  152.  
  153. case state is
  154. when start =>
  155. alu_instruction_out <= alu_store;
  156. disp_highlight_out <= "1111";
  157. disp_dots_out <= "0101";
  158.  
  159. when idle =>
  160. alu_instruction_out <= alu_none;
  161. disp_highlight_out <= "1111";
  162. disp_dots_out <= "0101";
  163. alarm_out <= '0';
  164.  
  165. when wait10hz =>
  166. alu_instruction_out <= alu_none;
  167. disp_highlight_out <= "1111";
  168. disp_dots_out <= "0101";
  169.  
  170.  
  171. when cntdwn =>
  172. alu_instruction_out <= alu_dec_timer;
  173. disp_highlight_out <= "1111";
  174. disp_dots_out <= "0101";
  175.  
  176. when timer_end =>
  177. alu_instruction_out <= alu_store;
  178. disp_highlight_out <= "1111";
  179. disp_dots_out <= "0101";
  180. alarm_out <= '1';
  181.  
  182. when sel_min =>
  183. alu_instruction_out <= alu_none;
  184. disp_highlight_out <= "1000";
  185. disp_dots_out <= "0101";
  186.  
  187. when inc_min =>
  188. alu_instruction_out <= alu_single_inc_min;
  189. disp_highlight_out <= "1000";
  190. disp_dots_out <= "0101";
  191.  
  192. when dec_min =>
  193. alu_instruction_out <= alu_single_dec_min;
  194. disp_highlight_out <= "1000";
  195. disp_dots_out <= "0101";
  196.  
  197. when sel_sec10 =>
  198. alu_instruction_out <= alu_none;
  199. disp_highlight_out <= "0100";
  200. disp_dots_out <= "0101";
  201.  
  202. when dec_sec10 =>
  203. alu_instruction_out <= alu_single_dec_sec10;
  204. disp_highlight_out <= "0100";
  205. disp_dots_out <= "0101";
  206.  
  207. when inc_sec10 =>
  208. alu_instruction_out <= alu_single_inc_sec10;
  209. disp_highlight_out <= "0100";
  210. disp_dots_out <= "0101";
  211.  
  212. when dec_sec =>
  213. alu_instruction_out <= alu_single_dec_sec;
  214. disp_highlight_out <= "0010";
  215. disp_dots_out <= "0101";
  216.  
  217. when inc_sec =>
  218. alu_instruction_out <= alu_single_inc_sec;
  219. disp_highlight_out <= "0010";
  220. disp_dots_out <= "0101";
  221.  
  222. when sel_sec =>
  223. alu_instruction_out <= alu_none;
  224. disp_highlight_out <= "0010";
  225. disp_dots_out <= "0101";
  226. when others =>
  227. alu_instruction_out <= alu_none;
  228.  
  229.  
  230. end case;
  231. end process;
  232.  
  233.  
  234.  
  235. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement