Friday, January 3, 2014

Playing the MIDI2VC with a MIDI device

A lot is working right now. I've made a look up table that translates MIDI keys to DAC programming values. I can now connect my computers USB2MIDI cable and play tunes using MIDIOX and the computer keyboard (not in tune though, I'll get back to that issue further down).  I had to modify two functions in the code to get this to work. One addition to the code is that "Note off", can be triggered with "Velocity" equals 0. I found that my MIDI keyboard signals note off that way, and MIDIOX does it with "0x80". So the code needs to support both ways. The modified code can be seen below:

1:  //***********************************************************  
2:  //**************Function processUARTSymbol*******************  
3:  //Checks to see if received UART symbol is 0x8X or 0x9X, or  
4:  //a symbol that follows one of those symbols  
5:  //The function puts 0x8X (or 0x9X) and it's following symbol  
6:  //in a two symbol buffer and then sends that buffer to  
7:  //function processUARTBuffer  
8:  //***********************************************************  
9:    
10:  void processUARTSymbol(int UARTSymbol) {  
11:    extern int UARTBufferCounter;  
12:    extern int UARTBuffer[];  
13:    
14:    //If symbol is MIDI "Note On"(0x9X) or MIDI "Note Off"(0x80),  
15:    //place symbol and it's following symbol in UART buffer  
16:    if (((UARTSymbol & 0xF0) == 0x80) || ((UARTSymbol & 0xF0) == 0x90)) {  
17:      UARTBufferCounter = 1;  
18:      UARTBuffer[0] = UARTSymbol;  
19:    } else if (UARTBufferCounter == 1) {  
20:      UARTBufferCounter = 2;  
21:      UARTBuffer[1] = UARTSymbol;  
22:    } else if (UARTBufferCounter == 2) {  
23:      UARTBufferCounter = -1;  
24:      UARTBuffer[2] = UARTSymbol;  
25:      processUARTBuffer(UARTBuffer);  
26:    }  
27:    
28:    return;  
29:  }  
30:    
31:    
32:  //***********************************************************  
33:  //**************Function processUARTBuffer*******************  
34:  //Interprets UARTBuffer, toggles LED and sends appropiate  
35:  //I2C data to DAC  
36:  //***********************************************************  
37:    
38:  void processUARTBuffer(int UARTBufferF[]) {  
39:    extern int i2cData[];  
40:    const int DACLookupTable[127] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x017,0x072,0x0C2,0x116,0x169,0x1B9,0x20C,0x25F,0x2B0,0x305,0x356,0x3A9,0x3FC,0x44D,0x4A2,0x4F5,0x547,0x5C7,0x5EF,0x63E,0x691,0x6E7,0x739,0x78E};  int DACValue;  
41:    int DACValue;  
42:    
43:    //If UART symbol is MIDI "Note on", light LED and  
44:    //send data to DAC  
45:    if (((UARTBufferF[0] & 0xF0) == 0x90) && (UARTBufferF[2] != 0x00) ) {  
46:    
47:      DACValue = DACLookupTable[UARTBufferF[1]];  
48:      i2cData[1] = (DACValue & 0xFF);  
49:      i2cData[0] = ((DACValue & 0x0F00)>>8);  
50:    
51:      lightLED();  
52:      i2cDataToBeSent = 1;  
53:    }//If UART symbol is MIDI "Note off", turn off LED and  
54:      //send zeros to DAC  
55:    else if (((UARTBufferF[0] & 0xF0) == 0x80) || (UARTBufferF[2] == 0x00)) {  
56:      i2cData[0] = 0x00;  
57:      i2cData[1] = 0x00;  
58:    
59:      unlightLED();  
60:      i2cDataToBeSent = 1;  
61:    
62:    }  
63:    
64:    return;  
65:  }  

I am having problems when I connect my MIDI keyboard. Some of the MIDI packets from the keyboard are lost in transfer. I don't lose anything when connecting it to the computer and receiving with MIDIOX, so there has to be something bad with my optocoupler. I looked at the data sheet, but I can't find anything that should rule out the optocoupler I use. I have not found anyone online using it in a MIDI project though, so there may be something with it that is not good. It is pin compatible with the recommended device, PC 900V0NSZX. So a switch will be easily done. The Sharp device costs about the double though. 

Tuning

Playing the MIDI2VC using my current, very simple, VCO, is not possible to do in tune. The VCO has a linear voltage control and the MIDI2VC is now programmed to give a 1V/octave  control voltage. So my next step will be modifying the VCO to get logarithmic control voltage input. I'll get back on that in my next post.

No comments:

Post a Comment