Mysterious apparent excess current drain (and overheating) with 74HC08 AND gate - Page 1
Forum section: electronics / beginners

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 12:49:43 pm
content: EEVblog'ers, I'm at my wits end hereand 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.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 07, 2022, 12:53:34 pm
content: Sounds like a classic case of latch-up.It's seeing voltage on an input pin before it's powered up, or getting an overvoltage spike

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 07, 2022, 12:55:03 pm
content: Quote from: mindcrime on July 07, 2022, 12:49:43 pmOne way to prevent (or at lease lessen the effect of) latchup is to increase the supply source impedance, which is what you're doing by adding the meter

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 12:59:44 pm
content: Quote from: mikeselectricstuff on July 07, 2022, 12:53:34 pmAah, interesting. I've heard the term "latchup" but I admittedly don't understand the details. I'll do some googling and read up on that when I get up later. Thanks for the pointer!EDIT:OK, I'm a glutton for punishment and don't need sleep anyway. I was just reading the Wikipedia page on latch-up and some other stuff. It seems that latch-up can happen in CMOS or TTL devices, but I guess it's more of an issue in CMOS? I wonder if I'm be better off switching from the 74HC08 to a non CMOS version? Thoughts?Any other good tips for helping to avoid this? Besides the aforementioned "increase input source impedance".

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 07, 2022, 01:08:28 pm
content: Quote from: mindcrime on July 07, 2022, 12:59:44 pmBest approach is to identify and prevent the root cause - could be as simple as a series resistor on an affected input, or a clamping diode.

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 01:13:38 pm
content: Quote from: mikeselectricstuff on July 07, 2022, 01:08:28 pmGotcha. Any rule of thumb for how to determine the resistor value for that? IIUC, since these are CMOS chips internally, but just dressed up as TTL compatible, they don't need much of a signal on the inputs to activate, so a fairly high value resistor?

author: Zero999
author_rank: Super Contributor
timestamp: July 07, 2022, 01:30:33 pm
content: Quote from: mindcrime on July 07, 2022, 01:13:38 pmNever exceed the maximum current rating of the input pin diode, even for a short length of time.I Googled and found this data sheet for the 74HC series, which says ±20 mA.https://www.renesas.com/us/en/document/dst/hd74hc-series-common-information

author: Andy Watson
author_rank: Super Contributor
timestamp: July 07, 2022, 02:01:43 pm
content: You've used an AND gate ? What have you done with the other three gates in the package? Specifically are the inputs floating?Also, with less than 5V available, the IRF540 is probably operating in its linear region - A "logic" level mosfet would be a better choice.

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 02:11:02 pm
content: Quote from: Andy Watson on July 07, 2022, 02:01:43 pm"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). "Quote from: Andy Watson on July 07, 2022, 02:01:43 pmNo doubt, but A. I didn't have any here to use, and B. given that the relay coil only uses about 100 mA, I doubt that is much of an issue. That said, when I eventually rebuild a new version of this board, I'll switch to a proper logic-level MOSFET.

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 02:20:37 pm
content: And just a side-note for anybody who is wondering about my mention of TTL above, in a discussion about a 74HC08 issue... I was originally using a 74HCT08, which is the "implemented in CMOS but uses TTL compatible inputs and outputs" version, and I was still thinking about that. But I began to suspect that chip was damaged and so I reached to the parts box for another and all I had were the HC ones. I jammed it in there without fully considering the impact that would have.Aaah well. What can ya do? I have a box coming from Jameco with a bunch of the 74HCT08's, so I can switch it out later tonight (or today, or tomorrow, or whatever it will be when I finally get around to going to sleep and then waking up. At this point, I'm debating just staying up straight through till tonight).

author: mindcrime
author_rank: Unknown
timestamp: July 07, 2022, 03:18:41 pm
content: And this is why I love this forum.I added a series resistor to the one input that didn't already have one (why I put a resistor on one and not the other in the first place is one of life's great mysteries), and added a resistor on the vcc line. Preliminary testing suggests that that fixed the problem. I was able to toggle between power supplies repeatedly over the span of several minutes, and had no issues with the 7408. Everything worked seamlessly.EDIT:Also, because I know somebody is going to read this and ask "Why the hell would you use a relay instead of semiconductors???"*sigh*I started out trying to build this using all semiconductors, MOSFETS mainly. I failed miserably at doing so, for multiple different reasons, but all of them ultimately reduce down to my own lack of knowledge. In particular, since the two rails are bonded at the output to the load, and voltage can "leak" from one rail to the other, I had a ton of trouble working out how to decide when to switch the MOSFET's for their respective rail to be ON or OFF as required. I also had issues caused by the voltage drop across diodes and what-not, before I realized that one of those cheap little boost converter boards can actually run a Raspberry Pi, and can be used to tweak voltages that are just a hair too low.I tried a ton of stuff, wasted a dozen of those little solderable breadboard boards, burned through a couple of bags of MOSFETS, capacitors, etc. and never quite got it to work.And then I realized that a relay makes life much easier since there's no electrical connection between the two rails. One or the other is connected to the load, but never both. So there's no worrying about how FET's conduct when reverse biased and the gate to source voltage is below blah, blah, etc. yadda.And yet.. relays suck. They're big, power hungry (in relative terms), produce more heat, make more noise, and have a limited lifespan. So the goal is to eventually go back and re-implement this as a pure semiconductor based approach. The good news is, working on this project has forced me to learn a TON of new stuff, and deepen my understanding of things that I kinda / sorta halfway'ish understood. (Note: there's still a lot of stuff that I only kinda/sorta halfway'ish understand, but a little bit less than 3 months ago). Anyway, I feel confident that I now know enough to deal with the issues that were plaguing me before. It's just a question of time to experiment, and $$$ for components to experiment with.Keeping in mind what Dave always says about how if you build something you should hope it doesn't work, because you didn't learn anything if it works the first time, I've had a great - if somewhat frustrating, and moderately expensive - learning experience over the past few months.

author: Bud
author_rank: Super Contributor
timestamp: July 07, 2022, 04:11:39 pm
content: Good man, we need more people like you

author: ebastler
author_rank: Super Contributor
timestamp: July 07, 2022, 04:22:18 pm
content: Quote from: mindcrime on July 07, 2022, 03:18:41 pm"If it works right away, the problem lies deeper", a friend of mine likes to quote a former professor of his.

author: mindcrime
author_rank: Unknown
timestamp: July 08, 2022, 05:42:39 am
content: I've done some extensive "burn in" testing with this thing tonight, and so far everything looks good. Over the course of several hours I've had the Pi up and running, and I have occasionally walked in that room and plugged / unplugged the mains cord to the USB charger. So far no more latchup or other weirdness. The Pi has stayed up and running throughout all the hotswap events, and nothing is on fire, or appears to be in danger of catching on fire. I'm about ready to declare this a success at this point.Of course I couldn't have done it without help from all y'all.Here are some pictures of the board, for people who like that sort of thing. No, it's not a custom PCB or anything (yet). Just one of those solderable breadboard deals. But they turn out to be pretty handy for prototyping stuff like this.