Need to interupt a 12V relay control side with a 3V micro, safest way to do so? - Page 1
Forum section: electronics / projects

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 04:54:06 pm
content: I have three 12V switches hooked directly to 3 12V relays. The coil resistance is about 75ohms, so, .16W with spikes I figure that could be 100-200mA as the coil is initially engaged and disengaged could be of course more (thus the need for a reverse diode later).I want to interrupt these switches with my 3V micro. That is, if the switch is activated and the micro doesn't want it to be it can open the circuit on the switch/coil side. My plan was to put a small MOSFET on each line, interupting the switch/coil signal on the high side with the drain and source, then pull down on the gate and hook that to my micro.But I want it to be infinitely reliable. These are small loads so I'm not terribly worried, but I'd like to ensure I can't get it stuck open or closed. I want to make sure my fet is overbuilt for the purpose without being excessively large.Can anyone recommend any changes to my plan? Or ideally also recommend a fet? Perhaps a circuit with a couple more protections? I don't think there would be any reason in this case to optoisolate but maybe someone makes a nice driver package for this already? I have three wires now but I could expand that to 6 or so.Any comments welcome.

author: HighVoltage
author_rank: Super Contributor
timestamp: June 02, 2015, 05:10:03 pm
content: I had a similar need a few weeks ago, but I could drive it with 5V.I came across a darlington transistor array that worked extremely well.ULN2803A Hi-Voltage/Current Darlington Transistor Arrayhttp://www.electroncomponents.com/ULN2803It is TTL, DTL, PMOS or CMOS compatible in the inputs and made to drive relays up to 500 mA in a sink setup.

author: dom0
author_rank: Super Contributor
timestamp: June 02, 2015, 05:32:40 pm
content: If high-side switching is a requirement: NPN emitter follower driven by an NPN common emitter switch stage. Losses are not optimal (~.7 V on the follower), but aren't an issue with relays.(Of course possible with any transistor, not just BJTs)

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 05:57:34 pm
content: Quote from: dom0 on June 02, 2015, 05:32:40 pmDarlington pair?but aren't an issue with relays.Explain? The relays I'm using already have a reverse biased diode, but I'm still curious as to what you mean.And advantage of this vs mosfet?

author: dom0
author_rank: Super Contributor
timestamp: June 02, 2015, 06:11:46 pm
content: The voltage drop isn't an issue with relays, since they have broad actuation ranges.The power loss (I*Ube in the switching transistor) isn't an issue with relays due to the rather low average current.Vs Mosfet: You'll always need two or more transistors (or a smart switch, which has this built-in) to switch high side with a logic control voltage. Although you would do it a bit differently with MOSFETs (NMOS high side / source follower is not good due to high Ugs(th). So you'd use a PMOS driven by a NMOS, both common source.

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 06:18:22 pm
content: Quote from: dom0 on June 02, 2015, 06:11:46 pmThis is because my 3.3V won't fully open the mosfet which is voltage controlled yes?Issue removed if I use an IGBT or opto-mosfet as I understand it.If I did (for some reason) want to use a regular MOSFET to do this, I'd need the two you're saying... One to switch at the micro's output to switching the 12V which then ran into the gate of the next, allowing a wide open circuit from source to relay, yea? Sort of like how the darlington is wired? Compared to just buying the right solution, I'm uninterested in trying to lay this out

author: Kalvin
author_rank: Super Contributor
timestamp: June 02, 2015, 06:26:41 pm
content: P-MOSFET: Source to +12V, relay to Drain, Gate pulled to ground by a 10kohm resistor keeping the P-MOSFET conducting all the time. Optocoupler connected between +12V and the Gate: When the optocouler is activated, the P-MOSFET will be turned off and the relay will be turned off too.With a TIP42 (PNP), a schottky diode, 2N3906, 2N3904 and two 10kohm resistors and one 1kohm resistor one can create something similar.

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 07:20:15 pm
content: Quote from: Kalvin on June 02, 2015, 06:26:41 pmCan you explain that the FET is even doing in this instance? If I'm running the 12V from the Opto and to the Gate, why not just skip the gate and use the Opto to connect/disconnect the 12V and relay?

