-
Notifications
You must be signed in to change notification settings - Fork 4
/
calcspec_tb.vhd
176 lines (142 loc) · 4.6 KB
/
calcspec_tb.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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.MATH_REAL.ALL;
use ieee.numeric_std.all;
use STD.textio.all;
use ieee.std_logic_textio.all;
entity calcspec_tb is
end calcspec_tb;
architecture Behavioral of calcspec_tb is
component fft is
port (
clock : in std_logic;
reset : in std_logic;
data_en : in std_logic;
data_in : in std_logic_vector(15 downto 0);
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 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 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;
signal clock,endoffile : std_logic := '0';
signal tick_48khz : std_logic := '0';
signal reset : std_logic := '0';
signal counter_48khz : integer;
signal audio_left : std_logic_vector(15 downto 0);
signal audio_left_en : std_logic;
signal fft_data_out_en : std_logic;
signal fft_data_out : std_logic_vector(31 downto 0);
signal fft_data_out_sh : std_logic_vector(7 downto 0);
signal fft_data_out_start : std_logic;
begin
fft_data_out_sh <= fft_data_out(31 downto 24);
clock <= not (clock) after 10 ns; --clock with time period 20 ns
main : process is
begin
reset <= '1';
wait until rising_edge(clock);
wait until rising_edge(clock);
reset <= '0';
wait;
end process main;
clock48khz: process(clock) is
begin
if reset='1' then
counter_48khz <= 0;
tick_48khz <= '0';
elsif clock='1' and clock'event then
if counter_48khz=99 then
tick_48khz <= '1';
counter_48khz <= 0;
else
counter_48khz <= counter_48khz + 1;
tick_48khz <= '0';
end if;
end if;
end process clock48khz;
--read process
reading : process (clock)
file infile : text is in "1.txt"; --declare input file
variable inline : line; --line number declaration
variable dataread1 : integer;
begin
if (clock='1' and clock'event) then
-- read_en <= '0';
if (tick_48khz='1') then
if (not endfile(infile)) then
readline(infile, inline);
read(inline, dataread1);
--read_data <= std_logic_vector(to_signed(dataread1, read_data'length));
--read_en <= '1';
else
endoffile <='1';
end if;
end if;
end if;
end process reading;
--------------
--write process
writing : process
file outfile : text is out "2.txt"; --declare output file
variable outline : line; --line number declaration
variable datatosave : integer;
begin
wait until clock = '1' and clock'event;
if(fft_data_out_en='1') then
datatosave := to_integer(signed(fft_data_out_sh));
write(outline, datatosave);
writeline(outfile, outline);
else
null;
end if;
end process writing;
-----------------
fake_dac_i1 : fake_dac
port map (
clock => clock,
reset => reset,
data_out => audio_left,
data_out_en => audio_left_en
);
fft_i1 : fft
port map (
clock => clock,
reset => reset,
data_en => audio_left_en,
data_in => audio_left,
data_fft_out_en => fft_data_out_en,
data_fft_out => fft_data_out,
data_fft_out_start => fft_data_out_start
);
plotspec_i1 : plotspec
port map (
clock => clock,
reset => reset,
data_in => fft_data_out(25 downto 18),
data_in_en => fft_data_out_en,
data_in_start => fft_data_out_start,
fb_data => open,
fb_wraddress => open,
fb_wren => open
);
end Behavioral;