EENG 383

Lab 12 - Hall effect with MIDI

Lab: 12
Status Live

InLab 12

Some self guided activities.

Lab 12 assignment

Create an embedded system that allows you to produce a consectutive MIDI piano notes of a song whenever the piano key is pressed. While the piano key is held down, sustain the note and when the piano key is released, the note should end. When the end of the song is reached, start over from the begining.

Software

I would advise you to write your program incrementally using the inLab code as a starting point. The main menu is a good starting point

You program will rely on the timer 0 ISR to acquire Hall effect samples. I have diagramed the behavior of the ISR in the following state diagram, reference it in the following discussion.


The ISR is "called" every time that TMR0 rolls over. You should configure this to happen every millisecond. The ISR will use a combination of local, static and global variables to do its work. The diagram shows four key global variables and who read and writes their value by the direction of the arrow. The arrow leaving "nominalUnPressed" means that main writes this value and that the ISR reads this value.

At any given time, the ISR will be in one of three states, UNPRESSED, PRESSSED_ACQUIRE and PRESSED_WAIT. Regardless which state the ISR is in, just before exiting, the ISR should start a conversion so that it has a fresh ADC value when it next runs in one millisecond.
UNPRESSED
This state means that the piano key has not been pressed. In this state the ISR reads the Hall effect output through the ADC once every ISR call. If the Hall effect sensor value drops below (nominalUnPressed - delta) then the ISR chages the keyState to PRESSED_ACQUIRE and sets the number of ADC samples collected to 0.
PRESSED_ACQUIRE
This state means that the piano key is in the process of being pressed. In this state each ISR invocation stores one Hall effect output into the hallSample global array and increments the number of samples collected. After N invocations of the ISR in this state, the hallSamples array is full, so the ISR changes keyState to PRESSED_WAIT. The ISR needs to exit after acquiring one sample - do not include a for-loop in this section of the ISR that iterates N times and on each iteration acquires a sample and wait 1ms!
PRESSED_WAIT
This state means that the piano key has been pressed and has yet to be released. Evey ISR invocation in this state reads the Hall effect sensor output and checks if it has returned to its unpressed level. In otherwords, the Hall effect sensor output is greater or equal to nominalUnPressed - delta.
The image below shows an excel plot of a piano key press and release as the blue plot. The dark red horztional line is the value of nominalUnPressed - delta. The light red horztional line is the value of nominalPressed + delta. If the ISR were to see this key press event, its state would change as shown. Note that it takes 64 milliseconds to fill the hallSamples array in my program (64 samples taken at 1 millisecond intervals).


Main will be monitoring the keyState global variable. When this variable is equal to PRESSED_WAIT, then the hallSamples array is filled up. Let N be the length of the hallSamples array. Main should compute the velocity of the piano key press as follows. For example, in the image below:


At start-up your program should present a splash screen - this would be a great place for some ascii art. The splash screen should also contain connection instruction for the development board; for this assignment tell the user there are no jumpers to install! When you press "?" at the terminal you should be greeted with the following menu. Oh, and you should run the terminal interface at 115,200 baud for quick bongo response time.
-------------------------------------------------
    Nominal 79 to 29
    delta = 5
    sampleRate = 2000us
-------------------------------------------------
?: help menu
o: k
Z: Reset processor.
z: Clear the terminal.
d/D: decrement/increment delta
c/C: calibrate unpressed/pressed hall sensor.
t: determine strike time with 64 samples, once every 2000us.
T: strike indicator and time
i: ISR values
M: enter into Midi mode.
-------------------------------------------------