2

I'm using raspberry pi 2 for driving a motor,, using motor driver L293d, through gpio pins of RPI.

My question is,if some short circuit happens between input and output of L293d,,12v goes to RPI,and it may burn it.

How can we prevent that loss? If we can use any diodes to do that,what kind of diode we must use?

sarfaraaz
  • 67
  • 1
  • 7
  • As long as you are not abusing the chip, I'd say its a slim chance that a short circuit will happen, but as @Krunal Desai said, isolation is the best plan. – MadHatter Dec 28 '15 at 18:13
  • Of interest might be this article if you find your motors not behaving like you expect: http://electronics.stackexchange.com/questions/108686/what-h-bridge-drivers-are-preferred-for-applications-controlling-a-low-voltage-m – Andy aka Dec 28 '15 at 23:36

3 Answers3

3

You can try placing a 3.3V TVS diode (Semtech makes some) on the IO lines, but if you truly have a short circuit, all it will do is burn up first before the Raspberry Pi, making it kind of a moot point.

If there's a serious risk of this type of short happening, isolation is your best bet. You can use a optocoupler like a 4N49 to optically isolate the drive signal, preventing a short circuit from reaching your RPi. You may have to adjust my optocoupler recommendation to find a device that will happily tolerate a 12V condition on its output.

There are also ICs from Analog Devices that can perform galvanic isolation of digital signals (ADUM3xxx) if I recall correctly, but I don't think they can withstand 12V on their outputs either.

Is this an extreme risk scenario, where metal shavings may cause the bridging? Or is it to defend against poor assembly? At some point, I would weigh the additional circuit complexity against the likelihood of the event I am defending against.

Krunal Desai
  • 6,246
  • 1
  • 21
  • 32
3

There is a difference between full protection and most likely protection.

If you want full protection, I say, go with what Krunal suggests: Full isolation.

If you want likely protection, you need to think of the motor driver as using just an old-fashion-y transistor. It could possibly be fused or drain too much current in several paths and in that case limiting the amount of energy that can cost you is usually sufficient. As unlikely as this is, with high current spikes and other distortions when it comes to motors, it may not be unwise for various other reasons to consider.

In fact, these spikes, when looped "correctly" (from a design point of view that should say badly) through your ground system might be so annoying, that full isolation may be the easiest option anyway.

What you can do to limit the energy is several things:

  1. Connect a diode in series
  2. Connect a resistor in series
  3. Connect a diode in parallel
  4. A combination of the above

All four have different reasons. Sometimes your signal will take too much current to use a resistor, sometimes your signal will suffer from 0.7V from the simplest, smallest signal diodes in series. Sometimes, as sketched by Krunal, just a parallel diode (TVS or otherwise) may not help and just burn up first.

In your particular case, if I had reason to worry for fusing to either ground or 12V, but no extra reasons to want full isolation, I'd probably go for something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

If your MCU has a 3.3V supply, it's probably good to get a 3.6V TVS, as usually a 10% margin on the input is tollerable to the MCU, while if the MCU outputs a high, at 3.3V, it will not notice the TVS diode, since it only "breaks down" at 3.6V

If the input of the motor driver takes about 0.5mA, the resistor of 1kOhm will only "lose" 0.5V, which should be acceptable and I suspect the motor driver has a lower input current, though I'm too lazy to lookup the PDF of the number you gave myself to check whether this is true in all cases.

When the driver suddenly becomes a hard 12V output, even if the TVS avalanches to short, the resistor and TVS will never see more than 12mA (12V over a 1k resistor). If your motor driver needs more current on the input, your resistor may have to go down a little in value, but then you should start looking at power dissipation in your resistor and TVS for the higher currents when the chip shorts to 12V.

Of course, put the protection as close to the intelligent chip (MCU) as you can, to protect against as many problems as possible.

To Note:

I rehash that this does not at all protect against everything, but it protects against the most likely problems with 12V motors.

One may be tempted to use the old diode to VCC trick as an alternative to the TVS, like this:

schematic

simulate this circuit

In theory this works just as well, since your 3.3V is strongly regulated, and the BAT54 schkottky diodes at 10mA haven't got a very high forward voltage drop, so the input will likely not see much more than the 3.6V peak we had just before.

BUT: You must always look at what happens in all cases.

Let's say your MCU only uses 5mA on average, now what happens when the motor driver shorts to 12V on only one pin (let alone all of them):

the 1kOhm resistor has 12V on one side, and the MCU drains on average 5mA, and the regulator is only designed to give current, not take it (in most cases). So the resistor has on average no more than 5mA running through it, because any more current can't go anywhere.

So the voltage drop, according to Ohm's law across the 1kOhm resistor can not be more than: V = I * R = 0.005A * 1000 Ohm = 5V, which leaves 7V at the anode of the diode, which makes for 6.5V-ish on the MCU. I think it's very likely it will not enjoy that very much. Nor will the voltage regulator, even if it manages to compensate it down to nearly 3.3V.

And that's using the average MCU current. Not even the lowest possible. And you should always use the lowest possible in this "worst case" estimation, because at the lowest current you have the highest peak voltage.

So if you do go by that trick, as many sites still may suggest, you first need to very carefully consider the resistor value and the lowest current use of your digital system and often these days you will soon figure out that the resistor needs to be too large, or that the other risks are just getting too high. Thing is, this trick comes from the days boards had so many chips warming up that 1A or more on the 5V VCC rail weren't uncommon in professional logic systems.

Asmyldof
  • 18,299
  • 2
  • 33
  • 53
  • 1
    This is a good answer -- the combination of series resistor and TVS should be pretty solid. The input cap of the motor controller is probably on the order of 10pF and the PWM frequency is probably less than 1kHz so I think the RC effect can be neglected. – Krunal Desai Dec 28 '15 at 19:01
  • 1
    @KrunalDesai While I think your answer (+1 ;-) ) adds good insight on full protection, I thought I'd add some info about "what may well do", as the answer is long already I decided to not google the PDF, but I assumed 1k would be fine, 10k would probably still and possibly even a 100k resistor, depending on unspecified parameters. But thanks for the confirmation :-) – Asmyldof Dec 28 '15 at 19:03
  • 1
    I just remembered that the L293D is a bipolar device -- as long as the series resistor allows at least 100uA, he should be good (so 10k should be more than OK). – Krunal Desai Dec 28 '15 at 19:36
0

One way that is not quite as foolproof as adding opto-isolation (but cheaper) is to add CMOS buffers with some series resistance (such as 10K). In case of a fault only 1.2mA will flow which is unlikely to damage the RPi.

If you add opto-isolation, I would suggest adding logic output optocouplers such as 6N137s which add very little delay, especially if you intend to PWM the motor drive.

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842