6
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Possible duplicate of electronics.stackexchange.com/questions/15422/… \$\endgroup\$ – Federico Russo Jul 20 '11 at 10:15
  • \$\begingroup\$ I don't think it's an exact duplicate, but there is useful information there in @stevenvh's answer. I could still use advice on which caps are necessary, where in my case - for instance, do I need one electrolytic cap per motor, or will one 100u cap do for both? What are the implications of putting the cap before or after the H-Bridge? \$\endgroup\$ – Nick Johnson Jul 20 '11 at 10:32
  • 1
    \$\begingroup\$ On reflection, this does answer most of my questions, and makes Adafruit's design much clearer. I'll update my question to reflect my remaining queries. \$\endgroup\$ – Nick Johnson Jul 20 '11 at 10:34
  • \$\begingroup\$ you can directly link to the answer to a question. If you hover over the answer's edit you'll be shown the answer's post ID. Append to the question's URL: <question's URL>/<post ID>#<post ID>. (I don't know why you have to add it twice, but it seems necessary) \$\endgroup\$ – Federico Russo Jul 20 '11 at 11:01
  • 1
    \$\begingroup\$ You've got all kinds of room on that board! Just switch to SMD parts: Your ATtiny is 1" by 0.3", it could be 1/2" by 3/8" with an SOIC part or just 0.15" by 0.15" in QFN. Even if you don't want to do that for solderability reasons, 0805 ceramic caps will help solve your problem, and you've still got ample room for that. \$\endgroup\$ – Kevin Vermeer Jul 20 '11 at 13:18
7
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ How do you decide how big the motor decoupling caps should be - rule of thumb? Is the answer different if I'm decoupling between ground and each motor line rather than between the two motor lines (and how should I choose between those options)? \$\endgroup\$ – Nick Johnson Jul 20 '11 at 13:41
  • 1
    \$\begingroup\$ @Olin - The 100uF electrolytic is indeed useless for decoupling, but it (and the tantalum caps that are used for similar reasons) are useful for other reasons. A 0.1uF cap can handle the high frequency stuff that gets coupled onto the power lines (and thus needs decoupling), but can't handle the long-term energy spikes that the larger caps will absorb. \$\endgroup\$ – Kevin Vermeer Jul 20 '11 at 14:16
  • 1
    \$\begingroup\$ @Nick - You can decide in one of three ways: (1) Rule of Thumb - see Steven and Rocket's posts, or Johnson's Handbook of Black Magic (2) By understanding the operation of high-speed electromagnetic circuitry - see Paul's Introduction to Electromagnetic Compatibility and/or take an EMC course, or (3) use the cargo cult "It works now" approach. 1 is easy, 2 is hard and quite safe, and 3 is easy and not safe. \$\endgroup\$ – Kevin Vermeer Jul 20 '11 at 14:28
  • 1
    \$\begingroup\$ @Nick: The cap accross the motor is not a decoupling cap. It is there to reduce the speed of the voltage transients, and thereby reduce overall noise generated by the motor. It is a tradeoff between big enough to reduce the dV/dt enough and small enough to not waste too large a charge every switching edge. As I said, my gut feel is that 1nF is better than 100nF, unless possibly you are switching infrequently. \$\endgroup\$ – Olin Lathrop Jul 20 '11 at 16:40
  • 1
    \$\begingroup\$ @Kevin: I agree about the lower speed bulk storage. I thought we were talking about decoupling. The complete design needs both. \$\endgroup\$ – Olin Lathrop Jul 20 '11 at 16:41
7
\$\begingroup\$

It's not because removing caps doesn't seem to have any effect that you shouldn't use them. It may work now, but not in an hour or so.
The principles are

  1. Place caps on the source of the disturbance, so that it doesn't conduct to susceptible components, or radiates via the wires
  2. Place caps on susceptible components. Your disturbance source may not be the only one, and you can't always rely on the others being properly decoupled
  3. Use a bigger and a smaller capacitor. The bigger one will absorb most of the disturbance's energy, but isn't very good at high frequencies, where the smaller one takes over.

Is it worthwhile to decouple the same disturbance source twice, over different components? Most likely yes, you can't decouple too much. I remember a colleague's design, where half of the components (about 200) were decoupling capacitors.

\$\endgroup\$
  • 3
    \$\begingroup\$ It's also difficult to evaluate effective decoupling on a breadboarded circuit, since the breadboard will likely have very different impedances than a PCB. \$\endgroup\$ – Adam Lawrence Jul 20 '11 at 13:54
  • \$\begingroup\$ @Madmanguruman - I think the problem with breadboarding will be more about placement: placing the caps as close as possible to the device. \$\endgroup\$ – stevenvh Jul 20 '11 at 18:28
  • \$\begingroup\$ It's quite difficult to reliably breadboard switchers in general. Things like minimizing loops, adding current sensing, etc. are difficult enough with a PCB layout. A pseudo-3-dimensional construction may actually work better than what you can achieve in 2D on a PCB - sometimes it won't work at all. You should be defensive with decoupling - put more than you think you'll need, and simply nopop the ones that are found to be extraneous. (That, and don't always trust a breadboard. Or a new PCB layout.) \$\endgroup\$ – Adam Lawrence Jul 20 '11 at 20:23
  • 1
    \$\begingroup\$ If you're looking for other designs that have lots of caps, just take a look at your graphics card or motherboard, especially on the opposite side of the processor. Caps everywhere, and the vast majority are for decoupling. \$\endgroup\$ – Kevin Vermeer Jul 21 '11 at 13:53
3
\$\begingroup\$

I'd follow approach with 1 goal: minimize the area for each AC current loop, coupled to power lines (Vcc and ground).

  1. Make list of all power nets: say, total 2 entires on list : V+, ground.
  2. Identify ports, connected to this nets, carrying power: 2 or more per IC package, active element
  3. Split list of this ports (total say ~15) into pairs, by relevance to package with possible duplicates on ground ports or V+ ports.
  4. Add 1 capacitor per each pair
  5. In layout move capacitor closer to ports to reduce the area of loop, formed by 2 leads of capacitor and 2 ports of the pair.

Effectively this will shorten the current path to minimize voltage drop, spikes, caused by line inductance and will isolate max(dI/dt) current loops each from other magnetically.

\$\endgroup\$

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.