音乐播放器实验报告(song_reader已验证).docx
文本预览下载声明
乐曲读取模块song_reader的设计任务:根据mcu模块要求,选择播放乐曲;响应note_palyer模块请求,从song _rom中逐个取出音符{note,duration}送给note_player模块播放;判断乐曲是否播放完毕,若播放完毕则回复给mcu。song_reader的结构框图地址计数器模块moduleaddress_counter(clk,note_done,reset,q,co);inputclk,note_done,reset;outputreg[4:0] q;output co;assign co=(q==5b11111)note_done;always@(posedgeclk)beginif(reset) q=5b0;elseif(note_done) q=q+1;else q=q;endendmodule结束判断模块moduleend_judger(duration,clk,co,song_done);input [5:0] duration;inputclk,co;outputsong_done;wiresong_done_temp;assignsong_done_temp=(duration==0)||co;one_pulseone_pulse_a( .clk(clk), .in(song_done_temp), .out(song_done));endmodulesong_rom(代码已提供)D_FFR module D_FFR (d, r, clk, q);parameter WIDTH = 1;input r;inputclk;input [WIDTH-1:0] d;output [WIDTH-1:0] q;reg [WIDTH-1:0] q;always @ (posedgeclk) if ( r ) q = {WIDTH{1b0}};elseq = d;endmodulesong_reader控制器根据流程图,使用一段式状态机写出代码module controller_of_song_reader(clk,reset,note_done,play,co,q,duration,new_note);inputclk,reset,note_done,play,co;input [4:0] q;input [5:0] duration;outputnew_note;reg[1:0] state;regnew_note;parameter RESET=2b00,NEW_NOTE=2b01,WAIT=2b10,NEXT_NOTE=2b11;always@(posedgeclk)beginif(reset) beginstate=RESET;new_note=0;endelsecase(state) RESET:beginif(play) begin state=NEW_NOTE; new_note=1;endelse begin state=RESET;new_note=0;endend NEW_NOTE: begin state=WAIT;new_note=0;endWAIT:beginif(play)if(note_done) begin state=NEXT_NOTE;new_note=0;endelse begin state=WAIT;new_note=0;endelse begin state=RESET;new_note=0;endendNEXT_NOTE:begin state=NEW_NOTE;new_note=1;endendcaseendendmodule ( 6 ) song_reader顶层代码module song_reader(song,clk,reset,note_done,play,duration,note,song_done,new_note);input wire[1:0] song;inputclk,reset,play,note_done;output wire[5:0] note,duration;outputsong_done,new_note;wire[4:0] q;wire co;address_counter address_counter_a(.clk(clk),.reset(reset),.note_done(note_done),.q(q),.co(co));song_romsong_rom(.clk(clk),.addr({song,q}),.dout({note,duration}));end_judgerend_judger_a(.duration(duration),.clk(clk),.c
显示全部