Electronics question - MIDI interface

I was looking around at MIDI interfaces after last night’s conversations
and I saw that Sparkfun had a MIDI breakout board -
http://www.sparkfun.com/products/9598, schematic at
http://www.sparkfun.com/datasheets/BreakoutBoards/BOB-09598-MIDI_Breakout-v11.pdf.
I was on the verge of sticking one on an order I was sending out when
I noticed this in the comments for the board:

“I don’t mean to sound harsh, but PLEASE next time you turn this board
can you put on the non-inverting buffer as specified by MIDI.ORG? I know
it looks like an optional part, but it’s there not just for it’s current
sink ability but also protection of the CPU for when people plug the
wrong cables into the wrong things. Sometimes the shortcuts just aren’t
worth it:”

and there was a link to a circuit diagram at
http://www.midi.org/techspecs/electrispec.php, which (if I’ve read it
correctly) includes buffers on both the MIDI THRU and MIDI OUT
interfaces. I also looked at the article Paul pointed me at -
http://www.thebox.myzen.co.uk/Hardware/MIDI_Shield.html

The questions are:

  1. Am I correct in believing that the Sparkfun shield is a complete
    pile, and that if you plugged IN and OUT in the wrong way round there’s
    a chance you’d fry your Arduino?

  2. I assume the BC212 in the thebox.myzen.co.uk page is playing the part
    of the buffer? The midi.org page says “Gates “A” are IC or transistor”,
    if you were to use an IC, what sort of thing would you be looking at?

Thanks!

Alan Burlison

Alan,

I have been looking at your questions and thought I would attempt to
answer clearly. It’s taken a lot longer than I thought it would!!

I agree with the comments that the poster has made and you are correct
in your reasoning why.

  1. Am I correct in believing that the Sparkfun shield is a complete pile,
    and that if you plugged IN and OUT in the wrong way round there’s a chance
    you’d fry your Arduino?

I doubt you would fry your arduino…might happen, might not. You
may send more current than you normally would into the arduino TX
input but as the MIDI protocol is active low I suspect nothing would
happen. Firstly because MIDI data isn’t sent all of the time from
musical instruments only when someone is playing them. It all depends
on what you plug the midi cable into, I know people who use midi for
controlling CNC machines and they can be constantly sending data so
connecting the out to the in might be bad news. If it was a poorly
designed keyboard then then some excess current draw from the keyboard
might occur…unlikely though. I haven’t looked at the arduino TX
pin currrent sourcing abilities. It would depend on the ATMEL 320p or
microprocessor of choice’s specifications. Check the datasheet and
then let me know!!

  1. I assume the BC212 in the thebox.myzen.co.uk page is playing the part of
    the buffer? The midi.org page says “Gates “A” are IC or transistor”, if you
    were to use an IC, what sort of thing would you be looking at?

