Electronic – How to select a good optocoupler for uart to 20 mA current loop converter

opto-isolatoruart

I'm trying to make a circuit that converts UART signals to 20 mA current loop signals.
I tried this circuit to switch the signals.

I used this circuit to switch

I am not much experienced in optocouplers I had just two types to test, TLP251 and 4N25. The below pictures show voltage of Node1 on oscilloscope. The input signal on TXD is a 20 KHz sqaure wave.

Node1 on 4N25

Node1 on TLP251

What is a good choice for optocoupler which is capable of transferring signals up to the 1M Baudrate of the uart?

This is what I got with 6N137.

Output with 6N137

The final Circuit in my mind would be something like below:

enter image description here

I need the logic to be the same not inverted which mean 5V on TXD makes 20 mA on current loop and 0V makes 0 mA.

Best Answer

A simple current source with mirror. Google to find the calculation for correct resistance. The Q1 needs to conduct the N-th current of parallel transistors, where N is the number of mirror's parallel transistors.

Why current source? Because the current loop is to be used on long distance cables and low speed. The current source will compensate for the long cable resistance.

schematic

simulate this circuit – Schematic created using CircuitLab

Try this:

schematic

simulate this circuit

The S5 PLC already has two current sources for that purpose.