# Why is there so much overshoot in my LED circuit and how do I prevent it?

I'm trying to PWM a 5 meter RGB LED strip with a microcontroller. With this setup:

simulate this circuit – Schematic created using CircuitLab

I have built it on a breadboard and probed the drain with my (new) scope and saw this huge overshoot:

Why doesn't the diode catch that spike? I though an 1N4148 would be fast enough. The power supply is a 12V 6A switching power supply from eBay. Is that why the voltage drop as low as about 8V?

Here is the gate voltage:

The high frequency spikes are from the 12V rail it seems, here how the 12V supply rail looks like:

I realize that breadboards are crap for signal integrity especially since I have used crappy long jumper wires but I had never guessed it would be this bad.

So why doesn't the diode catch those spikes ? And how can I reduce them? Also, is this power supply a total crap?

EDIT:

I have placed a couple of caps to decouple the power supply, there is still an overshoot:

I've added a 100nF ceramic cap across D4 and the overshoot is totally gone:

It looks good now, but notice the 2nd channel (in yellow). That's the power supply (which is a lot cleaner with the decoupling caps). Now another question comes in mind:

Why is the Drain voltage only about 6v when the leds are off ?

-
the 1n4148 is not fast enough, the question remains beacuse the leds are not inductive enough to produce such a spike. I'd point my finger to a crappy power supply, but that's just a guess. –  Vladimir Cravero Aug 8 '14 at 17:35
The led strip is 5 meters long, so that's like a 10 meter trace. This must have significant inductance, right ? –  Mike Aug 8 '14 at 17:53
@Mike The inductance is a function of the area encircled, not the length of the circuit. –  Phil Frost Aug 8 '14 at 18:02
The fact that you can see those PWM spikes on your ground and all your signals tells you that you have a major scope connection issue. –  WhatRoughBeast Aug 8 '14 at 18:19
It might be better to ask a new question rather than append a new one here. –  Phil Frost Aug 10 '14 at 11:27

You have no capacitors across the power supply. That's going to cause problems, even with a good power supply.

Furthermore, "crappy long jumper wires" and "breadboard" throw stray inductance everywhere. You will see voltage overshoot whenever current abruptly changes according to $v = L\:\mathrm di/\mathrm dt$, where $L$ is some value determined by the crappiness of your long jumper wires, and the loops formed by your breadboard connections.

You also haven't given details of your measurement setup. If the ground lead of the scope is not very near the probe tip, this introduces even more inductance into your measurement device, and you will measure more overshoot than there is. At fast MOSFET switching timescales, even the inductance of the alligator-style clip typically provided with the probe can be significant.

I would hazard a guess that this problem isn't a problem, if you add some capacitors across the power supply, and build the circuit with a reasonable layout mindful of stray inductance.

-
can stray inductance produce such a high (2Vcc) spike? I mean, that's what we see so it's happening, but aren't there any other reasonable culripts? –  Vladimir Cravero Aug 8 '14 at 17:47
This is exactly what I'm asking. I just threw this circuit together really quickly, and slacked off with the wire length and caps. Could there be any other reason for those spikes ? –  Mike Aug 8 '14 at 17:50
It looks like he's trying for a shut-off time around 1 ns. If he starts with 100 mA, it only needs 20 nH of stray inductance to generate a 2 V spike. Pretty easy to get 20 nH in a breadboard ratsnest. –  The Photon Aug 8 '14 at 17:50
Also if you introduce inductance in your scope probe (usually by connecting the ground far away from the thing being measured), then you will measure more overshoot than there actually is. –  Phil Frost Aug 8 '14 at 17:51
I just looked again and the turn-off time might be more like 50 than 1 ns. Even so a really bad breadboard could have enough excess inductance to cause this scale of problem. –  The Photon Aug 8 '14 at 17:53

Maybe this is just a measurement problem. Are you using a nice x10 scope probe? It could all just be ringing in your lines. (I don't think you need D4, it would be needed with an inductive load, but not here.)

-
Yep, the probe is a 10x probe. I managed to "fry" two mosfets when I didn't use D4. –  Mike Aug 8 '14 at 18:55
@Mike I'd guess that the problem isn't what you think it is, and D4 is masking the real problem that is frying your MOSFETs. –  Phil Frost Aug 8 '14 at 19:03
Hi @Mike, Hmm that's wierd. How does a little 1n4148 save a big FET? So maybe there is some inductance in the 5m string... could you add some C in parallel to it? (C across the diode string.) –  George Herold Aug 8 '14 at 19:12
I just did, see my edited question. –  Mike Aug 8 '14 at 19:15
Excellent, Mischief managed then. –  George Herold Aug 8 '14 at 19:19