-
Notifications
You must be signed in to change notification settings - Fork 4
/
vu_meter.vhd
530 lines (425 loc) · 12.2 KB
/
vu_meter.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity vu_meter is
port (
CLOCK_50 : in std_logic;
KEY : in std_logic_vector(3 downto 0);
AUD_ADCDAT : inout std_logic;
AUD_BCLK : inout std_logic;
AUD_ADCLRCK : inout std_logic;
AUD_DACLRCK : inout std_logic;
I2C_SDAT : inout std_logic;
AUD_XCK : out std_logic;
AUD_DACDAT : out std_logic;
I2C_SCLK : out std_logic;
SW : in std_logic_vector(17 downto 0);
TFT_SDO : IN STD_LOGIC;
TFT_SCK : OUT STD_LOGIC;
TFT_SDI : OUT STD_LOGIC;
TFT_DC : OUT STD_LOGIC;
TFT_RESET : OUT STD_LOGIC;
TFT_CS : OUT STD_LOGIC;
UART_TXD : OUT STD_LOGIC;
UART_RXD : IN STD_LOGIC;
UART_CTS : OUT STD_LOGIC;
UART_RTS : IN STD_LOGIC;
DEBUG_DATA : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
DEBUG_DATA_EN : OUT STD_LOGIC
);
end entity vu_meter;
architecture rtl of vu_meter is
------------------------
-- Components ----------
------------------------
component dac_i2s is
port (
CLOCK_50 : in std_logic;
reset : in std_logic;
AUD_ADCDAT : inout std_logic;
AUD_BCLK : inout std_logic;
AUD_ADCLRCK : inout std_logic;
AUD_DACLRCK : inout std_logic;
I2C_SDAT : inout std_logic;
AUD_XCK : out std_logic;
AUD_DACDAT : out std_logic;
I2C_SCLK : out std_logic;
audio_left : out std_logic_vector(15 downto 0);
audio_left_en : out std_logic;
audio_right : out std_logic_vector(15 downto 0);
audio_right_en : out std_logic
);
end component dac_i2s;
component ili9341 IS
PORT (
CLK : IN STD_LOGIC;
TFT_SDO : IN STD_LOGIC;
TFT_SCK : OUT STD_LOGIC;
TFT_SDI : OUT STD_LOGIC;
TFT_DC : OUT STD_LOGIC;
TFT_RESET : OUT STD_LOGIC;
TFT_CS : OUT STD_LOGIC;
fb_data : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
fb_wraddress: IN STD_LOGIC_VECTOR (16 DOWNTO 0);
fb_wrclock : IN STD_LOGIC;
fb_wren : IN STD_LOGIC
);
END component ili9341;
component plotspec is
port (
clock : in std_logic;
reset : in std_logic;
data_in : in std_logic_vector(7 downto 0);
data_in_en : in std_logic;
data_in_start : in std_logic;
fb_data : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
fb_wraddress : OUT STD_LOGIC_VECTOR (16 DOWNTO 0);
fb_wren : OUT STD_LOGIC
);
end component plotspec;
component fake_plotspec is
port (
clock : in std_logic;
reset : in std_logic;
fb_data : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
fb_wraddress : OUT STD_LOGIC_VECTOR (16 DOWNTO 0);
fb_wren : OUT STD_LOGIC
);
end component fake_plotspec;
component fake_dac is
port (
clock : in STD_LOGIC;
reset : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(15 downto 0);
data_out_en : out STD_LOGIC
);
end component fake_dac;
component fft is
generic (
SIZE : natural := 1024
);
port (
clock : in std_logic;
reset : in std_logic;
data_en : in std_logic;
data_in : in std_logic_vector(15 downto 0);
data_start : in std_logic;
data_fft_out : out std_logic_vector(31 downto 0);
data_fft_out_en : out std_logic;
data_fft_out_start : out std_logic
);
end component fft;
component uart_dump is
generic (
SIZE : natural := 1024
);
port (
i_clock : in std_logic;
i_reset : in std_logic;
i_start : in std_logic;
i_data : in std_logic_vector(15 downto 0);
i_enable : in std_logic;
o_tx_byte : out std_logic_vector(7 downto 0);
o_tx_dv : out std_logic;
i_tx_done : in std_logic;
i_tx_active : in std_logic
);
end component uart_dump;
component UART_TX is
generic (
g_CLKS_PER_BIT : integer := 115 -- Needs to be set correctly
);
port (
i_Clk : in std_logic;
i_TX_DV : in std_logic;
i_TX_Byte : in std_logic_vector(7 downto 0);
o_TX_Active : out std_logic;
o_TX_Serial : out std_logic;
o_TX_Done : out std_logic
);
end component UART_TX;
component debounce IS
GENERIC(
counter_size : INTEGER := 10); --counter size (19 bits gives 10.5ms with 50MHz clock)
PORT(
clk : IN STD_LOGIC; --input clock
reset : IN STD_LOGIC;
button : IN STD_LOGIC; --input signal to be debounced
result : OUT STD_LOGIC); --debounced signal
END component debounce;
component int2fp IS
PORT
(
clock : IN STD_LOGIC ;
dataa : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
END component int2fp;
component powerlog is
port (
i_clock : in std_logic;
i_reset : in std_logic;
i_data : in std_logic_vector(31 downto 0);
i_data_start: in std_logic;
i_data_en : in std_logic;
o_data : out std_logic_vector(31 downto 0);
o_data_en : out std_logic;
o_data_start: out std_logic
);
end component powerlog;
component dataacq is
generic (
SIZE : natural := 1024
);
port (
i_clock : in std_logic;
i_reset : in std_logic;
i_data_en : in std_logic;
i_data : in std_logic_vector(15 downto 0);
i_start : in std_logic;
o_data : out std_logic_vector(15 downto 0);
o_data_en : out std_logic;
o_data_start : out std_logic
);
end component dataacq;
component triggen is
generic (
CLKCOUNTER : natural := 5000000
);
port (
clock : in std_logic;
reset_n : in std_logic;
enable : out std_logic
);
end component triggen;
component windowfunction is
generic (
SIZE : natural := 1024
);
port (
i_clock : in std_logic;
i_reset : in std_logic;
i_data : in std_logic_vector(15 downto 0);
i_data_start: in std_logic;
i_data_en : in std_logic;
o_data : out std_logic_vector(15 downto 0);
o_data_en : out std_logic;
o_data_start: out std_logic
);
end component windowfunction;
------------------------
-- Signals -------------
------------------------
signal fb_data : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal fb_wraddress : STD_LOGIC_VECTOR (16 DOWNTO 0);
signal fb_wren : STD_LOGIC;
signal audio_left : std_logic_vector(15 downto 0);
signal audio_right : std_logic_vector(15 downto 0);
signal audio_left_en : std_logic;
signal audio_right_en : std_logic;
signal reset : std_logic;
signal i2s_left : std_logic_vector(15 downto 0);
signal i2s_left_en : std_logic;
signal fake_left : std_logic_vector(15 downto 0);
signal fake_left_en : std_logic;
signal fft_data_out_en : std_logic;
signal fft_data_out : std_logic_vector(31 downto 0) := (others => '0');
signal fft_data_out_start : std_logic;
signal r_tx_byte : std_logic_vector(7 downto 0);
signal r_tx_dv : std_logic;
signal r_tx_done : std_logic;
signal r_tx_active : std_logic;
signal select_dac : std_logic;
signal button_raw,trigger : std_logic;
signal logfft_data_out : std_logic_vector(31 downto 0);
signal logfft_data_out_en : std_logic;
signal logfft_data_out_start : std_logic;
signal buff_data : std_logic_vector(15 downto 0);
signal buff_data_en,buff_data_start : std_logic;
signal wbuff_data : std_logic_vector(15 downto 0);
signal wbuff_data_en,wbuff_data_start : std_logic;
signal r_start_fft : std_logic;
signal reset_n : std_logic;
signal fft_data_out_sh : std_logic_vector(7 downto 0);
signal plot_data : std_logic_vector(7 downto 0);
signal plot_data_en : std_logic;
signal plot_data_start : std_logic;
begin
reset_n <= not reset;
fft_data_out_sh <= fft_data_out(13 downto 6);
with SW(1) select plot_data <= logfft_data_out(7 downto 0) when '0',
fft_data_out(13 downto 6) when others;
with SW(1) select plot_data_en <= logfft_data_out_en when '0',
fft_data_out_en when others;
with SW(1) select plot_data_start <= logfft_data_out_start when '0',
fft_data_out_start when others;
-- data_in => logfft_data_out(7 downto 0),
-- data_in_en => logfft_data_out_en,
-- data_in_start => logfft_data_out_start
-- data_fft_out => fft_data_out,
-- data_fft_out_en => fft_data_out_en,
-- data_fft_out_start => fft_data_out_start
button_raw <= not KEY(1);
select_dac <= SW(0);
with select_dac select audio_left <=
i2s_left when '0',
fake_left when others;
with select_dac select audio_left_en <=
i2s_left_en when '0',
fake_left_en when others;
reset <= not KEY(0);
dac_i2s_i1 : dac_i2s
port map (
CLOCK_50 => CLOCK_50,
reset => reset,
AUD_ADCDAT => AUD_ADCDAT,
AUD_BCLK => AUD_BCLK,
AUD_ADCLRCK => AUD_ADCLRCK,
AUD_DACLRCK => AUD_DACLRCK,
I2C_SDAT => I2C_SDAT,
AUD_XCK => AUD_XCK,
AUD_DACDAT => AUD_DACDAT,
I2C_SCLK => I2C_SCLK,
audio_left => i2s_left,
audio_left_en => i2s_left_en,
audio_right => open,
audio_right_en => open
);
fake_dac_i1 : fake_dac
port map (
clock => CLOCK_50,
reset => reset,
data_out => fake_left,
data_out_en => fake_left_en
);
triggen_i1 : triggen
generic map(
CLKCOUNTER => 3_000_000
)
port map (
clock => CLOCK_50,
reset_n => reset_n,
enable => r_start_fft
);
dataacq_i1 : dataacq
generic map(
SIZE => 1024
)
port map(
i_clock => CLOCK_50,
i_reset => reset,
i_data_en => audio_left_en,
i_data => audio_left,
i_start => r_start_fft,
o_data => buff_data,
o_data_en => buff_data_en,
o_data_start => buff_data_start
);
windowfunction_i1 : windowfunction
generic map (
SIZE => 1024
)
port map (
i_clock => CLOCK_50,
i_reset => reset,
i_data => buff_data,
i_data_start => buff_data_start,
i_data_en => buff_data_en,
o_data => wbuff_data,
o_data_en => wbuff_data_en,
o_data_start => wbuff_data_start
);
fft_i1 : fft
generic map (
SIZE => 1024
)
port map (
clock => CLOCK_50,
reset => reset,
data_start => wbuff_data_start,
data_en => wbuff_data_en,
data_in => wbuff_data,
data_fft_out => fft_data_out,
data_fft_out_en => fft_data_out_en,
data_fft_out_start => fft_data_out_start
);
powerlog_i1 : powerlog
port map (
i_clock => CLOCK_50,
i_reset => reset,
i_data => fft_data_out,
i_data_en => fft_data_out_en,
i_data_start => fft_data_out_start,
o_data => logfft_data_out,
o_data_en => logfft_data_out_en,
o_data_start => logfft_data_out_start
);
DEBUG_DATA <= logfft_data_out;
DEBUG_DATA_EN <= logfft_data_out_en;
ili9341_i1 : ili9341
PORT MAP (
CLK => CLOCK_50,
TFT_SDO => TFT_SDO,
TFT_SCK => TFT_SCK,
TFT_SDI => TFT_SDI,
TFT_DC => TFT_DC,
TFT_RESET => TFT_RESET,
TFT_CS => TFT_CS,
fb_data => fb_data,
fb_wraddress=> fb_wraddress,
fb_wrclock => CLOCK_50,
fb_wren => fb_wren
);
plotspec_i1 : plotspec
port map (
clock => CLOCK_50,
reset => reset,
data_in => plot_data,
data_in_en => plot_data_en,
data_in_start => plot_data_start,
-- data_in => logfft_data_out(7 downto 0),
-- data_in_en => logfft_data_out_en,
-- data_in_start => logfft_data_out_start,
fb_data => fb_data,
fb_wraddress => fb_wraddress,
fb_wren => fb_wren
);
uart_dump_i1 : uart_dump
generic map (
SIZE => 1024
)
port map (
i_clock => CLOCK_50,
i_reset => reset,
i_start => trigger,
i_data => fft_data_out(31 downto 16),
i_enable => fft_data_out_en,
o_tx_byte => r_tx_byte,
o_tx_dv => r_tx_dv,
i_tx_done => r_tx_done,
i_tx_active => r_tx_active
);
UART_TX_i1 : UART_TX
generic map (
g_CLKS_PER_BIT => 108
)
port map (
i_Clk => CLOCK_50,
i_TX_DV => r_tx_dv,
i_TX_Byte => r_tx_byte,
o_TX_Active => r_tx_active,
o_TX_Serial => UART_TXD,
o_TX_Done => r_tx_done
);
debounce_i1 : debounce
GENERIC MAP (
counter_size => 5_000_000
)
PORT MAP (
clk => CLOCK_50,
reset => reset,
button => button_raw,
result => trigger
);
end rtl;