蜂鸣器篇的作业:蜂鸣器发出警车声音
这是实验现象:http://v.youku.com/v_show/id_XNzI4MDYzMDgw.html
想法:救护车的声音只是两个频率的变化的。如http://play.baidu.com/?__m=mboxCtrl.playSong&__a=2000100377&__o=/song/2000100377||playBtn&fr=-1||www.baidu.com#loaded。而警车色声音貌似有许多种,最简单的一种是频率周期性变化的。如http://www.9ku.com/play/549980.htm
这是实验现象:http://v.youku.com/v_show/id_XNzI4MDYzMDgw.html
/**************************************************************************
*Engineer: superdian
*Create Date: 2014/6/17
*Design Name: BEEP
*Module Name: BEEP
*Project Name: BEEO
*Target Devices: EP3CE5E144C8
*Tool versions:
*Description: 蜂鸣器发出警车声音
******************************************************************************/
module BEEP(sys_clk,beep);
//定义输入输出信号
input sys_clk;
output beep;
//定义几个寄存器
reg beep;
reg[22:0] counter1;
reg[13:0] counter2;
always@(posedge sys_clk)
begin
counter1<=counter1+1;
end
//让发声频率在适当范围内改变
wire[6:0] rate=(counter1[22]?counter1[21:15]:~counter1[21:15]);
wire[13:0] clkdivider={1'b1,rate,6'h000000};
always@(posedge sys_clk)
if(counter2==0)
counter2<=clkdivider;
else counter2<=counter2-1;
always@(posedge sys_clk)
begin
if(counter2==0)
beep<=~beep;
end
endmodule