author: Kalvin
author_rank: Super Contributor
timestamp: June 02, 2015, 07:22:11 pm
content: Quote from: jnz on June 02, 2015, 07:20:15 pmMOSFET is used if the optocoupler cannot handle the current. A small optocoupler can typically be used if the maximum current is in range 20mA ... 50mA.With the optocoupler-only approach the microcontroller needs to actively drive the optocoupler on in order to get the relay to be turned on. With the P-MOSFET the relay will be turned on by default, and it will be turned off when the optocoupler is turned on.

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 07:35:26 pm
content: Quote from: Kalvin on June 02, 2015, 07:22:11 pmCopy. And thank you.If I was working with different grounds/sources I'd consider the opto, or even might still even though I'm on the same battery just to 'be safe'. But if the current was too much for an opto alone and I needed a MOSFET, why wouldn't I just use a logic level mosfet alone?Something 'like' this?http://www.mouser.com/ds/2/149/FDC655BN-94837.pdf

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 02, 2015, 07:41:05 pm
content: Quote from: jnz on June 02, 2015, 06:18:22 pmNo. It's because to shut off the fet, you need to pull the gate up to the source. Your MCU probably wouldn't appreciate one of its GPIOs being driven to 12v.Pch with 12v to source, drain to relay, gate pulled up to source and attached to the drain of an Nch.Nch with drain on the Pch's gate, source to ground, gate to MCU GPIO with a pullup to MCU's Vcc.MCU's GPIO is high impedance or output high, Nch is on, Pch is on, relay is on. MCU's GPIO is set low, Nch shuts off, Pch shuts off, relay shuts off. It won't shut off instantly since you'll have to wait for the Pch gate's pullup resistor, but since you're essentially driving an inductor and a mechanical relay, it's going to be shutting off too quickly anyway.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 02, 2015, 07:42:04 pm
content: Quote from: jnz on June 02, 2015, 07:35:26 pmThat would be fine if you want to switch the low side of the relay coil instead of the high side.

author: Kalvin
author_rank: Super Contributor
timestamp: June 02, 2015, 07:48:21 pm
content: Quote from: jnz on June 02, 2015, 07:35:26 pmYou wanted to use high side switching? In that case driving a MOSFET at 12V needs some sort of voltage level translation, and in that case you want to have a P-MOSFET. If you want low side switching, a simple logic-level N-MOSFET is a good choise. However, MOSFETs are high impedance voltage controlled devices which may be sensitive to noise if the wiring is not done properly. Bipolar transistors are typically less susceptible to noise as they are current driven devices.

author: jnz
author_rank: Frequent Contributor
timestamp: June 02, 2015, 09:28:20 pm
content: Quote from: Kalvin on June 02, 2015, 07:48:21 pmCan you possibly elaborate on this? I understand I selected N-ch when I wanted P-ch, but I don't really understand why. I get that I'm "above" the load, but I thought that the circuit would "see" an activated N-ch as an open circuit and happily flow through.The issue with a P-ch is I'm not going to readily be able to control the voltage going to my micro. It's going to be a -12-14V or so because that's what I'm feeding in on the source, yea? As where N-ch is a lot easier to deal with.I get that MOSFETs are more suseptabily to transient noise, but I'm not really seeing practical examples of a bipolar part that would work for me. I'm using a micro with a very small output in mA per pin. Logic level mosfet seemed like a winner. Even opto I can drive a 3.3V and I think get desired results.I'm trying to learn, sorry if it's going a little slowly!

author: dom0
author_rank: Super Contributor
timestamp: June 03, 2015, 06:50:09 am
content: Quote from: jnz on June 02, 2015, 09:28:20 pmWas explained above.

