在本节中,我们增加一个拨码开关做控制,让拨码开关的ON或OFF状态相应的去控制蜂鸣器的发声与不发声。下面一起来学习一下
2021-11-08 23:03:52 69KB FPGA 蜂鸣器 开关电路 文章
1
将《练习》简谱数据提取出,装入寄存器(存储器),在FPGA(我用的是EP2C5Q208C8)及时钟的控制下不断提取存储器中的数据,用蜂鸣器演奏。蜂鸣器必须是无源蜂鸣器。
2021-05-25 08:46:13 874KB FPGA、蜂鸣器
1
用VHDA语言控制FPGA实现蜂鸣器的音乐演奏
2021-05-05 22:45:47 595KB FPGA
1
FPGA设计控制蜂鸣器播放音乐实验的Verilog逻辑源码Quartus工程文件+文档说明,根据简谱不同简谱名频率让蜂鸣器发出不一样的响声,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module music_top ( input clk, input rst_n, input key1, output reg buzzer ) ; parameter CLK_FRE = 50 ; parameter music_len = 32'd78 ; wire [19:0] cycle ; reg [31:0] play_cnt ; reg [31:0] music_cnt ; reg [19:0] hz_cnt ; wire [4:0] hz_sel ; wire [7:0] rom_hz_data ; wire [7:0] rom_time_data ; reg [31:0] music_time ; wire button_negedge ; parameter IDLE = 2'd0 ; parameter PLAY = 2'd1 ; parameter PLAY_WAIT = 2'd2 ; parameter PLAY_END = 2'd3 ; reg [1:0] state ; reg [1:0] next_state ; always @(posedge clk or negedge rst_n) begin if (~rst_n) state <= IDLE ; else state <= next_state ; end always @(*) begin case(state) IDLE : begin if (button_negedge) next_state <= PLAY ; else next_state <= IDLE ; end PLAY : begin if (play_cnt == music_time) next_state <= PLAY_WAIT ; else next_state <= PLAY ; end PLAY_WAIT : begin if (music_cnt == music_len - 1) next_state <= PLAY_END ; else next_state <= PLAY ; end PLAY_END : next_state <= IDLE ; default : next_state <= IDLE ; endcase end ax_debounce ax_debounce_a0 ( .clk (clk), .rst (~rst_n), .button_in (key1), .button_posedge (), .button_negedge (button_negedge), .button_out () ); //play counter always @(posedge clk or negedge rst_n) begin if (~rst_n) music_time <= 32'hffff_ffff ; else music_time <= rom_time_data*(CLK_FRE*1000000/8) ; end //counter in every step, maximum value is cycle always @(posedge clk or negedge rst_n) begin if (~rst_n) hz_cnt <= 20'd0 ; else if (state == PLAY || state == PLAY_WAIT) begin if (hz_cnt == cycle - 1) hz_cnt <= 20'd0 ; else hz_cnt <=