I recently finished building a circuit showcased in a beginner’s electronics book. I have included the picture of my creation below because I think it may become relevant to the question.
At the beginning of the build process, the instructions specified to add a "smoothing" 100 microfarad capacitor to be placed right by where the power supply cables were connected to the board. I decided not to bother with that step because I was using a quality power supply so I didn’t think I needed that "smoothing" capacitor (big mistake).
It wasn’t long before I started experiencing weird and inexplicable odd circuit behavior and after a lot of troubleshooting and getting nowhere, it occurred to me to add the smoothing capacitor to the circuit. As soon as I added the capacitor to the circuit the problems went away, but I found myself wondering how is possible that such a capacitor mattered so much given that my circuits uses a measly 50 milliamps of total power and I have what I think is a reasonably good power supply (Rigol DP832).
To make matters more interesting, I decided to move the smoothing capacitor away from the center of the board off to one end of the board and to my surprise the problems began again. Why such a big difference just by placing the capacitor in a different place on the board?
I decided to add a beefier 8200 microfarad capacitor (that is 82 times bigger than the previous one) thinking that this would put an end to all my problems but to my surprise once again, that still did not fix the problem. I actually had to move the capacitor back to the center of the board to make things go back to normal.
That wasn't the only issue, even with the capacitor in "perfect placement", I tried to power a small mechanical relay by using the same power from the circuit and every time the relay triggered my circuit would “reboot”.
So the question is, are all circuits that sensitive to even the smallest change in electric fluctuation? Or is the problem due to my cheesy circuit prototyping skills and an inefficient breadboard?
The IC used in the circuit are:
- NE555P (Precision Timers).
- CD4026BE (CMOS Decade Counters/Dividers).
The advised capacitor is a long-lead buffer, so to speak.
Even if you had a perfect power supply, the cables that run to your design are far from perfect. And that's not your fault, it's just how cables are. I believe some rapper wrote a song about that... I'm pretty sure it was about cables anyway.
Your cables firstly pick up noise. Secondly they have silly characteristics that you will learn about later at some point in more detail, but basically for high frequency signals (such as digital circuitry makes) they have a very high reluctance to conduct current, possibly even only 50 mA. Those signals are hard to transport over just any cable. You can see it for now as the cables being a bit slow to react. If you switch on a current they will take some time to supply that steadily, so if you switch it often, you'll start to notice a lot of noise on the power supply.
Adding that capacitor will allow your high frequency switching currents to be taken from the capacitor, so the cables can supply just the short-term average, and normal DC leads are very good at short term average near-DC, they can do many amps at that and so can your supply: Everyone happy.
In fact, many design guides for voltage management or voltage regulator chips specify an input capacitor of 2.2 μF, for example, parallel to a dotted 22 μF or larger, with an asterisk saying "if the incoming power cables are longer than X or Y, regardless of power supply used, add the 22 μF (or more) capacitor for stability and better noise rejection".
It may even be better to keep the 100 μF capacitor, because the 8200 μF capacitor will have a larger internal resistance, unless it's also much, much larger physically. The internal resistance of a capacitor determines how good it is at taking away the ripple of low-current high frequency signals. Smaller is better in most cases with first input capacitors like this one. But, with voltage regulators, that doesn't always apply for all input/output capacitors, so once you get to those beware! But that's not for now.
You can be happy about not everything being this sensitive, slowly switching or high frequency digital alike, there are many robust things that are much less sensitive to reboots, but it is often still a very good idea to add some capacitance if a board or design is powered with wires or sometimes even through a connector between boards. It doesn't always have to be as large as 100 μF, but a little to take the edge off (pun for the more weathered reader intended). Having no noise to work with is always better than having to work with noise.
The reason the capacitor between the power wires and the circuit works better than the circuit between the power wires and the capacitor is because the trace inductance (whether it's a PCB or bread board) will limit the response of the capacitor, if you then have power wires nearby, your circuit will ask them to supply some of the current as well, which will cause the same kinds of dips, but possible in a lower order. You are already basically putting your switching noise onto the cables and the cables already react to it. When your noise sees the capacitor first, even with some inductance in the traces, the noise will not go into the cables and not cause any further problems, which reduces the noise your circuit sees by a much greater factor.
Edit: Note: The above about capacitor position is severely simplified in some respects, but it generally conveys the idea well enough. To clarify it should suffice, but there are many dynamics to things like this. In later years looking back, you may find this to be a bit lacking. But you don't need to know all that right now. This will do.
The reason with a relay and a capacitor and shared power things go wrong, still, is because the current spike of your relay is too large for the capacitor to help with and then the cables can't keep up either, or because the relay release creates a voltage spike. A solution could be, if your design can handle a diode-drop:
simulate this circuit – Schematic created using CircuitLab
D1 prevents anything powered by the DR832 from stealing power from your digital buffering capacitor C1. D2 prevents the relay from making any significant noise on your supply and D3 catches any power spikes the relay still makes when you turn it off.