Software

Home
Introduction
Design
Hardware
Software
Results
Conclusions

The trickiest part about the software was trying to understand what the UART was actually receiving from the keyboard.  We had to write our own test program that would take in about 10 bytes of MIDI and then would print them to HyperTerminal so we could see what was going on.  We were stuck for a long time because one of the schematics we found online had an inverter after the output of the optoisolator.  We would look at the output of the keyboard and not be able to decode any of the bytes it had printed out.  The inverter caused us to read the start bit at the wrong place and then the bytes become jumbled.  Once this problem was solved, mapping different keys to different notes was not very difficult. 

This state machine shows how our program works:

 

The main state is Status.  If a status byte is detected, we then go to state Key.  The next byte is corresponds to what key is played.  We then go to the velocity state.  The next byte corresponds to the velocity.  If this is zero then we have to turn off the note which key was pressed.  Otherwise we ignore this value.  Then our state machine goes back to Status to wait for another Status byte.  The other part of the state machine goes to Program state when the program keys are pressed.  This allows us to control what sine wave table we are using and therefore create different sounds.  We also added a memory later which stores the last 6 notes still being pressed.  Thus, if the current note being played is released, then the most recently pushed note is played.  This memory was also slightly tricky to write since we had to store all the recent keypresses in an array.  Every time a note was released, we would have to search the array and delete that keypress from the array.  If the array was too big, the for loop would take too much time and cause to program to crash.  If the array wasn't big enough, then the array would be out of index and the program would crash.  We eventually found a happy medium at 6 notes.

To create our sounds, we used Lab 5 from Spring 2002, ECE 476.  They showed us how to use Timer1 and a sine table to create sinusoidal waves which can then be outputted to a DAC. 

We tried to implement some things which eventually did not work.  We spent a few weeks trying to come up with a way to account for multiple notes.  We knew we would have to change the way we produced sounds.  To produce a single note we were making a sine wave of the correct frequency.  To make multiple notes we knew we had to make all the notes based on the same frequency and find a way to add them together.  Unfortunately, we were force to give up, otherwise we would not have finished our project.  We also wanted to find a way to transpose the keys, but then we found that the keyboard we were using could already do this internally. 

 

 

Home | Introduction | Design | Hardware | Software | Results | Conclusions

 Copyright 2003
For problems or questions regarding this web contact gsh7@cornell.edu.
Last updated: 05/01/03.