author: Kalvin
author_rank: Super Contributor
timestamp: June 03, 2015, 12:34:36 pm
content: Quote from: jnz on June 02, 2015, 09:28:20 pmHi jnz,Here are three different suggestions.- The first one uses a P-MOSFET and it is connected so that the relay will be enabled until the MCU pulls the GPIO to 3.3V.- The second one uses a P-MOSFET and is connected so that the relay will be disabled until the MCU pulls the GPIO to 3.3V.- The third one uses a PNP transistor (BCW68 should be TIP42 or a PNP with better DC gain) and is connected so that the relay will be disabled until the MCU pulls the GPIO to 3.3V.The P-MOSFET's have a zener diode at the gate in order to protect the gate from the over voltage. The P-MOSFET can be almost any general purpose P-type MOSFET which can handle at least 1A current. The PNP transistor can be almost any general purpose PNP transistor in TO220 which can handle 1A current and has a DC gain of 50 or more.Hope this will help you get started.Br,Kalvin

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 03, 2015, 03:22:01 pm
content: Quote from: jnz on June 02, 2015, 09:28:20 pmThe difference is what direction you pull the gate.With an Nch, you pull the gate above the source to turn it on and allow current to flow from the drain to the sourceWith a Pch, you pull the gate below the source to turn it on and allow current to flow from the source to the drainEither can be used for high side or low side switching, but they clearly are more "geared" toward one application than the other.An Nch works best as a low side switch. Attach the source to ground, drain to your circuit, and all you have to do is bring the gate to about 2*Vgs(th) above ground for it to turn on and connect your circuit to ground.An Nchcanwork as a high side switch, but again you need to bring the gate ABOVE the source. So if you're switching 12V, it means you need to drive the gate to 2*Vgs(th) above 12V (say, 15-18V). This requires an additional power rail above your switched rail that you can use to drive the mosfet gate, which complicates things.A Pch works best as a high side switch. Attach the source to the power supply, drain to your circuit, and all you have to do is bring the gate down to ground (well, 2*Vgs(th) below your source) for it to turn on and supply power to your circuit. The only issue here is unless you're switching the same voltage as your MCU's Vcc, you can damage your MCU by trying to shut off the fet. The solution is to add an Nch to the mix, so your MCU drives the Nch, which drives the gate of the Pch. I described the wiring for this before.A Pchcanwork as a low side switch, but again you need to bring the gate BELOW the source, so if you're trying to ground your circuit with the fet, you'll need to bring your gate to 2*Vgs(th) below ground to turn it on. This requires an additional power rail below ground that you can use to drive the mosfet gate, which complicates things.Since Pch fets are more expensive than Nch, the last application above makes absolutely no sense, there's no reason you would use a Pch for a low side switch since an Nch is easier to use and cheaper. The other three are all viable though. Using an Nch as a high side switch is definitely more complicated than using a Pch, but since Nch fets are cheaper and generally have a lower Rds(on), it can make sense in some applications.Note: The "2*Vgs(th)" level I was quoting earlier is just an approximation. Vgs(th) is where the fet is just starting to turn on, you generally need to drive the gate to double that voltage to actually get a reasonable Rds(on), but you should check the Id vs Vgs curve for your particular fet to see what Vgs you actually need for your desired current flow and voltage drop.

author: jnz
author_rank: Frequent Contributor
timestamp: June 03, 2015, 04:51:08 pm
content: Quote from: suicidaleggroll on June 03, 2015, 03:22:01 pmThis makes 100% sense to me. Thank You very much for taking the time to write that out! I do get it. I'm slow, but I'm coming around. I don't have any immediate questions on it, and probably need to read a couple reads to process it fully.For all the effort involved. It seems MOSFETS aren't what I want and that push-pull setup in Kalvin's post doesn't seem too bad for number and cost of components. Although I suspect I'd be able to use smaller transistors with the mosfets, not certain on that yet.At the same time, I guess I should re-investigate the darlington pairs. I'm also not sure how one is just supposed to "know" what exists out there for integrated circuits that accomplish exactly what I want. By the time I go on mouser and get an NPN, PNP, schotty, resistors, and solder them, for all I know there is a SOIC-8 that was made to do all of this good to go at a cheaper price.

