音符对照表
音名 | 频率(Hz) | 半周期(us) | 12MHz分频系数 | 音名 | 频率(Hz) | 半周期(us) | 12MHz分频系数 | 音名 | 频率(Hz) | 半周期(us) | 12MHz分频系数 |
---|
低音1 | 261.63 | 1911 | 22932 | 中音1 | 523.25 | 956 | 11472 | 高音1 | 1046.5 | 478 | 5736 |
低音2 | 293.66 | 1703 | 20436 | 中音2 | 587.33 | 851 | 10212 | 高音2 | 1174.66 | 426 | 5112 |
低音3 | 329.63 | 1517 | 18204 | 中音3 | 659.25 | 758 | 9096 | 高音3 | 1318.51 | 379 | 4548 |
低音4 | 349.23 | 1432 | 17184 | 中音4 | 698.46 | 716 | 8592 | 高音4 | 1396.91 | 358 | 4296 |
低音5 | 392 | 1276 | 15312 | 中音5 | 783.99 | 638 | 7656 | 高音5 | 1567.98 | 319 | 3828 |
低音6 | 440 | 1136 | 13632 | 中音6 | 880 | 568 | 6816 | 高音6 | 1760 | 284 | 3408 |
低音7 | 493.88 | 1012 | 12144 | 中音7 | 987.77 | 506 | 6072 | 高音7 | 1975.53 | 253 | 3036 |
原理图
代码实现
module music(sel,clock_12MHz,clock_8Hz,speak);
input sel,clock_12MHz,clock_8Hz;
output speak;
reg [14:0]quti;
reg [4:0]mic;
reg [7:0]music_mem;
always @(posedge clock_8Hz)
clk_4Hz<=~clk_4Hz;
always @(posedge sel or negedge sel)
music_mem<=0;
always @(posedge clk_4Hz)
begin
if (sel)
begin
if(music_mem==total_long)
music_mem<=0;
else
music_mem<=music_mem+1;
case(music_mem)
'd0:mic<='d1;
'd1:mic<='d2;
'd2:mic<='d3;
'd3:mic<='d4;
default:mic<=0;
endcase
end
else
begin
if(music_mem==total_long)
music_mem<=0;
else
music_mem<=music_mem+1;
case(music_mem)
'd0:mic<='d1;
'd1:mic<='d2;
'd2:mic<='d3;
'd3:mic<='d4;
default:mic<=0;
endcase
end
end
always @(mic)
begin
case(mic)
'd0:quti<=0;
'd1:quti<=22932;
'd2:quti<=20436;
'd3:quti<=18024;
'd4:quti<=17184;
'd5:quti<=15312;
'd6:quti<=13632;
'd7:quti<=12144;
'd8:quti<=11424;
'd9:quti<=10212;
'd10:quti<=9096;
'd11:quti<=8592;
'd12:quti<=7656;
'd13:quti<=6818;
'd14:quti<=6072;
'd15:quti<=5736;
'd16:quti<=5112;
'd17:quti<=4548;
'd18:quti<=4296;
'd19:quti<=3828;
'd20:quti<=3408;
'd21:quti<=3036;
default:quti<=0;
endcase
end
always @(clock_12MHz)
begin
if(count==quti)
begin
count<=0;
speak<=~speak;
end
else
begin
count<=count+1;
end
end
endmodule