-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateMachine.vhd.bak
199 lines (99 loc) · 4.25 KB
/
stateMachine.vhd.bak
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity StateMachine is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
keypad_data : in STD_LOGIC_VECTOR(4 downto 0);
data_valid_pulse : in STD_LOGIC;
enable out : std_logic;
up out std_logic);
end StateMachine;
architecture Behavioral of StateMachine is
type State_Type is (INIT, OP_UP_Pause, OP_UP, OP_DOWN, OP_DOWN_Pause, Prog_UP_DATA, Prog_UP_ADDress, Prog_DOWN_DATA, Prog_DOWN_ADDress);
signal current_state, next_state : State_Type;
signal counter : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
begin
process(clk, rst)
begin
if rst = '1' then
current_state <= INIT;
counter <= (others => '0');
elsif rising_edge(clk) then
current_state <= next_state;
counter <= counter + 1;
end if;
end process;
process(current_state, keypad_data, data_valid_pulse)
begin
next_state <= current_state;
case current_state is
when INIT =>
if counter = "11111111" then
next_state <= OP_UP_Pause;
counter <= (others => '0');
end if;
when OP_UP_Pause =>
up <= '1';
enable <='0';
if keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= OP_UP;
elsif keypad_data = "10001" and data_valid_pulse = '1' then
next_state <= Prog_UP_ADDress;
end if;
when OP_UP =>
up <= '1';
enable <='1';
if keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= OP_UP_Pause;
elsif keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= Prog_UP_ADDress;
elsif keypad_data = "10001" and data_valid_pulse = '1' then
next_state <= OP_DOWN;
end if;
when Prog_UP_ADDress =>
if keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= OP_UP_Pause;
elsif keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= Prog_UP_DATA;
end if;
when Prog_UP_DATA =>
if keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= OP_UP_Pause;
elsif keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= Prog_UP_ADDress;
end if;
when OP_DOWN_Pause =>
up <= '0';
enable <='0';
if keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= OP_DOWN;
elsif keypad_data = "10001" and data_valid_pulse = '1' then
next_state <= Prog_DOWN_ADDress;
end if;
when OP_DOWN =>
up <= '0';
enable <='1';
if keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= OP_DOWN_Pause;
elsif keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= Prog_DOWN_ADDress;
elsif keypad_data = "10001" and data_valid_pulse = '1' then
next_state <= OP_UP;
end if;
when Prog_DOWN_ADDress =>
if keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= OP_DOWN_Pause;
elsif keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= Prog_DOWN_DATA;
end if;
when Prog_DOWN_DATA =>
if keypad_data = "10010" and data_valid_pulse = '1' then
next_state <= OP_DOWN_Pause;
elsif keypad_data = "10000" and data_valid_pulse = '1' then
next_state <= Prog_DOWN_ADDress;
end if;
end case;
end process;
end Behavioral;