⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 music_ambulance_siren.v

📁 基于FPGA的VHDL编程实现各种音频信号
💻 V
字号:
// music_ambulance_siren.v   //救护车汽笛
/**********************************************************************
Let's alternate 2 tones. We first use a 24 bits counter "tone" to produce 
a slow square wave. The MSB bit (tone[23]) toggles with a frequency of about 1.5Hz.
Then we use this bit to switch between 2 frequencies for the main counter,
 and that alternates between the 2 tones. Here comes the ambulance!

**********************************************************************/

module music_ambulance_siren(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 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -