Monday 23 July 2018

opto isolator - MIDI to Arduino with a 4N38 Optocoupler


I ordered a set of optocouplers the other day and was excited when they finally came in. Unfortunately, I've having a bit of trouble getting them to work. Simple on/off tasks work fine but when I attempt to use it to send MIDI data to an Arduino Uno I get no response. I suspect that the problem lies in the type of optocoupler I'm using. While the majority of projects on the internet seem to use the 6N138 I figured I could swap it out with the similar 6N38. Currently, I think the problem is switching time. The 6N138 is a diode optocoupler while my 4N38 is a transistor optocoupler. But without an oscilloscope I have no easy way to be sure. To complicate things, I can't find much in the way of any circuit using the 4N38 despite it's similarity to other chips. Is it possible to transmit MIDI data with this chip? Should I just buy a different one? 4N38 Circuit


NOTE: VCC is 5V.


EDIT: Corrected part number. EDIT: Specificity. EDIT: Added schematic.



Answer



R2 is too large. The specification specifies 220 Ω to get 5 mA; smaller currents just make the output transistor weaker.


R3 is wrong. A base-emitter resistor could be used to allow the charge to be removed faster from the saturated base when switching off. However, such a resistor also adds a minimum threshold for the base current (because no current will go into the base until the voltage drop over the resistor is large than the base-emitter voltage). This would be acceptable with a Darlington optocoupler like the 6N138, due to its high amplification, but with a simple phototransistor, that current is so small that it is unlikely that the transistor will ever turn on. Remove R3 altogether, or try a large value like 1 MΩ and go down from that.


The pull-up resistor R1 looks OK. But you might want to try a smaller value like 100 Ω, just to be sure.





At 31250 baud, one bit has a length of 32 µs. For reliable operation, the raise/fall times of your optocoupler's output must be much less than that; the MIDI specification recommends less than 2 µs.


A simple transistor optocoupler is unlikely to be fast enough.


The 6N138 uses a photodiode, but its Darlington output is too slow for MIDI unless you add more components (e.g., a base/emitter resistor) to speed it up.


The best optocoupler to use is a high-speed optocoupler with a logic output. Just use the one from the MIDI specification (note: "PC900" is Sharp's way of spelling "H11L1", which is made by many manufacturers).


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...