module melody (
input wire clk,
input wire reset,
input wire enable
output reg speaker,
);
reg [17:0] counter;
reg [7:0] sequence;
reg [17:0] nte;
parameter C1 = 190839, D1 = 170068, E1 = 151515, // these are the notes that will be played
F1 = 142857, G1 = 127551, A1 = 113636,
B1 = 101214, C2 = 95419, D2 = 85034,
E2 = 75757, F2 = 71633, G2 = 63775,
A2 = 56818, B2 = 50607, C3 = 47801,
silence = 0;
initial
begin
counter =0;
end
always @(posedge clk) counter <= counter+1; //setting the counter
always @ (posedge clk)
case(sequence)//inputing the sequence of notes
1: nte = C2;
2: nte = D2;
3: nte = E2;
4: nte = C2;
5: nte = C2;
6: nte = D2;
7: nte = E2;
8: nte = C2;
9: nte = E2;
10: nte = F2;
11: nte = G2;
12: nte = silence;
13: nte = E2;
14: nte = F2;
15: nte = G2;
16: nte = silence;
17: nte = G2;
18: nte = A2;
19: nte = G2;
20: nte = F2;
21: nte = E2;
22: nte = silence;
23: nte = C2;
24: nte = silence;
25: nte = G2;
26: nte = A2;
27: nte = G2;
28: nte = F2;
29: nte = E2;
30: nte = silence;
31: nte = C2;
32: nte = silence;
33: nte = D2;
34: nte = silence;
35: nte = G1;
36: nte = silence;
37: nte = C2;
39: nte = silence;
40: nte = D2;
41: nte = silence;
42: nte = G1;
43: nte = silence;
44: nte = C2;
45: nte = silence;
default: div=silence;
endcase
reg [15:0]count;
always @(posedge clk)
speaker <= (count == frequency);
begin //this is to play the notes after eachother
if(reset)
sequence <= 0;
else
sequence <= sequence + 1'b1;
//keeps moving to the next note
always @ (posedge clk)
begin COUNTER //block using clock and enable to get each note to be played for 0.6 seconds and paused for 0.2
if (reset == 1'b1) begin
speaker <= #1 4'b0000
end
elseif (enable == 1'b1) begin
speaker <= #1 speaker + 1;
end
end
end