Interesting WTPA2 MIDI Opto Repair

So, while I was testing these pre-assembled units, I found one that had intermittent MIDI functionality.
The symptoms were these:

Mess with MIDI keyboard, MIDI works normally.
Wait 20 seconds.  The first NOTE_ON or NOTE_OFF after that fails.  Subsequent messages within the ~20 second window worked fine.

"Aha, a bug", I thought.

However, all other assembled WTPA2 units worked fine.

I probed the input to the UART pin on the MCU coming from the optocoupler.  Scope traces looked exactly the same for working and non-working units.  Something borderline.

So I resoldered a bunch of stuff.  No dice.  I swapped the MCU, no dice.  I swapped the crystal (UART timings can be sensitive; I've never seen a crystal fail out of tolerance, but hey).  No dice.

Rising edges on the MIDI signal to the opto were wussy; I stiffened the value of the pull up on the opto's output.  Waveform looked the same, no change in symptoms.

Eventually I decided to swap the optocoupler (a 6N138).  Which fixed it!  The scope traces are basically indiscernible to the eye, but not to the MCU.

So, if you get intermittent MIDI and you've checked anything else, swap the opto.

SEE ANSWER BELOW

(NOTE -- I was using some old crusty reference schematic from the MIDI spec, but according to this:
The 6N138 doesn't really need a super stiff pull up.  Food for thought).

Thought I'd share.


Comments

  • edited January 2015
    So, I found a second unit like this.  The first message of any kind coming in after ~10 seconds was dropped, consistently.

    Since it happened twice I figured it was probably systemic.  Most manufacturer's datasheets showed the circuit I used in WTPA2, and midi.org had a similar one.
    However, some Internet searching and Horowitz and Hill reading produced the answer.

    For a Darlington (like the receiver in the the 6N138) to turn off quickly, it wants a pull-down from the base of the first transistor in the pair to ground.
    Looking at the circuit, this totally makes sense; the first transistor in the pair will float at the Vbe (or slowly transition to ground, based on leakage) once the base of Q2 hits about a diode drop.
    Apparently many other packaged Darlingtons include this (see H&H page 95).

    Also noteworthy, the Fairchild datasheet mentions that this resistor is integrated in the DUAL version of the 6N138 for temperature stability:

    Lastly, I also noticed others bitching about this on the Internet elsewhere:

    So, I threw a 2.4k resistor between pins 5 and 7 of the 6N138 and the problem immediately ceased.

    I was curious, so I took scope traces.  Here's the input to the AVR's UART with the original circuit:
    image


    And here it is again with a 2.4k pull down on pin 7 (base of Q1) -- Note, the time scale is different, but the byte is the same:

    image

    As you can see, the rising edges are a lot sharper.  It seems the original rise times mess with the transition timings enough that the it's right on the borderline of what the AVR's UART hardware finds acceptable.
    If you were writing your UART code in assembly rather than using the UART module, you could tweak the timings, but bump that.  I like my UART module.

    Upshot:
    ALL KITS SHOULD SOLDER A RESISTOR FROM PIN 7 OF OK1 (6N138) TO GROUND.
    A good place to pick up ground is pin 5 of the 6N138.
    Resistor value is relatively unimportant.  Anywhere from 1k to 10k should be fine, or larger if you're strapped for parts.

    Although you can probably get away without it (hundreds of WTPA1 units had the same schematic, and apparently worked well enough that nobody complained) it is a good idea to do this if you care about your MIDI being reliable.

    Live and learn.  Thanks for your patience,
    TB
Sign In or Register to comment.