Electronic – How to know where I need decoupling capacitors

capacitordecoupling-capacitormotor

I'm building a motor driver shield for the Arduino. Here's the schematics (please forgive the messy layout):

enter image description here

And here's the PCB layout:

enter image description here

I'm testing it out by breadboarding it while running a simple 'run for 5 seconds then reverse' procedure on the MCU, and I'm experiencing some odd issues with decoupling capacitors. If I leave them off, the motor stutters rather than moving smoothly, presumably due to the motor's power rail dropping. I put a 100uf electrolytic capacitor across it (shown on the board), and it started running smoothly.

Now, however, the motor reverses seemingly at random, I presume as the MCU is being reset for one reason or another. Following the 'more capacitance is better' mantra, I installed the second electrolytic cap, between the 5v and ground rails. Now, weirdly, we're back to step 1: the motor stutters.

Finally, I added a third, 0.1uf ceramic cap across the motor terminals. Suddenly, everything is fine: The motor runs smoothly, and it reverses when it's supposed to.

Adafruit's shield seems to solve the issue by just throwing lots of caps, both electrolytic and ceramic, at the problem. Unfortunately, as you can see, I have quite limited PCB space, so I can't afford to do that. I could take the cargo-cult approach and say "it's working now, great" and stop, but I'd rather understand what it is that caused each of these symptoms, and what I should do to ensure they don't happen on the real board.

The first answer to this question answers most of my obvious queries about capacitance, but I have a couple of remaining ones:

  • Is the 100u and 0.1u cap between the 5v (logic) rail and ground that Adafruit's shield has necessary? Removing it on my breadboard seems to have no effect.
  • Do I need the 0.1u ceramic caps across both the motor rail on the H-Bridge input and directly across the motor terminals?

Edit: I've updated the schematic and PCB layout with the proposed positions of caps, based on the advice of those kind enough to answer my question.

Best Answer

All digital ICs should have decoupling caps between their power and ground pins. These should be ceramic and physically as close as possible to the IC. You want to minimize the loop length from power pin to cap to ground pin thru the IC and back to the power pin.

Decoupling caps deal with short term current spikes the IC draws. They must therefore be high frequency. Large capacitance is not necessary, and since large capacitors usually have poor high frequency response, they are worse. A 100µF electrolytic cap is pretty useless for decoupling. 1µF to 100nF ceramic is good.

As for the cap on the motor, the idea is good but I think 100nF is too large. That could cause excessive or unnecessary current to flow in the H bridge every time it switches. If you're only reversing motor direction occasionally, then this isn't a big deal. If you're using the H bridge to modulate the apparent motor drive with PWM, then you should lower the cap. Something like 1nF should still cut down the noise the motor is making while not getting in the way of switching.