-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote_sys.vhd
258 lines (226 loc) · 6.71 KB
/
note_sys.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
-- Frequency Divider
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
USE ieee.std_logic_unsigned.all;
entity tempHz8 is
port (rst : in std_logic;
clk_in : in std_logic;
Hz8 : out std_logic);
end tempHz8;
architecture Behavioral of tempHz8 is
signal count: integer range 0 to 6249999 := 0;
signal temp : std_logic := '0';
begin
process (clk_in, rst)
begin
if rising_edge(clk_in) then
if (rst = '1') then
temp <= '0';
count <= 0;
elsif (count = 6249999) then
temp <= NOT(temp);
count <= 0;
else
count <= count + 1;
end if;
end if;
end process;
Hz8 <= temp;
end Behavioral;
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
USE ieee.std_logic_unsigned.all;
entity gen_note is
port (clk_in : in std_logic;
div : in std_logic_vector (19 downto 0);
note : out std_logic);
end gen_note;
architecture Behavioral of gen_note is
signal count: std_logic_vector (19 downto 0) := x"00000";
signal temp : std_logic := '0';
begin
process (clk_in)
begin
if rising_edge(clk_in) then
if (count = div) then
temp <= NOT(temp);
count <= x"00000";
else
count <= count + 1;
end if;
end if;
end process;
note <= temp;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE ieee.std_logic_signed.all ;
USE ieee.std_logic_arith.all ;
USE ieee.std_logic_unsigned.all;
entity note_sys is
port (nreset: in std_logic;
board_clk: in std_logic;
sct: in std_logic_vector (1 downto 0);
tone: out std_logic;
rth: out std_logic);
end note_sys;
architecture Behavioral of note_sys is
component tempHz8
port (rst : in std_logic;
clk_in : in std_logic;
Hz8 : out std_logic);
end component;
component gen_note
port (clk_in : in std_logic;
div : in std_logic_vector (19 downto 0);
note : out std_logic);
end component;
signal n, c, d, ef, e, f, gf, g, af, a, b, co, do : std_logic;
signal t, ze, cobze : std_logic;
signal cob : std_logic_vector (5 downto 0);
signal play: std_logic_vector (11 downto 0);
begin
-- rhythm
Rhythm: tempHz8 port map (nreset, board_clk, t);
-- note creation
--n <= '0'; -- Null, for pause note.
Ut : gen_note port map (board_clk, x"2EA85",c);
Re : gen_note port map (board_clk, x"29918",d);
Miflat: gen_note port map (board_clk, x"273C0",ef);
Mi : gen_note port map (board_clk, x"25084",e);
Fa : gen_note port map (board_clk, x"22F43",f);
Solflt: gen_note port map (board_clk, x"20FDE",gf);
Sol : gen_note port map (board_clk, x"1F23E",g);
Laflat: gen_note port map (board_clk, x"1D64A",af);
La : gen_note port map (board_clk, x"1BBE3",a);
Si : gen_note port map (board_clk, x"18B76",b);
Doktav: gen_note port map (board_clk, x"17544",co);
Rektav: gen_note port map (board_clk, x"14C8A",do);
ze <= ((cob(0) and cob(1) and cob(2) and cob(3) and cob(4) and cob(5)) or nreset);
cobze <= (cob(0) or cob(1) or cob(2) or cob(3) or cob(4) or cob(5));
rth <= t;
-- play <= "100000100000"; -- c/g
-- Maybe we should use integer rather then std_vector????
process (t)
begin
if (rising_edge(t)) then
-- Counter Part
if (ze = '1') then
cob <= "000000"; -- Could be a problem.
else
cob <= cob + 1;
end if;
if (cobze = '0') then
play <= "000000000000";
end if;
-- 00: French Anthem
if ((sct(0) or sct(1)) = '0') then
if (cob < 8) and (0 < cob) then
play <= "000000100000"; -- g
elsif (cob < 16) then
play <= "000000001000"; -- a
elsif (cob < 22) then
play <= "000000000001"; -- do
elsif (cob < 24) then
play <= "000000000100"; -- b
elsif (cob < 28) then
play <= "000000100000"; -- g
elsif (cob < 30) then
play <= "000000000100"; -- b
elsif (cob < 32) then
play <= "000000100000"; -- g
elsif (cob < 36) then
play <= "000100000000"; -- e
elsif (cob < 44) then
play <= "000000000010"; -- co
elsif (cob < 46) then
play <= "000000001000"; -- a
elsif (cob < 48) then
play <= "000000000100"; -- b
elsif (cob < 64) then
play <= "000000100000"; -- g
end if;
end if;
-- 01: German Anthem
if ((not(sct(0)) or (sct(1))) = '0') then --
if (cob < 12) and (0 < cob) then
play <= "001000000000"; -- ef
elsif (cob < 16) then
play <= "000010000000"; -- f
elsif (cob < 24) then
play <= "000000100000"; -- g
elsif (cob < 32) then
play <= "000010000000"; -- f
elsif (cob < 40) then
play <= "000000010000"; -- af
elsif (cob < 48) then
play <= "000000100000"; -- g
elsif (cob < 54) then
play <= "000010000000"; -- f
elsif (cob < 56) then
play <= "010000000000"; -- d
elsif (cob < 64) then
play <= "001000000000"; -- ef
end if;
end if;
-- 10: Russian Anthem
if ((sct(0) or not(sct(1))) = '0') then
if (cob < 4) and (0 < cob) then
play <= "000000100000"; -- g
elsif (cob < 12) then
play <= "000000000010"; -- co
elsif (cob < 16) then
play <= "000000100000"; -- g
elsif (cob < 20) then
play <= "000000001000"; -- a
elsif (cob < 28) then
play <= "000000000100"; -- b
elsif (cob < 44) then
play <= "000100000000"; -- e
elsif (cob < 48) then
play <= "000000100000"; -- g
elsif (cob < 52) then
play <= "000010000000"; -- f
elsif (cob < 60) then
play <= "000000100000"; -- g
elsif (cob < 64) then
play <= "100000000000"; -- g
end if;
end if;
-- 11: Romanian Anthem
if ((sct(0) and (sct(1))) = '1') then
if (cob < 6) and (0 < cob) then
play <= "000100000000"; -- e
elsif (cob < 8) then
play <= "000001000000"; -- gf
elsif (cob < 12) then
play <= "000000100000"; -- g
elsif (cob < 16) then
play <= "000000001000"; -- a
elsif (cob < 24) then
play <= "000000000100"; -- b
elsif (cob < 32) then
play <= "000100000000"; -- e
elsif (cob < 38) then
play <= "000000000010"; -- co
elsif (cob < 40) then
play <= "000000000100"; -- b
elsif (cob < 48) then
play <= "000000001000"; -- a
elsif (cob < 54) then
play <= "000000000001"; -- do
elsif (cob < 56) then
play <= "000000000010"; -- co
elsif (cob < 64) then
play <= "000000000100"; -- b
end if;
end if;
end if;
end process;
tone <=
(c and play(11)) or (d and play(10)) or (ef and play(9)) or (e and play(8)) or (f and play(7))
or (gf and play(6)) or (g and play(5)) or (af and play(4)) or (a and play(3)) or (b and play(2))
or (co and play(1)) or (do and play(0));
end Behavioral;