Lately I've been working on a project involving a Raspberry Pi, and I have a requirement to be able to connect it to two power supplies (for example, a USB "power bank" device and a mains powered USB charger) and have it automatically switch to and from the "preferred" source as that source comes and goes.
OK, getting something working on that front was an adventure in it's own right, and FSM willing I'll write up that whole story debacle one of these days. But anyway, in the end I did have a device working, with a big "but".
The issue was, if I killed and re-added one of the sources by physically yanking the USB cable out of the corresponding device, and plugging it back in, all worked perfectly. Note that one of my requirements is that the Pi not glitch or reboot as a result of the switch in power sources.
Then I started testing with what happened if I took the AC mains powered charger and unplugged it from the wall. Aaaaand you can probably guess where this is going. It didn't work. The charger has enough internal capacitance and apparently either intentional current limiting and/or just really high output impedance, to the point that instead of a really crisp edge to signal the transition in the signal, you get a sort of a stepped, jaggedy ramp down instead. And that affected the timing of my switching and causes the Pi to reboot. Rut roh!
"So", I think to myself, "maybe I just need a different power supply that has behavior more in line with what I'm expecting." With that thought in mind I start rummaging through the big ole box of old power supplies in the Closet of Despair and eventually drag out some random "13 point something" volt power supply that's rated for 3A or so. Of course I can't run a Pi off of 13.x volts, so I figure I'll hack together a quick little board to down-regulate the voltage to about 5.1 or so and call it good.
I reach, out of instinct, for my old friend the LM317, whack in a resistor and a potentiometer, connect it to the grumbly old 13.whatever supply, twiddle the pot a bit and get a nice, beautiful 5.2 volts. Perfect. Hack up a connector to connect it to the Pi, plug it in and... the Pi starts to boot! Yay! We're saved.
Yeah, no. The Pi *starts* to boot, but gets part way through the boot cycle and reboots. Wut? And here's where my stupidity kicks in. I convinced myself that the problem was most likely that this ancient, creaky old power supply just had too much ripple in it's output or something and the Pi was finally getting tired of it and throwing it's hands up and saying "da fuq?"
So I toss that decrepit old supply back in the Closet of Despair (I mean, there's a reason why it's called the Closet of Despair to begin with, ya know?) and move on.
Later that night I'm about to crawl into bed when this weird, random thought flitters into the edge of my consciousness: "Don't LM317's have automatic thermal shutdown if they overheat? And wasn't I running that with no heatsink? Can an an LM317 even power a Pi on its best day? What's the max current rating for an LM317 again???"
Right. Today I get home from work, set that experiment up again (braving another visit to the Closet of Despair) and tape a thermocouple to the LM317 and attach it to my thermometer. And turn on the Pi. And watch the temperature go up... and up.... and up... and up... and *reboot*.
Yeah. Not much question now. Double checked the datasheet and the LM317 is rated for 1.5A. That's a touch light to run a Raspberry Pi.
Anyway... now I know. So I ordered some LM338 regulators that can handle 5A (7A burst), a box of TO-220 heat sinks and some thermal paste. Soon I'll have a proper regulator and can get back to answering the question of "Does this power supply serve my purpose better than the RAV Power USB charger I was using?"
The moral of this story? The ubiquitous LM317 is your friend, but... it's not magic. It has limits. Like a 1.5A (approx) current limit and a maximum temperature. And that handy thermal cutoff feature which helps avoid destroying components, but which can really trip you up if you aren't thinking about thermal factors.