-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtec_gestor_tecla.vhd
310 lines (285 loc) · 11.3 KB
/
tec_gestor_tecla.vhd
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
entity tec_gestor_tecla is
port (
clk : in std_logic;
reset_l : in std_logic;
codigo2 : in std_logic_vector(7 downto 0);
pulsado : in std_logic;
nota : out std_logic_vector(3 downto 0) ;
vol_plus : out std_logic;
vol_minus : out std_logic;
enable : out std_logic;
nota_mel : in std_logic_vector(3 downto 0) ;
enable_mel: in std_logic;
tecla_mel : out std_logic_vector(1 downto 0);
syn_mel : out std_logic
) ;
end tec_gestor_tecla;
architecture arch of tec_gestor_tecla is
TYPE t_estado is (E_INICIO, E_ESPERA,E_ESPERA_PULSADO, E_ENABLE_NOTA, E_SUBIR_VOL, E_BAJAR_VOL, E_ESPERA_VOL, E_ENABLE_MEL);
signal EP, ES, ESTADO: t_estado;
signal mel : std_logic_vector(1 downto 0);
signal tecla_nota : std_logic_vector(3 downto 0);
signal tecla_vol : std_logic;
signal pulsado_ch_up: std_logic;
signal pulsado_ch_down: std_logic;
signal pulsado_prev: std_logic;
signal modo : std_logic_vector(1 downto 0);
signal ld_mel: std_logic;
signal ld_nota: std_logic;
signal ld_modo: std_logic;
signal sel_salida: std_logic;
signal enable_nota: std_logic;
signal r_nota_out: std_logic_vector(3 downto 0);
signal r_modo_out : std_logic_vector(1 downto 0);
signal tecla_mel_int : std_logic_vector(1 downto 0);
constant K_A : std_logic_vector(7 downto 0):= X"1C";
constant K_S : std_logic_vector(7 downto 0):= X"1B";
constant K_D : std_logic_vector(7 downto 0):= X"23";
constant K_F : std_logic_vector(7 downto 0):= X"2B";
constant K_G : std_logic_vector(7 downto 0):= X"34";
constant K_H : std_logic_vector(7 downto 0):= X"33";
constant K_J : std_logic_vector(7 downto 0):= X"3B";
constant K_X : std_logic_vector(7 downto 0):= X"22";
constant K_C : std_logic_vector(7 downto 0):= X"21";
constant K_Z : std_logic_vector(7 downto 0):= X"1A";
constant K_V : std_logic_vector(7 downto 0):= X"2A";
constant K_B : std_logic_vector(7 downto 0):= X"32";
constant K_N : std_logic_vector(7 downto 0):= X"31";
constant K_M : std_logic_vector(7 downto 0):= X"3A";
constant K_UP : std_logic_vector(7 downto 0):= X"75";
constant K_DOWN : std_logic_vector(7 downto 0):= X"72";
constant K_1 : std_logic_vector(7 downto 0):= X"16";
constant K_2 : std_logic_vector(7 downto 0):= X"1E";
constant K_3 : std_logic_vector(7 downto 0):= X"26";
constant K_4 : std_logic_vector(7 downto 0):= X"25";
--constant K_2 : std_logic_vector(7 downto 0):= X"3A";
--constant K_3 : std_logic_vector(7 downto 0):= X"3A";
--constant K_4 : std_logic_vector(7 downto 0):= X"3A";
constant SEL_NULL : std_logic_vector(1 downto 0) := "00" ;
constant SEL_NOTA : std_logic_vector(1 downto 0) := "01" ;
constant SEL_VOL : std_logic_vector(1 downto 0) := "10" ;
constant SEL_MEL : std_logic_vector(1 downto 0) := "11" ;
begin
--Salida UP
ld_modo <= '1' when EP = E_INICIO and pulsado_ch_up = '1' else '0';
ld_nota <= '1' when EP = E_ESPERA and r_modo_out = "01" else '0';
ld_mel <= '1' when EP = E_ESPERA and r_modo_out = "11" else '0';
enable_nota <= '1' when EP = E_ENABLE_NOTA else '0';
vol_plus <= '1' when EP = E_SUBIR_VOL else '0';
vol_minus <= '1' when EP = E_BAJAR_VOL else '0';
sel_salida <= '1' when EP = E_ENABLE_MEL else '0';
syn_mel <= '1' when EP = E_ENABLE_MEL else '0';
tecla_mel <= mel;
est_pr : process( clk, reset_l )
begin
if reset_l = '0' then
EP <= E_INICIO;
elsif rising_edge(clk) then
EP <= ES;
end if ;
end process ; -- est_pr
ESTADO <= EP;
maquina_de_estados: process (EP, codigo2, r_modo_out, pulsado_ch_down, pulsado_ch_up, tecla_vol)
begin
case EP is
when E_INICIO => if pulsado_ch_up = '1' then
ES <= E_ESPERA;
else
ES <= E_INICIO;
end if;
when E_ESPERA => if r_modo_out = "00" then
ES <= E_ESPERA_PULSADO;
elsif r_modo_out = "01" then
ES <= E_ENABLE_NOTA;
elsif r_modo_out = "10" and tecla_vol = '1' then
ES <= E_SUBIR_VOL;
elsif r_modo_out = "10" and tecla_vol = '0' then
ES <= E_BAJAR_VOL;
else
ES <= E_ENABLE_MEL;
end if;
when E_ESPERA_PULSADO => if pulsado_ch_down = '0' then
ES <= E_ESPERA_PULSADO;
else
ES <= E_INICIO;
end if;
when E_ENABLE_NOTA => if pulsado_ch_down = '0' then
ES <= E_ENABLE_NOTA;
else
ES <= E_INICIO;
end if;
when E_SUBIR_VOL => ES <= E_ESPERA_VOL;
when E_BAJAR_VOL => ES <= E_ESPERA_VOL;
when E_ESPERA_VOL => if pulsado_ch_down = '0' then
ES <= E_ESPERA_VOL;
else
ES <= E_INICIO;
end if;
when E_ENABLE_MEL => if pulsado_ch_down = '0' then
ES <= E_ENABLE_MEL;
else
ES <= E_INICIO;
end if;
--ACTIVAR LAS SEÑALES SEGÚN EL ESTADO
end case;
end process;
tecla_case : process (codigo2)
begin
case codigo2 is
------NOTAS------
when K_A => tecla_nota <= X"0";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_S => tecla_nota <= X"1";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_D => tecla_nota <= X"2";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_F => tecla_nota <= X"3";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_G => tecla_nota <= X"4";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_H => tecla_nota <= X"5";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_J => tecla_nota <= X"6";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_Z => tecla_nota <= X"7";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_X => tecla_nota <= X"8";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_C => tecla_nota <= X"9";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_V => tecla_nota <= X"A";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_B => tecla_nota <= X"B";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_N => tecla_nota <= X"C";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
when K_M => tecla_nota <= X"D";
modo <= SEL_NOTA;
tecla_vol <= '0';
tecla_mel_int <= "00";
-------VOLUMEN---------
when K_UP => tecla_vol <= '0';
modo <= SEL_VOL;
tecla_nota <= X"0";
tecla_mel_int <= "00";
when K_DOWN => tecla_vol <= '1';
modo <= SEL_VOL;
tecla_nota <= X"0";
tecla_mel_int <= "00";
-------MELODIAS---------
when K_1 => tecla_mel_int <= "00";
modo <= SEL_MEL;
tecla_nota <= X"0";
tecla_vol <= '0';
when K_2 => tecla_mel_int <= "01";
modo <= SEL_MEL;
tecla_nota <= X"0";
tecla_vol <= '0';
when K_3=> tecla_mel_int <= "10";
modo <= SEL_MEL;
tecla_nota <= X"0";
tecla_vol <= '0';
when K_4 => tecla_mel_int <= "11";
modo <= SEL_MEL;
tecla_nota <= X"0";
tecla_vol <= '0';
when others => modo <= SEL_NULL;
tecla_mel_int <= "00";
tecla_nota <= X"0";
tecla_vol <= '0';
end case;
end process;
mux_salida : process( sel_salida, enable_mel, nota_mel, enable_nota, r_nota_out)
begin
if sel_salida = '1' then
enable <= enable_mel;
nota <= nota_mel;
else
enable <= enable_nota;
nota <= r_nota_out;
end if ;
end process ; -- mux_salida
-- Proceso de ejemplo para copypaste
-- ej : process( clk, reset_l )
-- begin
-- if reset_l = '0' then
-- elsif rising_edge(clk) then
--
-- end if ;
-- end process ;
r_nota : process( clk, reset_l )
begin
if reset_l = '0' then
r_nota_out <= X"0";
elsif rising_edge(clk) then
if ld_nota = '1' then
r_nota_out <= tecla_nota;
end if ;
end if ;
end process ;
r_mel : process( clk, reset_l )
begin
if reset_l = '0' then
mel <= "00";
elsif rising_edge(clk) then
if ld_mel = '1' then
mel <= tecla_mel_int;
end if ;
end if ;
end process ;
pulsado_ch : process( clk, reset_l )
begin
if reset_l = '0' then
pulsado_prev <= '0';
elsif rising_edge(clk) then
if(pulsado = '1') then
pulsado_prev <= '1';
else
pulsado_prev <= '0';
end if;
end if;
end process ;
pulsado_ch_up <= ( pulsado_prev xor pulsado) and pulsado;
pulsado_ch_down <= (pulsado_prev xor pulsado) and pulsado_prev;
--Registro modo
--Proceso de ejemplo para copypaste
r_modo : process( clk, reset_l )
begin
if reset_l = '0' then
r_modo_out <= "00";
elsif rising_edge(clk) then
if ( ld_modo = '1') then
r_modo_out <= modo;
end if ;
end if;
end process ;
end architecture ;