1、9.10 乐曲演奏电路低音频 率 / Hz中音频 率 / Hz高音频 率 / Hz1 261.6 1 C 523.3 1 1046.52 293.7 2 D 587.3 2 1174.73 329.6 3 E 659.3 3 1318.54 349.2 4 F 698.5 4 1396.95 392 5 G 784 5 15686 A 440 6 880 6 17607 B 493.9 7 987.8 7 1975.5 音调控制预置计数器6MHz 二分频器 扬声器低音 6 6MHz / 2 / 440Hz = 68189365 + 6818 = 16383 音长控制全音符 1秒四分音符 4Hz
2、八分音符 8Hz 曲谱产生4Hz 音符显示 数码管9.22梁祝乐曲演奏电路/* clk50m 输入时钟, 50MHzspeaker 驱动扬声器的方波high, med, low 显示高,中,低音 */module song(clk50m, speaker, high, med, low);input clk50m;output reg speaker;output reg3:0 high, med, low;reg clk_6mhz; /产生音阶的基准时钟reg clk_4hz; /控制音长的时钟reg13:0 divider, origin; /分频计数 , 预置数wire carry; /
3、分频进位reg7:0 counter; /节拍计数reg2:0 count8; /分频计数reg19:0 count20; /分频计数/分频得到 6MHz时钟always (posedge clk50m)if(count8=7)begin count8=0; clk_6mhz=1; endelsebegin count8=count8+1; clk_6mhz=0; end/分频得到 4Hz时钟always (posedge clk_6mhz)if(count20=781250)begin clk_4hz= clk_4hz; count20=0; endelsebegin count20=count20+1; end/通过置数,改变分频比always (posedge clk_6mhz)if(divider=16383)begin carry=1; divider=origin; endelsebegin divider=divider+1; carry=0; end