[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>1.Simple beep
先做一个简单地蜂鸣器,原理是晶振通过不同的分频器分成不同的频率,通过电路发出音调不同的声音。
例子中Pluto
FPGA板子有25Mhz的时钟频率,采用16位计数器(可以产生65536个不同的数值),则最高位的频率是25000000/65536=381hz(通过计数器不同位数进行分频,产生不同的频率),例如第0位就是25Mhz/
2^0 =12.5Mhz…最高位就是以381hz的频率在0/1之间来回切换
实例代码如下:
module music(clk, speaker); input clk; output speaker; // first create a 16bit
binary counter reg [15:0] counter; always @(posedge clk) counter <= counter+1;
// and use the most significant bit (MSB) of the counter to drive the speaker
assign speaker = counter[15]; endmodule
现在产生的是381hz的声音
<>“A”的声音
A的声音频率是440hz,若要产生440hz的声音,则25000000/440 = 56818.18
则需要16位计数器到56817的时候重新开始计数,但对于32768(2^15)~ 56817
的占空比为42%(24049/56818),若要实现0.5占空比,最简单的方法是除以2(58818/2=28409),所以若要获得440hz的频率且具有0.5的占空比,需要在半个周期内(计数器为28409)将电平清零取反。
简单来说,晶振频率/时间 = 想要的频率
用计数器实现时间的确定,用计数的办法,也就是加法比如需要30%高电平,70%低电平,加到30取反清零,然后加到70再取反
代码如下:
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
<>救护车来了
救护车的音调为tone[23] 25000000/2^23 = 1.5hz
音调一致,两次响铃间隔时间来回交替,一个时间为clkdivider-1,一个为clkdivider/2
-1,也就是形成所谓的占空比,当tone[23]=1,维持时间为clkdivider-1,为0时维持时间clkdivider/2 -1,代码如下:
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