Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Base Emitter Resistor for 6N139 on MIDI input?

  1. #1
    Senior Member
    Join Date
    Feb 2015
    Posts
    151

    Base Emitter Resistor for 6N139 on MIDI input?

    So I have an interesting situation I would like to share. I created a MIDI input circuit that mostly follows the MIDI schematic detailed by Paul on the midi library page. I originally used this 6N139 optocoupler to do the job: https://www.fairchildsemi.com/datasheets/6N/6N138M.pdf and everything worked great!

    I changed over to this optocoupler (6N139-X009 option) http://www.mouser.com/ds/2/427/6n138-67270.pdf because of its low vertical profile. After assembly, my MIDI wasn't working properly! Clock messages would not come through, and stop messages would be recognized as clock messages. I noticed that there was some slew on the signal when I hooked up a scope. I swapped the new Vishay 6N139-X009 with one of my old fairchild 6N139 chips, and it worked as expected...

    I then stumbled upon this article: https://electronics.stackexchange.co...-many-circuits

    I followed the advice of the green check solution, and connected a 10k resistor between the Vbase (pin7 on the 6N139) and ground - this was after swapping back to the 6N139X009.

    Now it works!

    Just wanted to share this in case someone comes across this problem in the future. I do not fully understand this, but here is the explanation:

    Optocouplers with Darlington output (like the 6N138) are very slow, especially when the output transistor should switch off.

    To get a sufficiently fast raise time of the output signal, the base of the output transistor needs a connection to ground (through a resistor) so that the base charge can be removed quickly. Any value between 4.7 kΩ and 10 kΩ should work fine.

    Furthermore, the raise time of the output signal also depends on the value of the pull-up resistor (R1 below). Smaller values result in faster raise times, but very small values increase the power usage when the optocoupler pulls the output low. In practice, about 1 kΩ is commonly used.

    The 6N138 needs a 5 V power supply, and the Raspberry Pi does not work with 5 V signals. However, an open-collector output can be used to translate the signal level; just connect the pull-up resistor to 3.3 V instead, like this:

    Name:  KC9zW.png
Views: 359
Size:  4.6 KB

    If possible, forget about the 6N138 and use an optocoupler with a digital output (like the Sharp PC900 from the specification, or the H11L1); if you need to save space, use a SO-5 chip like the TLP2361 (which has a CMOS output, so it does not need a pull-up resistor).

  2. #2
    Senior Member
    Join Date
    Mar 2015
    Location
    UK
    Posts
    159
    As you say... it is interesting. Worth studying again the basics of transistor action.

    When the transistors are switched on, the base/emitter junctions are forward biased so there is no "depletion" region. But the base/collector regions are reversed biased so there is. This is NPN semiconductor action - positive to N (collector) and negative to P (base) creates a depletion region - a void area with no charge carriers but charges build up on either edges of the NP interface. This is effectively a capacitor made out of semiconductor material. Indeed, you can make an excellent "VDCap: voltage dependant capacitor" out of a reverse biased NP junction (and reverse biased LEDs make excellent VDCaps :-) !!).

    The second diode is also reverse biased inside the opto-coupler, so it too will store charge. The photodiode VDCap and the first transistor base/collector junction are in parallel which makes an even bigger capacitor.

    Now consider what happens when the light photons stop across the coupler gap. Both transistors try to switch off. But all the charge built up on the photodiode cathode and the first transistor base needs to be discharged somehow, and they will not fully switch off until that charge has been disposed of. By connecting R2 resistor from pin 7 to ground, you are providing an alternative path for that cathode and base charge to dissipate to ground - this is now in parallel with that the second transistor base/emitter junction, which without the resistor, was previously the only way for the charge to get to ground. A base/emitter junction forward biased has only a low resistance while there is a voltage across it of about 0.7 volts. As this voltage falls lower, then the resistance of the junction gets higher and higher - probably way above 10K ohms.

    You can now see why that 10K does its job effectively during switch off for the first transistor and photodiode.

    Also note that during switch off, the 10 K is effectively across the second base/emitter junction, so that is going to help the charge on the second base dissipate to ground even faster.

    A lot of bang for a small buck !!

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,720
    Thanks for sharing. I've added a link on the MIDI page, so hopefully anyone else with a similar 6N139 can find this.

  4. #4
    Senior Member
    Join Date
    Feb 2015
    Posts
    151
    TelephoneBill - Thank you for the explanation! I was never schooled in electrical engineering, so it is always nice when someone can explain the theory behind what is going on. These optocouplers were black boxes to me before!
    I like the idea of your voltage controlled capacitor. Makes me want to design a voltage controlled slew circuit with it.

    Thanks for adding it to the MIDI page, Paul! I have worked with a number of 6N139 chips in the past, but this was the only one that ever had an issue. The datasheets look very similar.

  5. #5
    Junior Member
    Join Date
    Oct 2017
    Posts
    5
    You don't need to be schooled just practical information and some diodes like semiconductor diode definition information and you will do nice circuits like this for others.

  6. #6
    I have used 6n138's for awhile for midi. That one also needs a resistor to drain the charge from the base. But now I have changed to 6n137's. These do not need the extra resistor for the base. Also the pull up resistor can be a lot larger. The resulting signal is much sharper.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •