For our final project in Computer Architecture we decided to build an Field Programmable Gate Array Guitar. We used 8 switches on the FPGA, and defined the first seven as notes, each one corresponding to different frequencies, and the eighth button being the “strum” button, that triggers the corresponding notes one want to play. The frequencies varied from approximately 200Hz to 440Hz (note “A”).
Documentation on generating sound with FPGA can be found http://www.fpga4fun.com/MusicBox.html
We decided to build a FPGA guitar because we thought it would cool to create music with an instrument that we all hated at one point.
We created a controlSignalGen() module that determined the control signals generated. We followed a one-hot-encoding pattern, where the inputControl switches are 7-bit numbers that is given by the orientation of the switches. This 7 bit number determined the 3-bit ControlSignal which is inputted to the frequency Generator. The frequency generator takes in the 3 bit ControlSignal and matches up the one of the notes (A, B, C, D, E, F, G) that the switches corresponds to. The frequency generator then uses a lookup table to find the desired frequency. In order to create the frequency for A (440Hz) from the FPGA clock cycle, we can use a counter to count a certain clock cycle to create our desired frequency. For the note A, the clock divider will equal 50000000/440/2. This is because the clock runs at 50 MHz. We define a variable called counter that counts the number of positive edges for which the amplitude of the new signal will remain high. The counter is reset every time it reaches the value of the clock divider, which resets it, and flips the speaker signal. Therefore, we create the desired frequency signals of the notes we want to play, depending on what the ControlSignals say.
We have two different modes on the FPGA guitar. One mode for manually changing the note and strumming, and another for playing a preset song. We can switch the mode by pressing a button which is connected to an input conditioner. On the posedge of the button, we toggle between manual guitar and a song generator. We decided to make a finite state machine for the intro of Guns and Roses’s song Sweet Child of Mine. We created a separate frequency generator that took in the clock as an input and produced the correct frequency for the output. We created this module we wanted the frequency generator to be dynamic instead of only being able to produce 7 different sounds depending on what the ControlSignals say.
1. Download our code from https://github.com/runnersaw/FPGAGuitar. Many of the files in this repository are for testing; you can ignore these. The only file responsible for FPGA operation is topLevel.v.
2. Open Xilinx’s ISE Design Suite, and click New Project. Name this project anything you would like and save to any location on your computer.
3. Specify that this is for the Spartan3 family and XC3S1000 device and click Next. Then click Finish.
4. Right click in your project heirarchy and click Add Source… Then navigate to where you saved our topLevel.v file. Then click OK to import it.
5. Right click on topLevel.v and click Add Source… again. Then navigate to the directory containing topLevel.v and choose topLevel.ucf. Choose this. Make sure that topLevel.ucf appears in the dropdown below topLevel.v.
6. Double click Configure Target Device. This will synthesize, implement design, and generate programming file. If it throws any warnings at this point, ignore them. Then click Okay to open iMPACT.
7. Double click Boundary Scan. Make sure that the FPGA is plugged into the computer and then right click inside the window. Click on Initialize Chain.
8. Click Yes to continue, and navigate to the folder you chose at the beginning. Double click toplevel.bit, then click Bypass on the next window. Then click OK.
9. Right click on the portion that says “toplevel.bit” and click program. You’re good to go!
Notes about using the FPGA guitar. When on manual mode, use switches 7 through 1 to select your note. Only one of these switches can be on, otherwise the guitar will not play a note. Then, “strum” on switch 0 to change the note. Operation should move like: choose note, strum, repeat. To switch to and from “Sweet Child O’ Mine” mode, press button 0.
Some of the difficulties that you might face while replicating this project is finding a working speaker. We spent a chunk of time scavenging for a functioning speaker to finally test our code on the FPGA. None of the members in our team were very skilled in mounting the Xilinx code on the FPGA so we spent some time trying to figure out how to fix the errors.
Our work flowed well. Our simplest iteration, which was just a strummable sound maker, was achievable. Luckily, we worked quickly enough that we were able to achieve one of our reach deliverables, which was an automated playing mode. This consisted of allowing users to press a button so that the FPGA would play a preset song.