need help with reverse polarity protection in two-supply system - Page 1
Forum section: electronics / projects

author: bigmessowires
author_rank: Contributor
timestamp: October 08, 2013, 04:02:59 am
content: Let's say you need to connect a Mac Plus keyboard connector to an ARM-based ST Discovery Board (because that's a normal thing to do). The Mac Plus uses a RJ11 cable for the keyboard, which has GND, CLK, DATA, and +5V, and connects to an RJ11 socket on an adapter board attached to the Discovery Board. Unfortunately the Mac isn't specced to provide enough current for the Discovery Board, so it's got its own power supply (from USB). The situation looks like this:You can hard-wire A to the Discovery Board's +5V, D to its GND, and B and C to ARM I/O pins, and everything will be great until someone use a regular RJ11 phone cable instead of an actual Mac keyboard cable. Because the phone cable has the pins in reverse order from the keyboard cable, you'll end up with +5V and GND swapped, as well as CLK and DATA swapped.Is there any simple way to prevent damage if the wrong cable is used? Even better, is there any simple way to detect when the lines are reversed, and make it auto-magically work anyway?Am I correct in thinking that the grounds of the two systems need to be connected? Or is that not even necessary?To simply prevent damage, you don't really need to connect +5V (pin A), since the systems have independent power supplies. So my first thought was to put a diode in the ground line of the adapter board, so that if +5V volts is connected to pin D, the diode will prevent current from flowing. But I think this would interfere with normal operation with the correct cable, and make the Discovery Board's ground 0.6V higher than the Mac's. Another thought was to put a polyfuse in the ground line of the adapter board, that would trip if too much current flows. But I'm not sure how much is "too much" or how much would flow under normal circumstances.To go beyond damage prevention, and have the circuit actually work, I was imagining something with two transistors acting as switches between the Discovery Board's ground and A and D. If A is high, then ground should be connected with D, but if D is high, then ground should be connected with A. However, I think this may rely on an overly-simplistic view of a transistor as a switch. In reality I believe there is still a small voltage drop between collector and emitter even when a transistor is on, so two system grounds connected in this way aren't really directly connected. Worse, I believe the current in this shared ground connection could only flow in one direction.Anyone see a simple path out of this mess?

author: Andreas
author_rank: Super Contributor
timestamp: October 08, 2013, 05:05:52 am
content: A 5V relay with 4 contacts + a diode for the polarity of the coil should work.with best regardsAndreas

author: kalobg
author_rank: Newbie
timestamp: October 08, 2013, 05:30:51 am
content: Quote from: Andreas on October 08, 2013, 05:05:52 am

author: bigmessowires
author_rank: Contributor
timestamp: October 08, 2013, 03:12:13 pm
content: That makes sense, thanks. Would you suggest a solid-state relay, or a mechanical one? Does a mechanical relay need a current-limiting resistor in series with the coil? I've never actually used a relay before.

author: bigmessowires
author_rank: Contributor
timestamp: October 08, 2013, 04:01:01 pm
content: OK, here's what I've got. The four lines from the RJ11 socket are A, B, C, and D. If A is +5 V, then the relay is energized, connecting D to the board's ground. If A is GND, then the coil is not energized, and it connects A to the board's ground. D is also passed through to the microcontroller as a digital input, so it can reverse the meanings of data lines B and C in software.Does this look right?

author: tszaboo
author_rank: Super Contributor
timestamp: October 08, 2013, 04:02:12 pm
content: Much nicer solutions exist.http://nandblog.com/reverse-power-supply-connection-circuits/This can take care of your power swapping problem. I suggest using the mosfet.And for the data, you can simply use a DPDT analog switch. They are super simple. Just power it from the rectified voltage, and connect the control pin to the appropriate input pin.

author: bigmessowires
author_rank: Contributor
timestamp: October 08, 2013, 04:10:49 pm
content: I'm not sure the solution described on your website would work here: I don't want to connect the +5V supplies from the two systems, I want to connect the grounds. So there is no "load". If I put the MOSFET circuit in the ground connection, then wouldn't there still be a small voltage difference between the two grounds, and with current in the ground line only able to flow in one direction? That seems like it wouldn't accomplish the goal of a common ground from the two systems.

author: tszaboo
author_rank: Super Contributor
timestamp: October 08, 2013, 09:31:49 pm
content: Isn't the NFET doing exactly that? I mean, if you connect the gate to the incoming 5V and the source to the incoming GND, drain to the system's GND than if the two GND is only connected together if the cable is inserted correctly. And you swap the signals depending on the actual voltage on the pin.

author: bigmessowires
author_rank: Contributor
timestamp: October 09, 2013, 12:01:44 am
content: Unless I'm mistaken, current in a FET can only flow from drain to source, not the other way. So to allow currents to flow in either direction in the ground line, you would need two FETs in parallel, where one has the source and drain oriented in the reverse direction of the other.Beyond that, my understanding of FETs in general is too poor to understand what would happen. What operating mode would the FETs be in? Approximately how much "on" resistance would exist between the two grounds? Is there a threshold voltage between the two grounds that must be overcome before the FET-switches would conduct current?

author: JohnnyGringo
author_rank: Regular Contributor
timestamp: October 09, 2013, 12:13:07 am
content: Would an OR-ing diode work here? (My apologies for my lack of HTML image sizing skills)such as:www.codemsys.com/SMPS/Parallel.htm1. Use ORing diodesThese are diodes connected to form a logic OR function.This is a simple OR gate. If either the top leg, or the bottom leg, or both, are high, the output will be high.If both inputs are low, the output is low.In the analog world, the higher of the 2 input voltages will be passed to the output, and the lower one will be ignored.More importantly, the higher voltage leg will not push current back into the lower voltage leg. And each voltage source will be unaware of the presence of the other.

author: tszaboo
author_rank: Super Contributor
timestamp: October 09, 2013, 01:10:54 am
content: Quote from: bigmessowires on October 09, 2013, 12:01:44 amIf only that would be true, my day job would be a catwalk. In fact MOSFETs have an intrinsic body diode inside the "other way". So it conducts like a diode. If you open it to top this, they conduct even more. The on resistance can be as low as 0.0005 Ohm depending on the type and voltages.