Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to program a song in FPGA spartan 3

Status
Not open for further replies.

TCY02

Junior Member level 3
Joined
Mar 5, 2005
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,486
musica fpga spartan 3

how to program a song in FPGA spartan 3
any website to teach how to proram FPGA
 

fpga spartan 3 conmutation wave

Do you want it to sound like the London Philharmonic, or like a tacky birthday card? An FPGA can do both, although one of them is considerably easier.

Half of the fun of a project like this is dreaming up your own way of making it work. Start out by finding a song that has its note frequencies and durations listed in a table. Maybe put that table into a block RAM, and then step through the block RAM while feeding its data into a simple DDS frequency synthesizer and timer.

You have now applied high technology to making tacky birthday cards.
 

And for audio output, if you wish to have multiple-bits audio (ex: 8bit or 16bit audio) you can use multiple output lines to a DAC, or one or 2 single lines to a serial DAC, or even simple, no external DAC, by synthesizing a delta-sigma DAC (See XAPP154, applying it to Spartan-III).
 

which song is easy
then implement this
the question is how to program it in VHDL
 

I don't "program" in HDL. FPGA is hardware design. I visualize my project as a hardware block diagram. A counter here, a memory there, a couple of accumulators and multipliers here and there, a pinch of sequencing logic, etc. That's the fun creative part. Then I write HDL that implements those things. That's the drudgery part, because HDL was created by either a madman or a committee, I'm not sure which. ;)
 

You can extract sample vectors for let's say a raw music file, like .wav, it will give you the raw samples of the music, you can use matlab or write a C code to do this. Then store this data on a memory, and design a circuit that will play this samples acording to a sampling frequency and stuff, you need a DAC, filters and so on.
Also you can make a simple synthesizer, to generate some waveforms using FPGA.
 

The simplest way is to use a simple square wave, with frequency derived from the system clock.

You could have a ROM table with 2 entries per records, which are clock divider and length.

For example, if you have a 10MHz clock, and you want to create a 'song' with the following tones:

440Hz for 1 second
600Hz for 2 seconds
pause for 1 second
440Hz for 1 second

When, you create your table like this

10MHz/440Hz/2 = 11364, 10MHz*1 sec = 10 000 000 cycles
10MHz/600Hz = 8333, 10MHz*2 sec = 20 000 000 cycles
pause = 0, 10MHz*1 sec = 10 000 000 cycles
10MHz/440Hz = 11364, 10MHz*1 sec = 10 000 000 cycles

So, your table could be

(11364,10000000),(8333,20000000),(0,10000000),(11364,10000000).

Then, when you 'play' your song, you have a counter that count to the first number and toggle flip-flop when the number is reached, and start again. For example, taking 11364, you'll have 11364 clock cycles with a '0' output, and 11364 cycles with a '1' output, over and over. Thus, you'll have a period that last 22728 clock cycles. With 10M clock cycles per seconds, this give a period of 22 728/10 000 000 = 0.0022728seconds (or by using '1/x', 439.9859Hz).

And the 2nd value of the table, count that many clock cycles before switching to the next entry.

Above, we assumed a '0' being a pause. If a 0 is read, simply do not output sound. Detecting the end of song, or song length, is up to you.

Of course, you can apply the above with any input clock frequency. You can have higher clock frequency, and divider, for higher precision, but this is often not necessary. To save space, you could encode the 2nd number (delay) as a lower value number, which is multiplied by a constant, to give the delay.
This will give a monophonic sound (one channel) square wave. With a piezzo buzzer, this will sound like a birthday card.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top