1

I am designing an I/O board based on the RP2040. One of the design requirements states that I/O terminals must be isolated hence I'm going for optocoupled I/O using something like 6N137S1 or similar.

Now, the RP2040 provides 30 multifunction software configurable GPIO. My design has 16 optocoupled digital output and 8 optocoupled digital input, leaving the rest of GPIOs available for comms and some other services.

Given the configurable nature of the RP2040 I am toying with the idea of keeping all 24 GPIO I need as multifunction.

Now the question is how to set them up in a way that the configurable GPIO circuit remains opto isolated and how to configure it as input or output.

A simple way to configure the GPIO circuit might be with micro jumpers, so jumpers in pos 1 will set the optocoupler as an output and jumpers in pos 2 will set the optocoupler as an input.

An alternative way would be to do that via software configuration of a switch or similar.

Is there any common design pattern for this use case?

What would be a good design for such a circuit?

Miki
  • 121
  • 5
  • 1
    Is the simple approach of just adding an extra set of header pins (one for input and one for output) not an option? – Nedd Apr 02 '22 at 17:38
  • @Nedd it is definitely possible, but I was wondering if there are better options out there. Assuming common GND this means 3 pins to switch circuits before the opto, and another 3 pins to reroute the circuit to a common connector terminal pin. – Miki Apr 02 '22 at 18:16
  • @Nedd Maxim sells configurable switches (non isolated) like the MAX14914 series, something like that but isolated would be great. My ideal solution would be an 8x optocoupler where I/O can be configured via SPI (also optoisolated) or something similar. – Miki Apr 02 '22 at 18:26

5 Answers5

2

Here is a circuit that would give true bidirectional I/O with isolation. Do note it would add a fair amount of hardware to implement all 30 (or 24) I/O lines. Of course you would need to separate the left and right power/ground lines (right side shown as Vdd2 and ground 2) to achieve the isolation. (You may be able to substitute an OC/OD inverter gate for the NMOS parts.) Also, the high driving capability would be limited by the pull-up resistors.

enter image description here

You can read more about this and similar circuits at: https://www.radiolocman.com/review/article.html?di=183925

Yet another option would be to substitute the LED driver gates (U2, U4) with another NMOS component (but driving the LED from the cathode side with a series resistor). You might then use a dual NMOS chip for each isolated side.

.

Nedd
  • 7,939
  • 15
  • 19
  • Thanks. I'm not sure a bidirectional bus is what I am looking for. To support bidirectional comms you need to have separate circuits for tr/rx (which means extra hw, as you point out). Configurable IO makes sense for me if I can configure the input/output circuit in a way that uses the same hw, optocoupler, etc. That link you posted is very interesting, BTW. – Miki Apr 03 '22 at 15:42
  • 1
    @Miki, If you want to do this in an all digital way it may involve something like a 24 bit serial latch and 24 pairs of tristate buffers arranged as bus transceivers. Each output bit of the latch would set the direction of a transceiver pair, (input or output). Besides being a lot of added hardware you would need to program the circuit with a 24 bit string, then enable the latch outputs. You would need a few added control lines to run the extra circuitry, a serial input and clock (SPI like), a latch enable signal, and possibly even a preset signal. Does this seem closer to what you want? – Nedd Apr 04 '22 at 07:19
  • seems like a lot of hardware. The more I dig into the problem the more I realize that if I go all digital I will have to switch between input/output mode in both sides of the optocoupler. To make it worse whatever control lines I drive to the connector terminal side (min 6 lines/bits for 24 IOs) will have to be isolated as well. – Miki Apr 05 '22 at 01:57
  • The beauty of this bi-directional circuit is that you wouldn't need to provide extra control signals or run additional software to setup the data direction of each I/O line. Lastly, there are a number of options that could reduce the overall parts count, such as chips with multiple opto-couplers, logic gates, resistors, and even multiple Mosfets in one package. – Nedd Apr 09 '22 at 03:20
1

I will give you a solution. It might not be the most optimized solution. What you are looking for is a multiplexer. The component looks like this:

mux sch

Product link

Depending upon SEL logic, D will connect to either S1 or S2. You can connect the RP2040 I/O to D. S1 will have optocoupler in input config and S2 will have optocoupler in output config. You set a logic to SEL to make your RP2040 I/O either an input or an output. Do this for all I/O pins.

Now your concern might be - I dont have enough I/O pins left for handling so many SEL pins. Thats where an i2c based port expander comes in. It looks like this:

port expander sch

This can take i2c commands and set the output high or low. Use these additional IO ports to control all SEL pins.

Now your logic is this:

To configure an I/O port as input or output, run some i2c commands and change the SEL pin to the right logic.

Whiskeyjack
  • 7,946
  • 8
  • 53
  • 91
  • This is interesting. First, how can I use the same optocouplers for both input and output configurations? And second, each GPIO circuit must end in the same connector terminal pin, regardless of its configuration, how this solution deals with that? – Miki Apr 03 '22 at 15:53
