1
\$\begingroup\$

I have a microcontroller interfacing with a normally-open automotive relay on the high-side, through a P-MOSFET. When the microcontroller closes the P-MOSFET's Source & Drain (by sending LOW signal to Gate, causing Vgs < 0), the auto relay is powered and closes a separate high amp circuit (not relevant for this question).

The automotive relay does not have a flyback diode, meaning I have to deal with a reverse voltage spike between the relay and the P-MOSFET.

Following this tutorial, I ended up with this working circuit:

circuit

Notes

  • Microcontroller is powered by the car's battery, via step-down converter.
  • Both grounds in circuit are identical (car chassis)
  • I cannot modify my interface with the relay or anything around it; I only have access to the wire that runs to its + coil pin (represented as above as "Load"), so that's the only place I can deal with the reverse voltage spike.

What would be the best way to prevent a spike at the MOSFET's D pin when the relay is opened?

PS: I'm very new to this sort of project, so if you spot anything that's obviously broken with the setup above, please advise! For the first prototype, I had a relay instead of the MOSFET and that worked fine, but I'm looking to a) downsize the circuit by using transistors, and b) learn more about electronics by trying out different components.


Note: While the original question was about how deal with reverse current coming out of the JD1912 relay, I ended up building an entirely different circuit (see accepted answer).

\$\endgroup\$
10
  • 1
    \$\begingroup\$ Unambiguously mark on your diagram with (say) red cross or circles, which nodes you do have access to. It's unclear from your words. \$\endgroup\$
    – Andy aka
    Aug 20 at 10:04
  • 1
    \$\begingroup\$ Why is 3.3V out shorted to 12V? Does the converter isolate, and you intend to use 3.3V as FET source so you can drive VGS to -3.3V? Also, the FET barely turns on at all at 3.3V gate voltage, you need more than that. \$\endgroup\$
    – Justme
    Aug 20 at 12:51
  • \$\begingroup\$ @Justme I confess I don't know why or how that bit works but it does work. I edited the post to include a link to the guide I followed. The gate turns on just fine, the FET's Vgs(th) is -3V (min max being -2 and -4V). \$\endgroup\$
    – biasedbit
    Aug 20 at 18:45
  • \$\begingroup\$ @biasedbit Please show which exact 12V to 5V converter you used. A generic LM2596 buck converter would not be isolated and the circuit would go up in smoke. Please also show how you connected them in real life, maybe the schematic does not match what you built. \$\endgroup\$
    – Justme
    Aug 20 at 19:30
  • \$\begingroup\$ @Justme I used one of these amazon.com/Zixtec-LM2596-Converter-Module-1-25V-30V/dp/… \$\endgroup\$
    – biasedbit
    Aug 20 at 19:36
1
\$\begingroup\$

In the application note you linked to, the only thing I found that might concern drain protection is the gate-to-drain clamp diodes. However these are really for mitigating large voltage excursions that may otherwise cause gate isolation to fail. In fact, I would suggest that those clamps will even expose whatever is driving the gate to the extreme drain voltages generated by the relay coil. In your case, that's a puny, fragile microcontroller. I do not consider those devices to be a good choice for your application.

You still need to quench those coil voltage spikes yourself, somehow.

Your module clearly has access to battery +12V, ground (chassis, battery 0V) and the top end of the relay coil. I can't see why you are unable to install a diode (inside your own module) between ground and the relay's coil connection. It would still effectively be across the relay coil, even though it may be physically located far from the actual relay. There might even be an argument for installing the diode close to the things it is trying to protect:

enter image description here

Whatever that "3Vout" is on the microcontroller, are you sure you want it connected to +12V? It seems foolish to connect anything in a microcontroller to something greater than its own supply, though I may be missing something.

Lastly, the microcontroller output will need to be an open drain, or high impedance, in order to allow the 10k pullup resistor to raise the FET's gate voltage to 12V. Otherwise you will not be able to switch the FET (and the relay) off. This is the curse of the high-side transistor switch.

Addendum

In light of your comments, and the video link you added to to the question, here's an addendum:

The video you mentioned does obliquely refer to the need for 12V to switch off the FET - he says that to control this high-side P-channel MOSFET switch using an Arduino requires an isolated supply, and that you must connect the Arduino's +5V supply and the motor's +12V supply together, to "raise" the Arduino's logic outputs to the levels required by the the MOSFET's gate.

However, the "Riorand" converter module, like most that use the LM2596, probably has the -Vi and -Vo terminals connected together, meaning that it is not isolated.

In your circuit, then, you are implicitly connecting the Arduino's 0V ground to the car's ground, via the buck converter, which in my opinion is the correct thing to do. It does mean, though, that the digital outputs of the Arduino cannot attain the +12V level needed to switch off the FET, and you must somehow translate the 0V to 5V output from the Arduino into a 0V to 12V signal for the MOSFET gate.

