Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help for Midi decoder

Status
Not open for further replies.

ikalogic

Member
Hello!

I am planning on adding MIDI decoding to our logic analyzer (SCANALOGIC-2).

I was wondering if someone here have some experience with MIDI protocol in order to test it and give me some directives (on how the decoded lines should look like, user experience, etc..)?

I did the same thing with another user when i implemented MAPLE bus decoding.

Anyone interested?

My first technical question would be: can the I/0 lines of a MIDI device be interfaced to a regular buffer gate? i read somewhere that it needs opto couplers.. (?)
 
MIDI is serial data 8bit, no parity, one stop at 31.250KHz (ie, 1MHz divided by 32). Input is via opto isolation. See mdfs.net/midi for examples. MIDI protocol sends commands with b7 set and data with b7 clear, commands can be omitted and data bytes will be interpreted according to the last command byte sent. Notes values are semitones, 60=middle C, 62=middle D, etc.
80,note,velocity - Note Off
90,note,velocity - Note On, 60=mid.C
A0,note,velocity - Note Aftertouch, 60=mid.C
B0,control,setting - Control Change
C0,program - Program Change
D0,note,velocity - Channel After-touch
E0,bend.lo,bend.hi - Pitch Wheel Change

F0 - System Exclusive
F1 - undefined
F2 - Song Position Pointer
F3 - Song Select
F4 - undefined
F5 - undefined
F6 - Tune Request
F7 - End Of Exclusive
F8 - Timing Clock
F9 - undefined
FA - Start
FB - undefined
FC - Stop
FD - undefined
FE - Active Sensing
FF - Reset
 
What microcontroller are you using for this? You CAN do a bit bang serial routine via software but it's always best to use a microcontroller with a hardware UART as you can keep your code size smaller and not have to tie up your code to receiving serial data.

For small MIDI projects I use the PIC 16F628A as it has the on chip UART. With the on chip UART you can write your code so that the uC can do other things while the MIDI receive can be interrupt driven.

That being said, MIDI is a 5mA current loop. Pin 4 at the transmitter end has a +5V voltage on it while pin 5 is an open collector style pulse pin that sources a ground to an optoisolator LED when pulsed on while interrupting the ground to the optoisolator LED when pulsed off. It's made to drive an LED optoisolator between the two pins. This means you will need an optoisolator with a fast rise time as you only have 32uS per bit and 320uS for the full 10 bit MIDI byte (8 bits + 1 start and 1 stop bit). MIDI specification calls for a rise/fall time of 2uS or less.

The 6N138 along with the Sharp brand PC900 are the two most popular for this application. The PC900s are becoming increasingly harder to find while the 6N138s are plentifully available.

The optoisolator is used to convert the flashing optoisolator LED into an open collector TTL signal for the receive pin.

MIDI is asynchronous serial non-return-to-zero @ 31,250 baud. You have 1 start bit, 8 data bits and 1 stop bit per byte for a total of 10 bits. No parity bits are used in MIDI (8N1 protocol, meaning 8 data bytes, No parity, and 1 stop bit). Each bit is transmitted at 32uS intervals for a total of 320uS per byte and each byte is transmitted LSB first. The receive end is edge triggered off of the falling edge of the start bit so there is a 48uS interval between the falling edge of the start bit and the middle of the first data bit pulse (1 1/2 bit time).

Here's a simple schematic that shows how to interface a MIDI controller with a uC -

**broken link removed**

And here it is shown using the 6N138 optoisolator -

**broken link removed**

As far as the status messages it will respond to (i.e. Program Change, Control Change, Note On/Note Off, etc etc) all depends on how you write the code but the hardware interface is the same.
 
Last edited:
Hello Jon,

Thanks for the detailed reply!

This is for our logic analyzer (**broken link removed**) so we cannot 'redo' the hardware. If we are gonna add the MIDI decoding to our list of decoded protocols, we're gonna have to find a way to do it based on this hardware:

**broken link removed**

I am wondering, if we connect those current sources to the buffer inputs, will we be able to get valid data?

Thanks a lot!

[EDIT] This schematic is old, the actual version has pull downs on the inputs, 100Kohm pull downs.. Maybe this will help converting current to voltage...?
 
Last edited:
Based on the schematic you posted, would it be easier to make a piece of external hardware that would convert the MIDI data into one of the supported protocols?

Also, I noticed the uC in the circuit you posted has an on chip UART but they show the receive pin with an LED to ground on it. What is the purpose of that?

EDIT - I thought I'd post this schematic up to illustrate the way that MIDI transmitters and receivers interface. At the transmit end, Q1 buffers the data signal from the UART TX line while also inverting it. Q2 is used to re-invert the signal as well as directly drive the internal LED in the receiver's optoisolator.

Current flows from the +5V source, through the pullup resistor on pin 4 at the transmit end, flows through the cable to the anode of the optoisolator LED, then from the cathode of the LED back through the cable to Q2 at the transmitter where it sinks to ground, forming the "current loop".

The UART at the transmitter pulses Q1 and Q2 on and off, which in turn pulses the LED on/off and causes the collector of the optoisolator's internal transistor to switch from high to low impedance. The 270R pull up resistor at the collector of the optoisolator references the collector to +5V when the collector goes high impedance, then gets pulled to ground once the LED flashes on and the optotransistor changes state from high to low impedance. This pulsing +5V/0V signal is the signal that the receive UART receives.

**broken link removed**
 
Last edited:
Now the last question I have for you is are you just looking to use the logic analyzer to look at the signal that gets output from a MIDI transmitting device?
 
Yes!!! That's it, now you got my point ;)

Thanks a lot for all those schematics, but µC you saw on my schematic is not to be used to analyze the MIDI signals, it will just sample and send back to the PC for the SCANALOGIC-2 logic analyer software, which is where all the analysis will be done (sorry i didn't explain it before).

So what i need is just to sample the MIDI signals, just store the logic state on a period of time!

Thanks a lot!
 
All you would need is the optoisolator, 3 resistors and a diode to make the current loop to TTL conversion circuit -

**broken link removed**

Another thing I think you can do is to connect an LED with a series resistor across pins 4 and 5 of the MIDI transmitting device (pin 5 goes to the cathode of the LED), then analyze the signal between pin 5 and pin 2 (pin 2 is the ground at the transmitting end). I have not personally tested this but it would seem to me that it would work as all you'd need is the LED itself to complete the current loop at the transmitter.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top