fpga4fun.comwhere FPGAs are fun

Music box 4 - A tune

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));

We also want that
so we change the last line of the previous design from
always @(posedge clk) if(counter_note==0 && counter_octave==0) speaker <= ~speaker;

into
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?

That's it folks. Hope it was fun.



Links