Main Site Documentation

Working on MIDI in/out Module for Gadgeteer


#1

For the most part, the MIDI modules out there won’t work correctly with 3.3v microcontrollers. The MIDI shields are meant for 5V Arduinos (I’ve seen one which has more options, but it’s huge and ugly).

The MIDI protocol is a relatively slow (31,250 bps) serial protocol implemented as a current loop with 5V signal levels. In theory, a high value froma 3.3v MCU should be just enough to trigger a 1, but in practice, it’s too close to be reliable. Keep in mind that much of the interesting MIDI equipment out there is old old old stuff dating from the mid 80s and later.

I wrestled with the signal level translation for a while, and in the end, went with a subset of what Sparkfun and others put together using a BSS138 mosfet. The MIDI IN stuff is something I’ve done any number of times, but the signal level translation on MIDI out is new territory for me. It took me so long because I still don’t really understand that level translation circuit, and I hate to use things I don’t understand.

I left out a MIDI thru because it’s not as useful as it once was (chaining MIDI instruments adds too much latency), and makes the board quite a bit larger.

Thoughts? Comments?

Pete


#2

Isolation on one side is like no isolation.

I would do it using logic gates. Most of these chips can be powered off 3.3v or 5v but accept TTL inputs, that is 2v for inputs. Simpler, cheaper and guaranteed to work.


#3

Thanks Gus

MIDI doesn’t require opto isolation on anything but MIDI IN. The reason the isolation is there is not really for protection – it’s to help prevent ground loops (these are audio devices). From the spec:

Note that MIDI IN is not grounded, but MIDI OUT is (some shields and breakout boards have incorrectly handled this in the past)

Logic gates: I have zero experience with them. Will they actually step up the voltage, or will they simply pass through the trigger voltage? What should I look for when evaluating the correct part to use?

Here’s the standard schematic
http://www.midi.org/techspecs/electrispec.php

Pete


#4

To follow-up: if using a logic gate, would I use two NOT gates connected in serial or something? I’m trying to visualize how to get out what I put in, just at a higher voltage.

Pete


#5

Still, isolating noise on one side is like having no isolation, if I understand this correctly.

Also, I do not understand why isolating the out instead of the in? You would think more noise will come from inputs.

For gates, if you power a TTL gate with 5v and connect the input to a pin on gadgeteer, the output will be 5v.


#6

2 not gates or a single AND or OR gate, just tie the inputs together.


#7

[quote]Still, isolating noise on one side is like having no isolation, if I understand this correctly.
Also, I do not understand why isolating the out instead of the in? You would think more noise will come from inputs. [/quote]

MIDI instruments are often connected in a chain. OUT (or THRU) on one to IN on the next one. If all follow the schematic correctly, the grounds for any two devices will never be connected, but the cables themselves will be grounded to a single device.

Isolating MIDI IN was likely done because it means you save one isolation circuit (isolating OUT would require also isolating THRU – most synthesizers have both). The net effect is the same, assuming the cable itself isn’t the source of noise (which it can be, which is why the spec says something like 10-15M max length)

Here’s some more info for the curious:
http://whitefiles.org/b1_s/1_free_guides/fg1mt/pgs/h10d.htm

Tying the inputs of an AND/OR gate: Excellent, thanks.

Pete


#8

Gus,

This is not about digital noise, or noise about transmission.
This about ground-loops that will re-inject noise into the audio signals elsewhere on the device.
If you look at the schematics as provided by Pete, or the official Midi Assoc. web, you can see that :

  • Midi OUT is active and create a current loop using the VCC of the emitter. The current goes out through pin 5 and comes back through pin 4 (current is pulled when the emitter pull the signal low.
  • Midi in is just current getting in from pin 4 through the LED and out on pin 5.
    The cable is generally shielded and shield of DIN socket is connected to the emitter side only.

All this insure perfect isolation : all signals belongs to the emitter circuit.

Pete,

Indeed you will succeed with default schematic only if you have +5V on your board.
In that case, using a gate (non inverting) or 2 gates in serie (inverting) is OK.
Both the gate and the resistor on pin 4 shall be powered by +5V.

Now if you only have 3V3, you can make it work by adapting the resitors on the emitter side.

You should always assume that the receiver has a 220 ohms resistor but you are free to change the resistors on the emitter side.
The 6N139 LED is given for a forward voltage drop of 1.3V.
Out of 5V, this means that the typical current going through the loop and through the LED is (5 - 1.3)/(220 +220 + 220) = 6mA
[italic]This is pretty low as DataSheet recommend 20mA…[/italic]

So to get it work out of 3V3 (gates and midi out), you need to consider changing the 220 ohms resistor to R’ on emitter side so that (3.3 - 1.3) / (R’ + 220 + R’) = 6mA
56 ohms for each resistors should be ok. Even 47 or 33 would work.

Hope this helps

EDIT : I don’t know about Hydra and Spider, but on USBizi, as pins can’t source/sink more than 4mA (LPC datasheet), you must use a gate. In order to make your module as universal as possible, I strongly suggest using a gate.


#9

Barbudor
Thanks. Great info. I can get +5v power (not logic) on the Gadgeteer sockets, so I should be ok once I use the gate as you mentioned. Very good point about the current.

Gus
What’s the limiting factor of the +5v pin on the gadgeteer socket? I assume this is just essentially a pass-through from USB, or stepped-down in the case of external power, right? Presumably if you can power the big LCD with it, powering this won’t be any problem, but I just wanted to understand the parameters.

Pete


#10

Yes 5V would be fine to power your circuit.


#11

@ Gus

Thanks

@ Barbudor (or anyone else)

So, I’ve been trying to figure out which logic chips would be good to do this 3.3v to 5v translation, but I keep running into level issues. See attached for an example. Logic high min is higher than the 2.whatever that the Gadgeteer is expected to spit out for a logic high.

Is there a logic family that works in this situation? Something with a relatively low logic high at 5v?

Pete


#12

I gave you the answer in first post :slight_smile: The keyword here is TTL.

The high level on these chips will always be 2V. The ones with vcc x 0.7 are no good

Here is an example http://www.ti.com/lit/ds/symlink/sn74act08.pdf


#13

@ Gus. Aha! Thanks. I’m still learning this stuff :slight_smile:

I see the TTL stuff is quite a bit more expensive than the other logic. Not crazy (like $0.25 instead of $0.05) but enough to notice in quantity.

Pete


#14

You can get cheap. You need CMOS gate but with TTL levels. Lol, sorry if this is confusing.


#15

@ Gus

It’s not confusing. Once you helped me figure out what to look for, it was relatively easy. I was just saying that they were more expensive than the mosfet solution (unless I bought huge quantities).

Thanks.

Pete


#16

An intern in MSR-Cambridge worked on some MIDI stuff for Gadgeteer - let me see if I can dig up his reference designs.


#17

Thanks, but I’d rather go from scratch on this one :slight_smile:

Pete


#18

Let me know if you need a beta tester. My side project right now is building a MIDI arpeggiator with Gadgeteer :slight_smile:


#19

I think you should use a higher speed opto, like the 6N135 f.e.


#20

Wouter

Speed is not a problem. But 6N135 has a lower gain that 6N139.
The current available on a MIDI current loop is low and 6N139 works much better than 6N135.