User Tools

Site Tools


2014:fpga_piano_drums

This is an old revision of the document!


FPGA Chiptunes

For our project, we programmed a Field Programmable Gate Array (FPGA) with Verilog that allowed a person to use the eight built-in switches as a keyboard and the four built-in buttons as a drum pad. This was written specifically for the [insert model name here] FPGA, so slight code changes may need to be made if you have a different one.

Verilog Modules

Clock Divider

The first module that we made was a clock divider. This allowed us to slow down the built-in clock of the FPGA to audible frequencies. For reference, our FPGA's default clock frequency was 50MHz while humans can only hear up to about 20kHz. We used this website as a reference to ensure that we were upholding good practices such as not gating the clock. We instantiated eight of these modules to get square waves of eight different frequencies (we chose frequencies that made a G Major scale starting on G4). These eight square waves could then be ANDed with the eight switched on the FPGA board, and the results output through eight different General Purpose Input/Output (GPIO) pins.

Linear Feedback Shift Register

In order to make drum beat sounds, we needed to create random (or rather pseudorandom) noise. We did this by creating a Linear Feedback Shift Register (LFSR) module. An LFSR is a shift register whose serial input bit is the result of XORing a specific selection of its other bits, and it created a pseudorandom sequence of numbers with a certain period. Here is a reference if you would like to learn more about LFSRs. The way that we used an LFSR to generate noise sounds was to shift the bits of the LFSR at a specific frequency and look at the serial output bit. Each of the four buttons was ANDed with the output of an LFSR that was shifting its bits at a different frequency, and the result was put through an additional four GPIO pins.

Circuit

In order to use a single speaker for all twelve possible signals, we used a non-inverting summing amplifier circuit that we found here. The circuit diagram from that webpage is shown below. Our circuit differed in that we had twelve inputs rather than three. We used an LM386N-1 low voltage audio power amplifier, but just about any operational amplifier should work. Our power rails for the amplifier were +5V and 0V from a benchtop power supply. For our resistors, R = R1 = R2 = … = R12 = 1kΩ and Rf = 200Ω. Finally, we connected the output of the amplifier to one lead of an 8Ω speaker, and the other lead was connected to ground.

2014/fpga_piano_drums.1418787974.txt.gz · Last modified: 2014/12/16 22:46 by jkingery