-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFSM.vhd
More file actions
49 lines (43 loc) · 1.5 KB
/
FSM.vhd
File metadata and controls
49 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY FSM IS
GENERIC (N : INTEGER := 5); -- 0123
PORT (
clk, rst_n, start : IN STD_LOGIC;
switches : IN STD_LOGIC_VECTOR(2 * N - 1 DOWNTO 0);
A_out, B_out : OUT STD_LOGIC_VECTOR (N - 1 DOWNTO 0);
operator_out : OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
state_out : OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
done : OUT STD_LOGIC
);
END FSM;
ARCHITECTURE Behavioral OF FSM IS
TYPE state_type IS (GET_AandB, GET_OPERATOR, FINISHED);
SIGNAL current_state : state_type := GET_AandB;
BEGIN
PROCESS (clk, rst_n, start)
BEGIN
IF rst_n = '1' THEN
done <= '0';
current_state <= GET_AandB;
ELSIF falling_edge(start) THEN
CASE current_state IS
WHEN GET_AandB => current_state <= GET_OPERATOR;
WHEN GET_OPERATOR => current_state <= FINISHED;
WHEN FINISHED => current_state <= FINISHED;
END CASE;
END IF;
CASE current_state IS
WHEN GET_AandB =>
A_out <= switches(2 * N - 1 DOWNTO (2 * N - 1) - (N - 1));
B_out <= switches(N - 1 DOWNTO 0);
state_out <= "00";
WHEN GET_OPERATOR =>
operator_out <= switches(1 DOWNTO 0);
state_out <= "01";
WHEN FINISHED =>
done <= '1';
state_out <= "10";
END CASE;
END PROCESS;
END Behavioral;