Tripped up by my over-reliance on the LM317 (trap for young players?) - Page 1
Forum section: electronics / beginners

author: mindcrime
author_rank: Unknown
timestamp: June 22, 2022, 12:43:08 am
content: 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 wholestorydebacle 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 areasonwhy 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.

author: sleemanj
author_rank: Super Contributor
timestamp: June 22, 2022, 01:00:37 am
content: 1.5A is a tiny part of the story, that 317 can do 1.5A **if you can keep it cool**.Power Dissipation is the phrase of importance, 13 - 5 = 8v you have to lose, at 1.5A that is 12W you have to get out of the TO-220 fast and continuously.You need some fairly substantial passive heatsinking to get that 12W discarded, or a smaller heatsink and a modest fan.

author: mindcrime
author_rank: Unknown
timestamp: June 22, 2022, 01:19:16 am
content: Quote from: sleemanj on June 22, 2022, 01:00:37 amThe thing is, even 1.5A is borderline for a Pi, at least if it's running full tilt. IIRC the recommendation is to use a supply capable of sourcing 3A, which is approximately twice what the LM317 can handle.That said, your point is valid. And with sufficient heat-sinking and fan, I might be able to scrape by with the LM317. But I think going with the LM338, and a good heatsink, and possibly a fan, will give me a little bit more margin for error.And in the end, this might all be a waste, because this power supply might have the same crappy turn-off behavior as the other one. But that's OK. I'm simultaneously pursuing another strategy to try and account for the lack of that nice crisp falling edge on the signal that I was expecting. Early indications are that this approach will work ( a small scale simulation on the breadboard works anyway), but the acid test will be doing it with the Pi running and see if it can handle the switch without rebooting.I'm tellin' ya... I've dabbled in hobby electronics on and off for probably close to 40 years now and I've probably learned more in the last two months than I did in the previous 40 years combined. :-) This has been a challenging, but educational, process.

author: bdunham7
author_rank: Super Contributor
timestamp: June 22, 2022, 01:56:05 am
content: Quote from: mindcrime on June 22, 2022, 01:19:16 amFor running a Raspberry Pi I wouldn't think you'd need a linear regulator. A buck converter or a DC-DC converter module would be simpler and more efficient.https://www.mouser.com/datasheet/2/468/RPM_3_0-1398189.pdf

author: mindcrime
author_rank: Unknown
timestamp: June 22, 2022, 02:05:22 am
content: Quote from: bdunham7 on June 22, 2022, 01:56:05 amI didn't have any handy when all of this was going on. I actually ordered a few that just came in earlier today. I have some of those SEPIC converters coming as well. I started down the linear reg path just because I always have a few 317's in the parts box.Ideally I'll be switching back to a 5V supply anyway, and won't need any of this down regulation stuff. This was really just an experiment to see if I might get lucky and find a Closet of Despair part that would, by happenstance, be more suitable for what I was doing. I'm not going to invest a whole lot in trying to work with 13V as my main supply if I can help it.

author: Zero999
author_rank: Super Contributor
timestamp: June 22, 2022, 09:02:21 am
content: A series resistor before the input capacitor on the regulator can help dissipate some of the power, so it doesn't all get burned inside the regulator. Aim for a voltage drop which will give 3V higher, than the regulator's output voltage at maximum load and minimum acceptable input voltage.Example: your power supply is 12V, when fully loaded with the maximum load of 1.5A and the output voltage is 5V.5 + 3 = 8V12V - 8V = 4VR = V/I = 4/1.5 = 22/3R, so use 2R7, or 2R4.P = VI = 1.5*4 = 6W, so use a much higher power resistor, say 8W, or 10W.Anyway the LM317 is just a distraction. You should work in fixing your voltage switching circuit so it will work off the 5V power supply and not reboot when the voltage is slowly ramped up/down.

author: wraper
author_rank: Unknown
timestamp: June 22, 2022, 09:35:11 am
content: Quote from: mindcrime on June 22, 2022, 12:43:08 amLM338 without a heatsink will behave exactly the same. Current rating without considering power dissipation means nothing.

author: bdunham7
author_rank: Super Contributor
timestamp: June 22, 2022, 01:51:24 pm
content: Quote from: mindcrime on June 22, 2022, 02:05:22 amOK, if you are hacking something temporary together from spare parts, you can use two LM317 or LM7805 in parallel if they are attached to the same heat sink right next to each other. A dropping resistor wouldn't hurt either, depending on what you have in your closet. I keep chunks of aluminum around for one-off heatsinks, even if temporary. My closet overflows...

author: mindcrime
author_rank: Unknown
timestamp: June 22, 2022, 02:21:37 pm
content: Quote from: Zero999 on June 22, 2022, 09:02:21 amYep. I have already thrown together a circuit that can detect when the voltage drops by a small delta and then send a signal that can be used to switch a transistor or whatever. I believe if I tune it carefully enough, I can detect the falling edge soon enough and do the switching so that nothing bad will happen. Adding a larger reservoir capacitor on the output of my board to provide more buffering might also help.

author: David Hess
author_rank: Super Contributor
timestamp: June 22, 2022, 03:42:24 pm
content: Quote from: sleemanj on June 22, 2022, 01:00:37 amA TO-220 package *by itself* can handle about 2 watts, and this applies just as much to the higher current 3 amp LM350 and 5 amp LM338 as the 1.5 amp LM317.

author: mindcrime
author_rank: Unknown
timestamp: June 22, 2022, 03:53:47 pm
content: Quote from: WraperQuote from: David Hess on June 22, 2022, 03:42:24 pmAbsolutely. That's why I ordered a box of TO-220 heatsinks and a new tube of thermal paste.I know I already have some heat sinks here somewhere, but I'll be darned if I could find one the other night. I desperately need to reorganize / straighten / label my parts collection... *sigh*