The BC212 transistor is to provide current sourcing to drive the midi
instrument that you are intending the computer to play. In order to
get the instrument to play a note the signal sent serially down the
cable needs a bit more juice. You can provide current sourcing in
electronics in various ways. The common two methods are to use a
bipolar transistor with the base biased so that the transistor always
comes on when a signal is present at the base with maximum current
flow available from the power supply. (Drive the transistor so that
more than 0.7V is present at the base (NPN transistor) so that
saturation occurs. For PNP transistors drive it such that the base
pin is 0.7V less than the voltage supply at the emitter pin. The PNP
version is what has been used in the example given because midi is
active low (a 0V signal is an ON) and PNP transistors are active low.
How much current will flow depends upon the type of transistor used.
The specification is which gives this information is called the output
characteristic or small signal current gain (Hfe) and will be
specified on the transistor datasheet. It is unit less because of the
maths involved (collector current (Ic) divided by base current (Ib)).
For amplifiers or circuits where high current sourcing is required the
bigger the Hfe the better. For audio amps the frequency bandwidth of
the device is also critical…but thats another topic.

If we look at the circuit specified by your good self (See attached
circuit schematic diagram). We have a BC212 PNP transistor with a 6k8
ohm resistor coming from the arduino TX pin and a 2k7 resistor going
to +5V rail. So good old ohms law says that the base of the
transistor will have 4.3V and 17.3uA present at the base when driven
with a 2.5V (simulated) serial signal. I have set the load of the
attached instrument at 1k…i’m not sure what it is…never checked.
I haven’t done much midi…I’m very curious though…might start.
Anyhoo back to the circuit and we can see that the output is at 5V
and 3.4mA so we have more current to drive our circuitry. According
to the datasheet of the BC212 it has an Hfe of 200 meaning that for
every 1mA at the input it can supply 200 times more at the output and
if we do our sums we can see that this is the case here:

3.4mA (Ic) / 17.3uA (Ib) = 196.53 - close enough for government work!
3.4 * 10-3 A / 17.3 *10-6 A = 196.53 (notice the units cancel -
dimensional checks are useful to make sure you have the correct
answer!) It also explains why Hfe is not specified with units.

Now that should explain the transistor circuit and what it is
for…you can get the same or similar circuit function using an
op-amp in unity gain topology. The circuit is also known as a buffer.
To me a buffer is something that provides protection and separation
from thing to another. In electronics this is also the case. A
buffer circuit provides a way of connected a circuit with low
impedance to a circuit with high impedance preventing excessive power
consumption and signal degradation from the signal source. A better
term might be signal matching circuit. Please have a look at the next
attached diagram to understand where we are:

A signal is provided to the non inverting terminal of the amplifier.
The output of the op-amp is connected to the midi out connector but
also fed back directly into the inverting input. This means that
whatever happens the op-amp will attempt to amplify any signal at the
non inverting terminal. As the circuit has been set with no gain
(unity gain amplifier) no amplification of voltage will occur
but…the op-amp output will provide more current as its output is
low impedance ( impedance is resistance with frequency included). The
input is high impedance so it will draw little current from the signal
provided at it’s inputs. In the circuit diagram I used a 741 op-amp,
any op-amp will do one that doesn’t take up too much circuit
real-estate is normally what is required.

Now…for the isolation bit…Any signal that is placed at the
output of the op-amp or transistor (connecting the midi out to the
midi in) will not get passed the op-amp or the transistor…This is
because current cannot flow through a P-N junction from the cathode to
the anode. The semi-conductor will block the current flow and prevent
any damage occurring. If no semiconductor is present (no transistor
or op-amp then current can flow backwards from the output to the input
and could potentially damage the microprocessor inputs. It really
depends on the device in use. Some devices are more rugged than
others and can take a few hits…others can’t. IMHO people
(Sparkfun) should learn to design circuits with worst case scenarios
in mind and add the required isolation circuitry. The benefits are
good signal strength (more current at the output) and no chance of any
damage to the uProc as the semi-conductor provides circuit isolation.
The reason people normally leave the buffering circuitry out is
because they are trying to reduce costs. In Sparkfun’s case I think
they don’t really know what they are doing.

Hope this answers your questions Alan,

Regards

Alex

P.S I accept this is a damn long post. I can ramble at times!!On 12 May 2011 08:14, Alan Burlison alan.burlison@gmail.com wrote:

I was looking around at MIDI interfaces after last night’s conversations and
I saw that Sparkfun had a MIDI breakout board -
http://www.sparkfun.com/products/9598, schematic at
http://www.sparkfun.com/datasheets/BreakoutBoards/BOB-09598-MIDI_Breakout-v11.pdf.
I was on the verge of sticking one on an order I was sending out when I
noticed this in the comments for the board:

“I don’t mean to sound harsh, but PLEASE next time you turn this board can
you put on the non-inverting buffer as specified by MIDI.ORG? I know it
looks like an optional part, but it’s there not just for it’s current sink
ability but also protection of the CPU for when people plug the wrong cables
into the wrong things. Sometimes the shortcuts just aren’t worth it:”

and there was a link to a circuit diagram at
http://www.midi.org/techspecs/electrispec.php, which (if I’ve read it
correctly) includes buffers on both the MIDI THRU and MIDI OUT interfaces.
I also looked at the article Paul pointed me at -
http://www.thebox.myzen.co.uk/Hardware/MIDI_Shield.html

The questions are:

  1. Am I correct in believing that the Sparkfun shield is a complete pile,
    and that if you plugged IN and OUT in the wrong way round there’s a chance
    you’d fry your Arduino?

  2. I assume the BC212 in the thebox.myzen.co.uk page is playing the part of
    the buffer? The midi.org page says “Gates “A” are IC or transistor”, if you
    were to use an IC, what sort of thing would you be looking at?

Thanks!


Alan Burlison


You received this message because you are subscribed to the Google Groups
“HAC:Manchester” group.
To post to this group, send an email to hacman@googlegroups.com.
To unsubscribe from this group, send email to
hacman+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/hacman?hl=en-GB.

Hope this answers your questions Alan,

Yes, much more than I could have hoped for! Thanks Alex, it’s a really
good mini-tutorial on how to work this sort of thing out - the circuit
is a real-life example but is small enough for us non-plumbers to get
our heads around :wink:

P.S I accept this is a damn long post. I can ramble at times!!

No, it’s great - it has encouraged me to dig out my calculator and check
I can get the right answers myself :slight_smile:

Alan Burlison