And you must dispense with that "3Vout to +12V" nonsense.

It's not hard to do, with another transistor, as Spehro Pefhany has demonstrated in his answer - though I think his value for R5 (and probably R6) is unnecessarily low in this application. For completeness, I include here an adaptation of Spehro Pefhany's use of a BJT to perform this level translation:

schematic

To see why all this is necessary, first understand that the MOSFET Q1's gate must be near +12V in order to switch it off. That means whatever source of voltage is driving the gate must be capable of outputting +12V.

If, as suggested in the video, the Arduino's positive supply is connected to the battery positive, +12V, and you somehow manage to provide the Arduino's ground pin with a voltage 5V below that (i.e. +7V), then its digital output levels are effectively +12V and +7V, which will work fine for the MOSFET.

However, you cannot obtain +7V from the LM2596 (at least, not in a way you can use here). It cannot provide 5V lower than +12V, it can only give you 5V higher than 0V. This is what is meant by it not being "isolated". So you are forced to share a common ground between the vehicle (chassis, battery negative) and the Arduino, whose outputs will therefore be 0V or +5V, not +7V or +12V.

You need a 12V signal to switch the MOSFET off, so Q2's function is to translate (and invert) the Arduino's 0V and +5V output levels into +12V and 0V respectively.

\$\endgroup\$
6
  • \$\begingroup\$ Interesting point on that diode placement! I kind of assumed that current would just flow backwards from the relay back to MOSFET's D pin and that I had to figure out a way to route it somewhere if it exceeded a certain voltage threshold. Thanks for the suggestion! \$\endgroup\$
    – biasedbit
    Aug 20 at 19:02
  • \$\begingroup\$ As for the 12V to MCU's 3V out pin, I don't really know exactly how that works -- but it does work. I updated the original question to include a link to the tutorial I followed. There's a comment in the video about how the P-MOSFET "must be connected to the VCC side of the circuit." and how in order to achieve that, one has to "pull Arduino 5V and the positive side of the 12V power source to the same level". I was thinking of creating another post to try and get someone to explain what that's all about :) \$\endgroup\$
    – biasedbit
    Aug 20 at 19:09
  • 1
    \$\begingroup\$ Considering this new information, I've ammended my answer. \$\endgroup\$ Aug 20 at 21:14
  • \$\begingroup\$ Brilliant, thank you for your patience and thorough explanation! 🙌 \$\endgroup\$
    – biasedbit
    Aug 20 at 21:25
  • \$\begingroup\$ Built it out and it works as expected! Video (LED as the flyback diode just for this prototype, to actually see the reverse current spike.) Thank you, @simon-fitch. \$\endgroup\$
    – biasedbit
    Aug 20 at 23:03
4
\$\begingroup\$
  1. The 12V is connected to the 3V regulator out. That will instantly destroy the MCU.

  2. You cannot switch a 12V p-channel MOSFET with a 3V output. It will stay on all the time (since Vgs = -9V and it needs to be much closer to zero). So, you will need a high-side driver, at least an additional transistor (NPN or N-channel MOSFET) to drive the p-channel. Or one with an open-drain capable of safely >>12V but you're not going to find that.

Here, from the Arduino forum, is a standard kind of high-side driver suitable for (only) slow-switching applications and having a flyback diode across the load.

Where they've shown a 3.3V rail connected is where you connect your MCU output. The additional parts also reduce the likelihood that your MCU will be killed by contact with 12V due to MOSFET failure etc.

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ I've updated the post to include a link to the tutorial I followed for the high-side switch. I confess I don't really understand why that 12V is connected to the MCU's VCC but it does work and nothing is getting fried (the MCU's ground is not the same as the 12V power supply's ground). As for adding a flyback diode across the load, I mention in the post that I cannot do that, as I only have access to the high-side of the load, meaning the wire that goes to the car's relay. \$\endgroup\$
    – biasedbit
    Aug 20 at 18:53
  • 1
    \$\begingroup\$ Looks like the only reason why I haven’t burned this thing down is because I haven’t actually hooked the circuit to the car, and I’m powering the MCU via USB. I can understand how the circuit you propose works — unlike the one I’ve drawn, which was largely based on my (mis)interpretation of a tutorial. For the fly back diode, I’ll try Simon’s suggestion in the other answer. I’m going to prototype this and will circle back to accept your answer. Cheers! \$\endgroup\$
    – biasedbit
    Aug 20 at 20:37
  • 1
    \$\begingroup\$ The diode in Simon’s schematic is connected identically, and is almost the same part number (1A and rated for 1000V rather than 400V), either type is more than good enough. \$\endgroup\$ Aug 20 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.