1

First, let's assume that the isolator interface from the low-voltage side is two pins:

  • I/O - outputs a logic signal or inputs it, depending on direction

  • DIR.INPUT - high when the isolator should be an INPUT isolator, low when the isolator should be an OUTPUT isolator.

I'm not going to show how to build such an optoisolator, since it's the easy part of the task.

If you want to have two GPIO pins for every I/O pin, i.e. one pin for state, and another for direction, then the solution is trivial: just connect the two isolator pins to two GPIO pins on the RP2040 and you're done.

But that seems wasteful. Could we detect the directionality of a GPIO pin, and thus reconstruct the state of the DIR.INPUT signal?

Yes, we certainly can do that. We need a circuit that could detect current flow between a 50% reference voltage level, and the GPIO pin.

There are a couple of different approaches possible, but I've explored one that uses simple current measurement bridge.

schematic

simulate this circuit – Schematic created using CircuitLab

The "logic buffer gate" is a simulation workaround: it should have been a BUF, but those only work with special digital signals, not with arbitrary voltages - so a comparator has to be used. In practice, you'd treat Q6's collector as a logic level DIR.INPUT source.

Another approach, in similar vein, but more sensitive and more robust, using differential pairs:

schematic

simulate this circuit

Both above simulations are interactive. To change input states, i.e. OUTPUT ENABLE, OUT PORT, and INPUT STATE, click on the input state (0/1 in a circle) to highlight it, and press Space to toggle. The DC solution is instantly recalculated, and the node voltages, as seen on the handy voltmeters, will be updated.

  • The idea of detecting the directionality of a GPIO pin is very interesting. This is way more sophisticated that what I was looking for. It requires a lot of hardware as well x24. Thanks a lot for taking the time to put this together. – Miki Apr 05 '22 at 02:27
  • 1
    Given the sizes of resistors (0402) and BGA/CSP transistor pair packages, I dare say the whole thing per channel will take less space then the optocouplers will. In quantity should be <<$1 per channel, too. Of course you can always use an external IO expander. Transistors are super cheap though and even for prototypes these days you shouldn’t be putting smt together by hand anyway. So in practice it basically doesn’t matter how much hardware it takes. I don’t think the approach above is super practical but I put it out here as a silly wild tangent :) – Kuba hasn't forgotten Monica Apr 05 '22 at 02:56
  • 1
    The biggest win from using dumb transistors and discretes? You’ll always find them. As for IO expanders… you have to compete for stock with automotive and industrial OEMs. “Basic” chips like that come and go from stock all the time. If you won’t be able to buy transistors anymore, the civilization will have bigger problems than your device can solve :) Some older logic families still made are also good since new designs mostly don’t use them, so the stock levels are more stable as only established products and hobbyists use them. Recent stock upheavals require unorthodox thinking :) – Kuba hasn't forgotten Monica Apr 05 '22 at 02:59
  • I've posted an answer that basically relies on a "hat" that can be manually reversed to configure GPIOs. Re-reading your answer I am realizing now that it might be possible to replace the voltage regulator in the "hat" with transistors and discretes, what do you think? – Miki Apr 06 '22 at 18:38
1

So I finally settled for a simple "hat" that holds the opto + voltage regulator that takes a wide range of input voltages. See a crude schematic of the circuit, accessory Cs and Rs around the voltage regulator missing:

enter image description here

Depending on the orientation of the hat the GPIO acts as an input or an output.

I can probably group GPIOs in sets of 6, so I can have a single GND/VCC per group/hat. So I'll end up with 4 hats per board, each of them providing 6 GPIOs, allowing the board to configure I/Os in groups of 6.

Each hat will have two 8 pin connector (6 signal pins + GND/VCC).

Using a voltage regulator like HT7533 or similar allows the hat to drive the opto led from a variety of input voltages, from 3.3V that the RP2040 provides when acting as an output to 30V when acting as an input (usually 24V).

Extra hardware is just the voltage regulator plus a bunch of cheap board-to-board connectors.

EDIT 1: @bobflux suggests replacing the voltage regulator with a darlington pair.

Miki
  • 121
  • 5
1

Neat idea about flipping around the hats!

Note you need a resistor at the output of your LDO to limit LED current.

You could also add a diode for reverse polarity protection on the input side and maybe on the output side.

I'm not sure the LDO will be stable without capacitors. In fact, you could replace the LDO with a simple resistor.

Here's a quick proposition: in order to keep the input current low enough for a "one size fits all" resistor value on the LED, while keeping the output pullup low enough, the usual optocoupler current transfer ratio of 50-100% is not adequate. However, with a darlington on the output, current transfer ratio is multiplied by hFe of the second transistor. This means it is possible to run the LED at a much lower current.

enter image description here

bobflux
  • 70,433
  • 3
  • 83
  • 203