author: jnz
author_rank: Frequent Contributor
timestamp: June 03, 2015, 05:27:46 pm
content: Quote from: Kalvin on June 03, 2015, 12:34:36 pmKalvin, that absolutely helps! Thank you very much for making those! I could be wrong, but it seem to me that mosfets would allow for a smaller package size than a PNP transistor (esp when we get into the TO220 size)?Another assumption on my part; A typical darlington pair wouldn't work for me becayse I'd need a PNP version, and then I would be in the same boat where since I need to be high side, my micro couldn't handle pulling that PNP directly, yea? Any other disadvantages? I'm slightly concerned about the part count. And if we're really looking at TO220, the size.As to the size of the package. I have a 12V wire with a 75ohm coil in the relay, insignificant resistance in the switch. That should be E^2 * R = 1.92watts that will travel through the transistor. When I'm looking at the datasheet, I need to find one that has a power dissipation of 2watts or so yea? I'm sort of confused as to why this is easy to understand with MOSFETS with the RdsON value, but no such value for other transistors, am I to assume that other transistors appear to have a lot less resistance equivalent? (EDIT... wait... I need to look at the voltage drop on the transitor right? Look at what the transistor is absorbing right?)Thanks a ton to everyone here!

author: suicidaleggroll
author_rank: Super Contributor
timestamp: June 03, 2015, 06:21:45 pm
content: Quote from: jnz on June 03, 2015, 05:27:46 pmAs you worked it out in the end, it's the voltage drop across the transistor that matters when sizing it. Say you find a Pch or Nch fet with a 50 mohm Rds(on) at your intended Vgs. You now have 12V dropped across a 75 ohm coil in series with a .05 ohm fet. It's your classic voltage divider. You'll get about 160mA of current, which will drop 11.99 V across the coil, and the remaining .01 V across the fet. The fet's power dissipation will be around 1-2mW.

author: Fungus
author_rank: Super Contributor
timestamp: June 03, 2015, 06:41:09 pm
content: Quote from: jnz on June 02, 2015, 06:18:22 pmThere's plenty of MOSFETs that will work at 3.3V, eg. IRL540 has a threshold voltage of about 1.5V.The trick is to look for an 'L' in the name, it means 'Logic Level'. "IRL540" will work, "IRF540" won't.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2015, 06:53:15 pm
content: What about using theminimumlowparts count high side MOSFET switch option with a NPN common base level shifter?Connect a small signal NPN transitor: emitter to the GPIO pinvia a resistor, base to the 3.3V rail and collector to the P channel MOSFET gate. Add a high value pull-up resistor gate to source.With a 12V supply, that gives over 8V of gate drive and only needsthreefourcheap parts.Edit: See below - I forgot the emitter resistor to set the max GPIO current

author: jnz
author_rank: Frequent Contributor
timestamp: June 03, 2015, 08:43:54 pm
content: Quote from: suicidaleggroll on June 03, 2015, 06:21:45 pmCopy.And that's great because otherwise I wasn't finding transistors with even remotely the right pdiss.One thing tho... Are mosfets using rdsON and NPN/PNP fets using saturation because of the differences in mosfets being voltage actuated and other fets being current?In my case... Say I wanted to use this fet combo, using Kalvin's third example above.http://www.mouser.com/ds/2/115/ds31217-49093.pdfHere is what I worked out...At the NPN, the 1K and 3.3V signal is 3.3mA to pull on the FET. My reading of the datasheet means that'll be somewhere in the 50-75 dc gain, and .4-.5V saturation. That gain should be "good" up to 165mA yea?At the PNP then, it appears to be 12V and the 1K which will go into the NPN being a transistor to transistor load of 12mA, a gain of 100, and a load through that PNP of 168mA to the relay. Then .4V saturation there too.So I'm thinking a typical case in that package of .9v loss and 160mA being the transistor absorbing 144mW which is well under the power dissipation of 300mW, so shouldn't need anything near the size of a TO220 right?Or am I WAY off track here?

author: jnz
author_rank: Frequent Contributor
timestamp: June 03, 2015, 08:45:58 pm
content: Quote from: Fungus on June 03, 2015, 06:41:09 pmGood tip! Yea, I worked out the logic level mosfets later on.

