Ah, the 7805 voltage regulator. Easy to use and indestructable - right?
But there are some gotchas. And in one project I managed to run into not just one, but two of them!
The thing which I designed is in itself at easy as it can get. The main power is 24V and the 7805 supplies 5V to to logic side (an AVR microcontroller). Before you start shouting "INEFFICIENT!!" let me tell you that only a couple of those are going to be built, also it only has to power this one chip. Should this design enter serial production I'm going to put a switching regulator on it, I promise.
(Update August 2017: No serial production yet, but we needed more boards. The input voltage is now 30V and, yes, the new design now contains a switching regulator. Bit more pricey but runs much cooler).
So power comes in from the power brick (an industrial power supply), into the 7805. I added 1µF+100nF of decoupling on the 5V side and that's it. I figured I wouldn't need big caps on the 24V side since the power bricks with its beefy output caps is just a few centimeters away. So, we soldered the board, I hooked up my benchtop power supply and the microcontroller burnt out immediately. No visible blue smoke but circuitry enganged which shouldn't do anything with an unflashed microcontroller.
I measured the output of the 7805 - and got around 5.8 to 6V. Too much for the poor AVR :(. I tested a couple of other 7805s from different manufacturers and they all experience the same behaviour: When the input voltage goes above 22V the output goes out of regulation - which is weird because all datasheets say that the chips should be able to take up to 35V. And, no, it's not resonance, I tried it with an output capacitor as well. An easy way to get the 7805 back to the correct voltage is to apply some load to it, which gets us to the first lesson:
Lesson 1) A 7805 needs it's output to be loaded when the input voltage is very high.
For example a power indicator LED is an elegant way of doing it. In my case I just soldered a 1K resistor next to one of the decoupling caps. Couldn't find anything in the datasheet about this behaviour though.
So the board was working nicely, I hooked it up to my AVR programmer, flashed some test firmware onto it, everything looked hunky dory until the power cable fell off my benchtop power supply. It didn't touch anything, it just disconnected the power. So I plugged it back in and BANG - got a nice amount of blue smoke from the microcontroller. What happened? The regulator gave way and let the full 24V through. It took me a while to figure this one out but the datasheet mentions it clearly. The output of the regulator must never be higher than the input. How can this happen? I had some capacitors on the 5V line but almost no capacitance on the input - because clearly the big caps in the final design would be enough. But during development I didn't use this power brick but my benchtop supply. When the cable fell off the input of the regulator went from 24V to 0V almost immediately. The output stayed at 5V a while longer thanks to the decoupling caps. So it was the "power off" action, not the "power on" which destroyed the regulator. Luckily there is an easy fix:
Lesson 2) Put a diode between input and output of the regulator to prevent backfeed. (with the ring pointing towards the input, of course)
And sure enough, two burnt out microcontrollers, one destroyed 7805 and circuit board later I've learned my lessons. I'm going to put this diode in all my future designs which use a 7805, you know, just in case ....
PS: I also bodged in a 100µF input capacitor on this board, again, just in case.