FPGA 喇叭不同音節控制

2021-09-24 17:44:21 字數 2663 閱讀 6792

fpga乙個引腳控制喇叭發聲   25mhz

專案一、發出乙個單音 嗶嗶

module music(clk, speaker);

input clk;

output speaker;

// 16位計數

reg [15:0] counter;

always @(posedge clk) counter <= counter+1;

//計數器高位設定喇叭

assign speaker = counter[15];

endmodule

專案二:設定發出固定頻率440hz聲音

「a」音符(440hz)        時鐘週期25000000/440=56818

56818/2=28408

module music(clk, speaker);

input clk;

output speaker;

reg [14:0] counter;

always @(posedge clk) if(counter==28408) counter<=0; else counter <= counter+1;

reg speaker;

always @(posedge clk) if(counter==28408) speaker <= ~speaker;

endmodule    

公升級module music(clk, speaker);

input clk;

output speaker;

parameter clkdivider = 25000000/440/2;

reg [14:0] counter;

always @(posedge clk) if(counter==0) counter <= clkdivider-1; else counter <= counter-1;

reg speaker;

always @(posedge clk) if(counter==0) speaker <= ~speaker;

endmodule

專案三、兩個音交替切換

module music(clk, speaker);

input clk;

output speaker;

parameter clkdivider = 25000000/440/2;

reg [23:0] tone;

always @(posedge clk) tone <= tone+1;

reg [14:0] counter;

always @(posedge clk) if(counter==0) counter <= (tone[23] ? clkdivider-1 : clkdivider/2-1); else counter <= counter-1;

reg speaker;

always @(posedge clk) if(counter==0) speaker <= ~speaker;

endmodule

專案四、警笛音

module music(clk, speaker);

input clk;

output speaker;

reg [22:0] tone;

always @(posedge clk) tone <= tone+1;

wire [6:0] ramp = (tone[22] ? tone[21:15] : ~tone[21:15]);

wire [14:0] clkdivider = ;

reg [14:0] counter;

always @(posedge clk) if(counter==0) counter <= clkdivider; else counter <= counter-1;

reg speaker;

always @(posedge clk) if(counter==0) speaker <= ~speaker;

endmodule

專案五、完整警笛音

module music(clk, speaker);

input clk;

output speaker;

reg [27:0] tone;

always @(posedge clk) tone <= tone+1;

wire [6:0] fastsweep = (tone[22] ? tone[21:15] : ~tone[21:15]);

wire [6:0] slowsweep = (tone[25] ? tone[24:18] : ~tone[24:18]);

wire [14:0] clkdivider = ;

reg [14:0] counter;

always @(posedge clk) if(counter==0) counter <= clkdivider; else counter <= counter-1;

reg speaker;

always @(posedge clk) if(counter==0) speaker <= ~speaker;

endmodule

always @(posedge clk) if(counter_note==0) counter_note <= clkdivider; else counter_note <= counter_note-1;

FPGA控制不其他晶元

1 本節目錄 2 本節引言 3 fpga簡介 4 fpga控制不其他晶元 5 結束語。不積跬步,無以至千里 不積小流,無以成江海。就是說 不積累一步半步的行程,就沒有辦法達到千里之遠 不積累細小的流水,就沒有辦法匯成江河大海。fpga field programmable gate array 是在...

功放與喇叭如何選型(喇叭聲壓計算問題)

功放和喇叭匹配原則 5.1 功率匹配 常有人將功率放大器的額定功率與揚聲器的額定輸入功率等同起來,認為只有這兩個功率指標完全相同時,才稱為功率匹配。這種看法是片面的,它們是兩個完全不同的概念,不可混淆。功率放大器的額定輸出功率是指失真所限制的功率,超過這個輸出功率的電平,功放輸出將產生削波失真,必須...

控制PC喇叭發聲

pc喇叭發聲就是需要控制硬體的聲調和延時,讓其發出對應的聲音,可用來對外界產生測試聲音源。注意 使pc喇叭發聲是繞過音效卡的,也就是說就算計算機上沒有音效卡,該操作也可完成。1 新建乙個mfc對話方塊,並且安置七個按鈕,分別表示聲調的7個階,每個按鈕的操作函式如下 void cspeakerbeep...