Let's play a tune now!
It's easy, just a matter of using a ROM to hold the notes.
// use a counter to go through a ROM containing the notes of a little tune that we want to play reg [30:0] tone; always @(posedge clk) tone <= tone+1; wire [7:0] fullnote; music_ROM ROM(.clk(clk), .address(tone[29:22]), .note(fullnote)); |
always @(posedge clk) if(counter_note==0 && counter_octave==0) speaker <= ~speaker; |
always @(posedge clk) if(counter_note==0 && counter_octave==0 && tone[30]==0 && fullnote!=0) speaker <= ~speaker; |
The rest of the design stays the same.
The complete source is available here.
Can you recognize the tune?