EEVblog'ers, I'm at my wits end here
and hoping somebody can help. I have a circuit that I built, and that essentially works, with the caveat that it sometimes goes into a pathological state and a 74HC08 AND gate starts to overheat badly and is apparently being asked to source too much current.
First let me apologize for not posting a schematic. I know that would help, but I don't have one ready yet. I'll whip it up later, but hoping somebody might recognize something obvious from a verbal description. I'm about to go to bed, been up messing with this all night, but when I get up I'll see about making a schematic to post if it's needed.
So, here's the setup. I'm still working on this whole "hot swapping USB power supplies" for a Raspberry Pi thing. I implemented one approach that made the logic switching decision based on a "falling edge detector" I built with a voltage reference and a comparator, to deal with the bad behavior (relative to my needs anyway) of the USB charger where it turns off too slowly and causes excess switching time which causes the Pi to reboot. Anyway, I actually have that working, but since it's operating really close to the margins in order to be fast enough, it's also prone to false positives, etc.
Soo... I decided to implement another approach as a test. This will sound WAY over-complicated when you hear it, but it actually turns out to be very natural for reasons I don't have time to explain right now. And that approach is this: in addition to the USB charger that actually provides power to the Pi, I have a second power supply attached to the same AC input. It's a very basic transformer based supply that emits 12VDC and has none of the wonky "slow shutdown" stuff. If you pull the mains plug out of the wall, the signal goes to 0 nearly instantaneously. This is what I want, so I pipe that signal into my device and use it purely for logic to decide when to toggle the relay ( a small 1P2T relay that switches the power rails that serve the load).
But here's the rub: I can't just turn the relay on and off based on that alone, because in addition to shutting down slowly, the USB charger also starts up slowly. So if I swapped the relay on, on a HIGH signal from the external power supply, the relay would be cutting over to a rail that isn't fully ready yet. That would be bad.
So I take the 12VDC from the external source, and regulate it down to 5VDC. The USB rail is already a nominal 5VDC, so everything is TTL compatible. So I figure "Hey, I'll just AND together the external signal and the USB power signal and the AND gate output won't go HIGH until both of those are HIGH." So I did that, and it works. Yay. I use a 74HC08 quad AND gate, where VCC is coming from the battery power rail (assumed to always be present. It wouldn't be if the battery were ever completely discharged, but that's not a use case that matters to me right now). The output from the 7408 drives the gate of an IRF540 MOSFET which is configured as a low-side switch on the relay coil. The relay coil takes it's power from the USB charger rail (both rails have a common ground). There is a snubber diode across the relay coil terminals to deal with spikes caused when the relay closes.
There are also 3 electrolytic caps that total up to about 22000 microfarads of capacitance, used as a reservoir on the output to buffer the output voltage during the relay switching time. And a diode to prevent current from those caps from flowing backwards through the relay.
Now here's where things get weird. This all works, so long as the board is sitting on the bench with no load connected (except for maybe a multimeter across the output terminals). I can plug and unplug the mains cord and watch/hear the relay switch and measure voltages everywhere and everything looks good. The ouput from the 7408 is right at 4VDC when it's HIGH and basically 0 when LOW, as expected. Nothing gets hot and I can switch it back and forth till the cows come home (so far as I know. I haven't actually waited for any cows to show up). BUT.. if I connect the Raspberry Pi to the output, let it boot, and then start plugging and unplugging the AC cord, at some point the relay stops switching. Both times this happened I immediately noticed that the 7408 was HOT, like crazy hot. Not just "warmer than desired" but rather "is probably going to catch on fire if I don't turn this off."
And I have NO idea why. The load is served by the relay, and there's no electrical connection between any of the switching logic stuff and the Pi. The only (used) output from the 7408 is just activating a MOSFET gate so there's little current draw there. Also, if it matters, I have all the unused inputs to the 7408 tied LOW (the datasheet says you can tie them HIGH or LOW, and doesn't express any preference that I can see). The unused outputs are floating (the datasheet doesn't mention doing anything specific with them so far as I can tell).
Now here's where it gets even weirder. I decided to adhere to an adapted version of Dave's "thou shalt always measure voltages" adage and do "thou shalt measure current draw." So I cut the VCC wire going to the 7408 and inserted my multimeter as an ammeter and ran some more tests with the load connected. And the current draw never even exceeded 1 mA and the chip never got hot and quit working.
So yeah, I'm thoroughly confused now. This works when unloaded, and/or when measuring the current to the 7408 with a multimeter.
But with a load and no multimeter, it tries to catch on fire.
It's almost 9:00am here and I haven't slept yet, so I'm calling it here.
If anybody has any suggestions, please share. I'll check in when I wake up and see where things stand. And if necessary, yes I can hack together a proper schematic.