author: jnz
author_rank: Frequent Contributor
timestamp: June 03, 2015, 09:03:51 pm
content: Quote from: Ian.M on June 03, 2015, 06:53:15 pmIs this what you're saying? Because I'd be very cautious that I'm grounding 12V at my micro. No?

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2015, 09:31:11 pm
content: That's right except you seem to have the MOSFET drain and source swapped. A P channel MOSFET needs to be connected with its source positive otherwise its body diode will conduct all the time.The NPN transistor emitter voltage cant rise above the base voltage unless the transistor is faulty (excessively leaky or shorted). The only disadvantage is that all the MOSFET gate drive current + the pullup current + the tiny bit of base current has to go through the MCU I/O pin so its no good for fast switching applications with large MOSFETs (high gate capacitance).

author: DrGeoff
author_rank: Frequent Contributor
timestamp: June 03, 2015, 09:41:45 pm
content: Or you could use a micro relay on your microcontroller output (suitable buffered if required) which provides a clean set of contacts to do whatever you like. As well as some degree of isolation.

author: jnz
author_rank: Frequent Contributor
timestamp: June 04, 2015, 11:02:34 pm
content: Ok, so, I took Kalvin's two normally open and IanM's minimal parts designs and put them in sim. They all seem to work well, but I have a bit of confusion maybe someone could help me clear up?In IanM's design, I'm seeing a LOT of current being sunk at my GPIO pin. Far too much really. For this project I will want to make my micro sleep and wanted the entire board to be under 1mA quiescent. So if I want to leave my interrupting transistor circuit "on" so that if the user presses the switch everything still works, I can't be wasting a lot of power on the BJT and the mosfet. There is maybe only one or two circuits I'd do this "constant" activation with, the rest can wait until I wake the circuit which means there is an infinite energy source plugged in.Here is what I drew up for IanM's design (please excuse the terrible appearance):It's saying approx 124mA being sunk at the GPIO which is way beyond acceptable. Granted, I kind of used a generic MOSFET because my sim program doesn't have a huge library.Here is what I got for Kalvin's middle example:Still too high at 3mA after the NPN. I kind of don't really get that voltage divider as well. It's 10k up and 1k between the gate and collector. That's a voltage of 1.11ish from 12V. If mosfets run on voltage and 1.1V works well, can't I increase the resistors on both sides to something like 1.11v ish at less mA loss down stream of the NPN? It would really only also help to make that 1K from the GPIO a 10K, but now I feel like I'd be getting into the gain and that's not something I really understand. Can anyone explain how to adjust these resistors?That 1.1V is just about the gate threshold at 1V. But the max for the gate is -12, so wouldn't -6 be a little safer to ensure the mosfet is going to react as it should?I'm on-board with the idea of how high and low side drivers need P and N channel respectively. But the resistances and gain is still confusing me. If there is any info anyone can add I'd appreciate it great!Thoughts?

author: Ian.M
author_rank: Super Contributor
timestamp: June 04, 2015, 11:54:26 pm
content: Sorry about that. I forgot it needs an extra resistor to set the pulldown current. between the emitter and the GPIO. Subtract Vbe from the 3.3V rail voltage to get the emitter voltage, then calculate the resistor to limit the current the GPIO sinks to an appropriate maximum. N.B. there is NO base resistor.That makes it less attractive as its now two resistors, two semiconductors, so you may prefer the simple MOSFET level shifter approach even though it needs a driver with a very low VGS threshold. or even the conventional NPN in common emitter with a base resistor to the GPIO..

