-
Notifications
You must be signed in to change notification settings - Fork 1
/
moore.vhdl
137 lines (120 loc) · 3.14 KB
/
moore.vhdl
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY moore IS
PORT (
clk, reset, enable : IN std_logic;
i : IN std_logic;
o : OUT std_logic_vector(1 DOWNTO 0);
s : OUT std_logic_vector(3 DOWNTO 0)
);
END moore;
ARCHITECTURE behaviour OF moore IS
TYPE moore_states IS
(S00, S10, S20, S21, S30, S31, S40, S41, S42, S50);
SIGNAL state, next_state : moore_states;
BEGIN
transition : PROCESS (state, i)
BEGIN
-- avoid latching
next_state <= state;
CASE(state) IS
WHEN S00 =>
IF i = '0' THEN
next_state <= S40;
ELSIF i = '1' THEN
next_state <= S10;
END IF;
WHEN S10 =>
IF i = '0' THEN
next_state <= S20;
ELSIF i = '1' THEN
next_state <= S30;
END IF;
WHEN S20 =>
IF i = '0' THEN
next_state <= S42;
END IF;
WHEN S21 =>
IF i = '0' THEN
next_state <= S42;
END IF;
WHEN S30 =>
IF i = '0' THEN
next_state <= S00;
ELSIF i = '1' THEN
next_state <= S31;
END IF;
WHEN S31 =>
IF i = '0' THEN
next_state <= S00;
END IF;
WHEN S40 =>
IF i = '0' THEN
next_state <= S41;
ELSIF i = '1' THEN
next_state <= S50;
END IF;
WHEN S41 =>
IF i = '1' THEN
next_state <= S50;
END IF;
WHEN S42 =>
IF i = '1' THEN
next_state <= S50;
END IF;
WHEN S50 =>
IF i = '0' THEN
next_state <= S21;
ELSIF i = '1' THEN
next_state <= S00;
END IF;
WHEN OTHERS =>
next_state <= S00;
END CASE;
END PROCESS;
state_memory : PROCESS (clk, reset)
BEGIN
IF reset = '1' THEN
state <= S00;
ELSIF rising_edge(clk) THEN
IF enable = '1' THEN
state <= next_state;
END IF;
END IF;
END PROCESS;
output : PROCESS (state)
BEGIN
IF state = S00 THEN
o <= "00";
s <= "0000";
ELSIF state = S10 THEN
o <= "10";
s <= "0001";
ELSIF state = S20 THEN
o <= "00";
s <= "0010";
ELSIF state = S21 THEN
o <= "01";
s <= "0011";
ELSIF state = S30 THEN
o <= "00";
s <= "0100";
ELSIF state = S31 THEN
o <= "01";
s <= "0101";
ELSIF state = S40 THEN
o <= "00";
s <= "0110";
ELSIF state = S41 THEN
o <= "01";
s <= "0111";
ELSIF state = S42 THEN
o <= "10";
s <= "1000";
ELSIF state = S50 THEN
o <= "00";
s <= "1001";
END IF;
END PROCESS;
END ARCHITECTURE;