Introduction: Blues Piano Using Terasic DE2-115 Development Board
This piano plays the notes of a D flat blues scale. The piano uses an eight key keyboard for inputs and displays whatever note is being played using the Terasic boards' seven segment displays. The notes are played over a speaker connected through a 9mm jack. The piano can only play one note at a time. Watch the above video for a demonstration of the piano.
Step 1: Materials
The following materials will be needed to complete the project.
1. Eight pushbutton switches
2. Eight 2kΩ resistors or eight resistors of similar resistance
3. Eight 0.022μF capacitors (optional)
4. One or Two 10μF capacitors
5. 9mm audio jack
6. DE2-115 Terrasic development board
7. 40 pin breakout ribbon cable
8. Bread board
9. Lots of wires
10. Quartus II software
Step 2: Setting Up the Hardware
Connect the Terasic De2-115 development board to a standard breadboard using a 40 pin ribbon cable with a header connector. The above pin planner is for the header connector .
The above circuit diagram explains the circuit that is to be constructed.
The high voltage pin and the ground pin can be seen on the above pin planner.
Place the eight push button switches on the breakout breadboard.
Connect the push button switches to inputs to the eight inputs to the Terasic development board. The inputs will be the pins GPIO 5,7,9,11,13,15,17,19 on the 40 pin header connector and are denoted by In1-8 on the circuit diagram.
Place the eight 2kΩ pull up resistors in between a high voltage line and the eight push button switches on the same nodes that are already connected to the header connector. The resistors are denoted as R1 - R8 on the circuit diagram. They will act as pull up resistors, pulling the inputs high when the push button switches are open. This design keeps the inputs from entering a high impedance state.
Connect the other side of the push button switches to the ground wire.
Place the eight 0.022μF capacitors in between the terminals of the push button switches. This will help even out the input signal.
Connect the left and right input pins of the 9mm audio jack together. This will make the audio jack mono as apposed to stereo. Connect the ground. Connect the input pin to pin GPIO 25 on the expansion header which is denoted by 'Speaker In' on the circuit diagram. Place the two 10μF capacitors in between the input pin and the ground pin. These will alter the square waveform from the Terasic board into a sinusoidal waveform. Playing around with the values of these two capacitors will give the piano different sounding notes.
Step 3: Implementing the Verilog Code
The code for this project is written in Verilog using the Quartus II version 15.0 programming environment.
Start a new project specify the chip as the Cyclone IV EP4CE115F29C7.
Copy the code from the above files.
Copy the pin assignments from the above image.
Explanations of the code will be explained in the coming steps.
Step 4: Some Ideas for Future Work
Future Work on this project can go in two main directions, although there are certainly others. The onboad flash memory could be used to store music files witch could then be played. Music files could either be uploaded using a computer or entered directly using the Terasic development Board.
Instead of playing one single tone at a time the project could play multiple tones at the same time by either using an op amp circuit or by tying inputs together using capacitors. Tying inputs together would certainly be easier but using an op amp would allow the project to control the volumes of the different tones being played.
Step 5: Module Break Down
This step and the next seven steps are purely informative. They will simply explain the verilog code and musical theory for future development of the project.
Shown above is a block diagram of the Verilog modules that controls the piano. A main method is the central piece of this function essentially operating as the central nervous system of our project. To avoid overlapping signals from the buttons we used a priority encoder to take in the input, implemented in the keyboard module. In order to generate the tones we first will modify the 50 MHz clock on the Altera board using the Phase Lock Loop also on the board. Then we will proceed by taking the modified clock and then we will use a clock divider to divide the now modified clock by powers of 2, this occurs in the clock scheme array module. Once we have produced the desired tones we will take the input from the buttons to decide which tone is sent to the speaker. The tones then get output as a square waveform to the audio jack where we can here them as lovely music. The following steps are intended to illuminate the functions of the modules within the code.
Step 6: Module: Main
This module is the general control
module. All other modules are called from this module. This module has a minimal amount of direct implementation of logic gates and instead calls other modules and routes signals in between them.
The inputs to this module are ‘rawclk’ which is the 50 MHz clock signal (PIN_Y2) and ‘keys’ which is an array of 8 buttons that are inputted from the expansion header to the breakout bread board. The output ‘speaker’ is the line that goes to the audio jack which is also on the breakout bread board. This line has a capacitor that alters the signal from a rectangular waveform to a sine waveform. The output hex1 and hex2 are 7 bit arrays that are connected to seven segment displays on the DE2 board. They will display which note is being played at a given time. The wire ‘statevalue’ is a binary representation of which note is currently being played. The wire ‘gkeys’ is an array that is the compliment of ‘keys’.
This module calls the module ‘keyboard’ to determine which note, if any, should be played and passes this information on to ‘sevsegdiaplay’ and ‘tonemaker’.
Step 7: Module: Tone Maker
This module processes the binary signal from the ‘keyboard’ module and outputs a sound signal. The module ‘clockschemearray’ is called to produce multiple signals of rectangular waveform with frequencies that are proportional to specific notes. The module then uses an ‘always’ statement in conjunction with ‘if/else’ statements to decide which signal from the produced signals to play through the speaker. The decision is made based on the binary signal from the ‘keyboard’ module.
Step 8: Module: Clock Scheme Array
This module produces a series of arrays with the elements of said arrays being signals of rectangular waveform with frequencies that give musical notes. This module uses multiple phase lock loops (PLL) to alter the 50MHz clock input signal into several signals of specific frequency. The individual signals of specific frequency from the PLLS can then be divided by powers of two using a counter to give the frequency of a desired note. This is then done once for each different musical note. The specific frequencies can be found using the following formula.
This formula is derived from the following equation shown above.
Where ‘n’ is any integer value. The value of ‘n’ is chosen so that the Output of the PLL is close to the frequency of the input clock. The given code has PLL outputs close to 10 MHZ. The frequency of the desired note can be the frequency of any note. The following table shown above illustrates the frequency’s used in the given code.
The PLL can be implemented using the library’s that come with the Quartus II software. Each PLL onboard can provide up to five output clock signals. To divide the clock signals by two a 32 bit counter module is implemented. Differences of octaves are simply powers of two in frequency, therefore it is only necessary to implement one output of a PLL per musical note even if you would like to use octaves of this note.
In the given code the 32 bit arrays clkarray0 – clkarray5 are outputs containing arrays with each element being a rectangular waveform. Each array is for a single musical note with each element being the frequency for a different octave of that note.
To make this module implement different music notes find the frequencies of the musical notes that are to be played. Use the above mentioned formulas to find output frequencies of the PLLs for the selected musical notes. The IP catalog that comes with the Quartus II software environment can be used to implement a PLL with the output frequency of the selected musical notes. Go into the code and replace one of the current PLL module calls with a module call for your PLL. The code may need to be modified slightly if you do not have the same number of output clocks as the current PLL modules.
It should be noted the PLL was designed with the board and not by us.
Step 9: Module: Upcounter
There is an up counter implemented to half a frequency given to it. This is used in junction with the PLL to create specific frequencies. The initial frequency all of these are based off of is the Altera board's clock, which runs at 50 MHz. The frequency produced by the up counter is made by counting when the given frequency goes from low to high (positive edge). This will half the frequency as the initial frequency this is based off of is the clock, which has positive edges on equal time intervals. The actual circuit of this is a 32 bit asynchronous up counter. It is made with 32 D Latches wired serially.
Step 10: Module: Keyboard
The notes being played are displayed on two on board seven segment displays. The module takes in the note as a 4 bit binary value between 0 and 7 and returns two 7 bit arrays of binary values that each correspond to a light on the 7 segment display. See above photo for reference . One array displays the note letter and the other returns the accidental (whether the note is flat, natural or sharp). Both values are defaulted to all 1 which displays blank. The rest are set to our predetermined notes. We use Altera's standard for which value corresponds to each light in the display, which can be found in the DE2-115 User Manual.
Step 11: Module: Seven Segment Display
The notes being played are displayed on two on board seven segment displays. The module takes in the note as a 4 bit binary value between 0 and 7 and returns two 7 bit arrays of binary values that each correspond to a light on the 7 segment display. One array displays the note letter and the other returns the accidental (whether the note is flat, natural or sharp). Both values are defaulted to all 1 which displays blank. The rest are set to our predetermined notes. We use Altera's standard for which value corresponds to each light in the display.
Step 12: Some Notes on Music Theory
The scale that is programmed on the piano is the minor blues scale. This scale is used in many songs across genres, but especially in rock and blues (hence the name). It is made from the 1st, 3rd, 4th, 5th and 7th positions of the Aeolian (natural minor) scale with a flat 5 added.
This scale is taught to many musicians beginning to learn to improvise since it is easy to make melodies that sound good on it. This lends itself well to our project, since we wanted it to be used without a knowledge of music theory or even not being able to play an instrument.
Step 13: References
 DE2-115 User Manual, Terasic, HsinChu, Taiwan, 2010, pp. 37, 47.
We have a be nice policy.
Please be positive and constructive.