author: Kalvin
author_rank: Super Contributor
timestamp: June 05, 2015, 07:25:24 am
content: Hi jnz,You can simplify my design a bit:1. D1 is only used to protect the gate if there should be any voltage bumps in +12V power supply. You can remove D1 if the mosfet can tolerate easily -12V gate voltage and you can guarantee that +12V will not bump to, say +20V, during transients which might violate the maximum gate voltage.2. You can also remove R2 if you remove D1. R2 is used only to limit the current through D1 in the case of D1 starts conducting.You still need R1, Q2 and R3 to drive the P-MOSFET.Btw, the voltage at junction of R3 and R2 doesn't have to go down to 0V. It is sufficient that the voltage at the P-MOSFET's gate relative to the P-MOSFET's source is negative enough in order to make the P-MOSFET turn on properly. The ball park estimate is that the gate voltage relative to the source voltage needs to be around 2*Vgsth. For example, if the Vgsth = -3V, the minimum voltage at junction of R3 and R2 should be about 12V - 2*|-3V| = +6V in order to make the P-MOSFET conducting and make the relay turn on.I also mentioned a PNP in TO220 (see my circuit suggestion #3 above). This was just a very crude estimate as it would allow currents up to 1A. As your maximum current is approx. 200mA, a cheap 2N2907 should do. 2N2907 is also available in TO-18 metal can for better thermal handling should the transistor get too warm. If the base current is 10mA ... 15mA, the 2N2907 should saturate well enough with -200mA collector current, thus the dissipation is approx. 0.2mA * 0.5V ~ 100mW.

author: mikerj
author_rank: Super Contributor
timestamp: June 05, 2015, 08:03:13 am
content: Quote from: jnz on June 02, 2015, 09:28:20 pmThe point is that for an N channel, the gate needs to be at a positive voltage with respect to the source pin. This makes things very easy for low side switching since you tie the source pin to ground, and your micro supplies it's 3.3v output to the gate which is enough to turn on a logic level MOSFET.If you want to use an N channel on the high side of your load, you still have to raise the gate voltage above the source voltage. The source voltage in this case will be your supply voltage (12v), so your micro has to apply the supply voltage plus whatever the required Vgs is to turn the MOSFET on, if it's 3.3v then you need to apply 15.3v to the gate pin. Obviously this adds a lot of extra complexity since you now need to generate this high voltage.With a P channel, the source is still at your supply voltage (12v) but now you need to apply a voltage to the gate which is negative with respect to the source. This is easy, since 0v is negative with respect to 12v. However, then you have the problem of switching the MOSFET off, since you now need to apply 12v to the gate pin to achieve this, and obviously your micro can't do this (unless it has a high voltage open collector output pin). In this case you need a second transistor to use a voltage translator. Another thing to note is that you must not exceed the maximum permitted gate-source voltage of the MOSFET, which can be quite low. You can use a potential divider or a zener circuit to limit the voltage if this is a problem.

author: dom0
author_rank: Super Contributor
timestamp: June 05, 2015, 08:13:29 am
content: Quote from: jnz on June 04, 2015, 11:02:34 pmThat's cause a PNP common-base circuit is not really suitable for switching DC. Change that stage to NPN common-emitter as I've shown above and the GPIO current will be <<1 mA.

author: jnz
author_rank: Frequent Contributor
timestamp: June 05, 2015, 06:27:53 pm
content: Quote from: dom0 on June 05, 2015, 08:13:29 amThe NPN pulling the PNP for the sigh side is a really common circuit. Is the only advantage over what you posted that it allows a close to 12V output from the PNP's emitter? Switching speed seems ok, because both NPNs get fairly positive voltage and ground when needed.I ran the circuit you posted in spice-ish.http://s7.postimg.org/cp8ikmujv/dom0_dual_NPN_low_Q.pngSeems good. It's normally closed which has pros and cons for me, I'll have to balance that out. Seems to be .256mA when the GPIO is putting 3.3V out which opens the relay circuit, and effectively no current when the GPIO is 0V which closes the circuit again. Great! But there is quite a bit 12mA of loss from 1K down to first collector when I want the relay to be off..... When I adjust that 1K to be higher to prevent loss, I'm also reducing the voltage to the relay (going to 10K gives me better loss, but only 5V at the relay). So I'm thinking I see the issues with this now.If I can get Kalvin's 3rd example with the NPN/PNP (which I've found other examples of online) to run off of higher resistances I feel like I can balance that out well with loss at the micro and overall. At least that's the current idea. The parts count is relatively low but I'm not sure if I can find parts in the right pacakges with the rain gain, etc.Maybe I'm way off with the issues of NPN/NPN vs NPN/PNP?