Trouble with Optoisolator - Page 1
Forum section: electronics / beginners

author: Graz
author_rank: Contributor
timestamp: June 24, 2018, 06:48:27 pm
content: Hi,I'm trying to develop a really simple circuit to convert a +5V current loop into a +12V/-12V signal. This is for a MIDI to RS232 converter. Most examples I've seen use a MAX232 or similar and some kind of 5V supply to go from TTL to RS232. That seems overkill in an application where I have a +/- 12V supply available. Therefore, I'm trying to do it with just an optoisolator in a common collector arrangement. Except this simplest of circuits is just not working. The circuit I came up with is in the attachment.IN+ is connected to +5V on the other end.IN- is the input data. It's positive in the sense that a +5V is a logical 1, 0V is logical 0.RS232 is inverted in the sense that -12V is a 1 and +12V is a 0. Therefore, I essentially need to invert the received data as it passes through the circuit.The theory is this: When there is a logical 1 on IN-, both sides of the LED are at 5V, no current will flow through it, the will be transistor off, and so R2 will pull RXD to -12V. I see this happen. When there is a logical 0 on IN-, current will flow through the LED, turning the transistor on. The transistor should pull RXD very close to +12V. However, I only see RXD return to 0V.I have checked +12V and -12V rails are good. Nothing in this circuit is connected to 0V (except IN- when it is transmitting a logical zero). The whole idea of the optocoupler is that the two sides of the circuit are electrically isolated from each other and so I don't understand where the 0V is coming from here.I suspect I need to connect the base of the optocoupler to something. Everything I read suggests that this would help with noise immunity or frequency response, neither of which appear to be the problem here. If that's the problem, what should I connect this to? Have I completely misunderstood how these things work?Help would be appreciated.

author: Gyro
author_rank: Super Contributor
timestamp: June 24, 2018, 07:25:16 pm
content: I think you're expecting the Opto transistor to source too much current. To get to +12V it needs to pass 16mA, probably way over the top for the CTR of the opto. Also you are asking R2 to dissipate nearly 0.4W at +12V output. Try increasing the value of R2 (try 10k) while studying the Opto datasheet.If you need more current than it can provide then you will need to buffer it.

author: BrianHG
author_rank: Super Contributor
timestamp: June 24, 2018, 07:48:55 pm
content: What's the rise and fall time with a 10k load. That optocoupler may have too smeary an output to send full MIDI bandwidth through.I would use a sensitive high speed optocoupler with buffered logic output to feed an RS-232 input.Maybe something like a PC900V. But then, you have the inverted output to deal with.A 6N139 which has low current input + high speed + high current output would do the trick, except, you would need to change the +/-12v to +/-5v to stay within that optocoupler's output voltage range. +/-5v will drive standard RS232 port's input easily up to 100k baud.

author: Graz
author_rank: Contributor
timestamp: June 24, 2018, 10:41:49 pm
content: I tried with a 10k resistor in place of R2. Now I get a pretty good rise up to +12V. On the negative side, it only falls to around -5V, but it's enough. With this change, the circuit works on a real machine with real MIDI devices.The opto I'm using here is the Vishay IL207. It has a CTR of 100% - 200%, but that's at 5V collector-emitter voltage. I chose this one because of the high EC voltage rating (70V), which is plenty over the 24V needed to switch +/- 12V. While I have +/- 12V available, I don't have 5V and I was trying to avoid a regulator. I measured the rise and fall times with the 10K resistor as around 15us. Given that MIDI is 31250 bps, this is going to work.I'll try with a slightly lower value resistor to see if I can get a greater negative voltage and a faster rise time out of it just for margin. Otherwise, I think this is working sufficiently well.Thanks for the suggestions.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 26, 2018, 05:52:55 pm
content: Optocouplers are analog parts and they have a "current transfer ratio".This is ratio of current through the LED and the current through the transistor.Some optocouplers are optimized for analog operation and then this ratio can be within a few percent lineair of a few orders of magnitude.If you put a 10k resistor at the transistor side then you will certainly measure a voltage change on your bench, but if it has to drive a long cable you will likely get into trouble.Adding an extra transistor to build a darlington is a better idea.Your 1k5 resistor may get a bit hot @ 24V:octave:28> 24^2/1500ans = 0.38400

author: Benta
author_rank: Super Contributor
timestamp: June 26, 2018, 06:12:09 pm
content: The ancient MC1488/SN75188 will do this and cost a few cents. And are guaranteed to be compliant with EIA-232.