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;
- use work.TIMER_PKG.ALL;
- entity CONTROLLER is
- port (
- -- Clocks and Reset
- sysclk_in : in std_logic;
- clk10hz_in : in std_logic;
- reset_in : in std_logic;
- -- Alu
- alu_instruction_out : out ALU_INSTRUCTION_TYPE;
- timer_is_zero_in : in std_logic;
- -- Key Controls
- keyUp_in : in std_logic;
- keyDown_in : in std_logic;
- keyLeft_in : in std_logic;
- keyRight_in : in std_logic;
- keySet_in : in std_logic;
- -- 7 Segment Display
- disp_highlight_out : out std_logic_vector(3 downto 0);
- disp_dots_out : out std_logic_vector(3 downto 0);
- -- Alarm
- alarm_out : out std_logic
- );
- end CONTROLLER;
- architecture Behavioral of CONTROLLER is
- type fsm_type is ( IDLE, START, WAIT10HZ, CNTDWN, TIMER_END, RESTORE,
- SEL_MIN, INC_MIN, DEC_MIN,
- SEL_SEC10, INC_sec10, DEC_SEC10,
- SEL_SEC, INC_SEC, DEC_SEC);
- signal state, next_state : fsm_type;
- state <= idle;
- begin
- P1:process is begin
- wait until rising_edge(sysclk_in);
- state <= next_state;
- end process;
- P2:process(sysclk_in, reset_in, keyup_in, keydown_in, keyleft_in, keyright_in, keyset_in,
- timer_is_zero_in) is begin
- next_state <= state;
- case state is
- when IDLE =>
- if (keyright_in or keyup_in or keydown_in or keyleft_in) = '1' then
- next_state <= start;
- elsif keyset_in = '1' then
- next_state <= sel_min;
- end if;
- when Start =>
- next_state <= wait10hz;
- when wait10hz =>
- if clk10hz_in = '1' then
- next_state <= cntdwn;
- end if;
- when cntdwn =>
- if timer_is_zero_in = '1' then
- next_state <= timer_end;
- elsif (keyright_in or keyup_in or keydown_in or keyleft_in or keyset_in) ='1' then
- next_state <= restore;
- end if;
- when restore =>
- next_state <= start;
- when timer_end =>
- if (keyright_in or keyup_in or keydown_in or keyleft_in or keyset_in) ='1' then
- next_state <= idle;
- end if;
- when sel_min =>
- if keyup_in = '1' then
- next_state <= inc_min;
- elsif keydown_in ='1' then
- next_state <= dec_min;
- elsif keyright_in ='1' then
- next_state <= sel_sec10;
- end if;
- when sel_sec10 =>
- if keyleft_in = '1' then
- next_state <= sel_min;
- elsif keyright_in ='1' then
- next_state <= sel_sec;
- elsif keyup_in = '1' then
- next_state <= inc_sec10;
- elsif keydown_in = '1' then
- next_state <= dec_sec10;
- end if;
- when sel_sec=>
- if keyleft_in ='1' then
- next_state <= sel_sec10;
- elsif keyright_in ='1' then
- next_state <= start;
- elsif keydown_in ='1' then
- next_state <= dec_sec;
- elsif keyup_in ='1' then
- next_state <= inc_sec;
- end if;
- when inc_min =>
- next_state <= sel_min;
- when dec_min =>
- next_state <= sel_min;
- when inc_sec10 =>
- next_state <= sel_sec10;
- when dec_sec10 =>
- next_state <= sel_sec10;
- when inc_sec =>
- next_state <= sel_sec;
- when dec_sec =>
- next_state <= sel_sec;
- when others => null;
- end case;
- if reset_in = '1' then
- next_state <= idle;
- end if;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- alarm_out <= '0';
- alu_instruction_out <= alu_none;
- case state is
- when start =>
- alu_instruction_out <= alu_store;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- when idle =>
- alu_instruction_out <= alu_none;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- alarm_out <= '0';
- when wait10hz =>
- alu_instruction_out <= alu_none;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- when cntdwn =>
- alu_instruction_out <= alu_dec_timer;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- when timer_end =>
- alu_instruction_out <= alu_store;
- disp_highlight_out <= "1111";
- disp_dots_out <= "0101";
- alarm_out <= '1';
- when sel_min =>
- alu_instruction_out <= alu_none;
- disp_highlight_out <= "1000";
- disp_dots_out <= "0101";
- when inc_min =>
- alu_instruction_out <= alu_single_inc_min;
- disp_highlight_out <= "1000";
- disp_dots_out <= "0101";
- when dec_min =>
- alu_instruction_out <= alu_single_dec_min;
- disp_highlight_out <= "1000";
- disp_dots_out <= "0101";
- when sel_sec10 =>
- alu_instruction_out <= alu_none;
- disp_highlight_out <= "0100";
- disp_dots_out <= "0101";
- when dec_sec10 =>
- alu_instruction_out <= alu_single_dec_sec10;
- disp_highlight_out <= "0100";
- disp_dots_out <= "0101";
- when inc_sec10 =>
- alu_instruction_out <= alu_single_inc_sec10;
- disp_highlight_out <= "0100";
- disp_dots_out <= "0101";
- when dec_sec =>
- alu_instruction_out <= alu_single_dec_sec;
- disp_highlight_out <= "0010";
- disp_dots_out <= "0101";
- when inc_sec =>
- alu_instruction_out <= alu_single_inc_sec;
- disp_highlight_out <= "0010";
- disp_dots_out <= "0101";
- when sel_sec =>
- alu_instruction_out <= alu_none;
- disp_highlight_out <= "0010";
- disp_dots_out <= "0101";
- when others =>
- alu_instruction_out <= alu_none;
- end case;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement