I was trying to build a 16x9 LED matrix with an MCU with a limited amount of pins. The Anodes of the LEDs are driven by P-channel MOSFETs which gates are driven by a 74HC595 8 bit shift register. the cathodes of the LEDs are sunk by the TLC5940 LED PWM driver IC. The circuit around the MOSFETs looks like this: enter image description here

The Source is connected to 5 V and the Gate is pulled up to 5 V through the 1 kΩ resistor. Drain is connected to the anodes of 16 LEDs in parallel and the gate to the 74HC595. Now my observation on a logic analyzer (as well as on an oscilloscope):

enter image description here

The red channel is just the constant 5 V supply at the source. The brown channel is the switching signal coming from the 74HC595 and the black channel the voltage at the drain. Isn't the MOSFET supposed to shut off immediately after the gate gets pulled high again? The turn off delay is described as about 80 ns which is clearly passed on the output of the logic analyzer. Is this the expected behavior or am I doing something wrong here? Since the TLC5940 can only sink current on the cathodes of the LEDs I could not get around high side switching, but I was under the impression that this circuit should work...


After finally having some time, I recreated a simpler version of the circuit and tested it on a prototyping board with an Arduino to isolate the problem. This is my schematic, the unconnected nets connect to the control pins from the Arduino:

enter image description here

As p-channel MOSFETs I tried both, the FQP27P06 and the IRF9540N which both have similar specs. My readings were in both cases almost the same: enter image description here

We see that the MOSFET is only supposed to conduct for 0.27ms according to the gate reading but it remains for another 0.86 ms which really causes harm to my application when all 9 led rows are connected in the end. It caused trouble, because one column with all 16 LEDs lit was drawing 320mA. With this behavior on all the MOSFETs though and all LEDs activated in my matrix, 3-4 MOSFETs were conducting at the same time which at least tripled the current draw and since my board was not specced for this the voltage was braking down and the MCU ended up halting. Also my package of the TLC5940 was not rated for the amount of heat dissipation and it occasionally went into the temperature error mode. Anyone having an idea why this problem might occur? Every answer is greatly appreciated!

  • 3
    \$\begingroup\$ Please show more of the circuit so we can see exactly how the MOSFETs are connected. \$\endgroup\$ – Bruce Abbott Mar 29 at 5:09
  • 2
    \$\begingroup\$ Don't show a fragment of the circuit then describe the rest. Show the whole circuit. \$\endgroup\$ – Andy aka Mar 29 at 8:51
  • \$\begingroup\$ What happened next? Was there a floating pin? \$\endgroup\$ – Russell McMahon Apr 3 at 0:56

Try adding pull-down resistors to the drain pins of the MOSFETs. The waveforms you are showing are classic capacitive discharge curves caused by high-impedance loads.

Since your FET Source pins are at 5 Vdc, try 1k resistors from the drains to Ground.

| improve this answer | |
  • \$\begingroup\$ Unfortunately 1K probably isn't enough to get the job done - that's a fair amount of capacitance on 16 LEDs. Also it wastes power when the column is 'on'. \$\endgroup\$ – hacktastical Apr 25 at 0:24

You've misunderstood something crucial and it's not about your circuit, it's about your reading of the datasheet. IRF9540 says:

enter image description here

It's clear now that the Fall Time "promised" is in fact 51ns. But you need to pay attention to the conditions:

  • VDD = -50V
  • ID = -11A

This means that the "promised" Fall Time is not going to be 51ns, or at least not with your 5v supply. This is the root of the problem.

If you don't believe me yet then check the following, I made some tests:

enter image description here

This is the response of the circuit with VDD = 5v. The resulting Fall Time is 4ms!

enter image description here

This is the response of the circuit with VDD = 12v. Here the resulting Fall Time is 2.5ms. It's less in fact because we're getting closer to the test values (e.g. VDD=50v).

I would like to test this with VDD = 50v but I don't have the tools right now.


Read the datasheet and be careful next time! They promise some things but you should read between lines.

| improve this answer | |
  • \$\begingroup\$ No way this is the problem. The R-C discharge time OP shows is in the multiples of ms. This is charge being left on the drain, with no place to drain to once the LEDs are no longer actively foward-biased. \$\endgroup\$ – hacktastical Apr 25 at 0:28
  • \$\begingroup\$ Uhm, well, you can try to replicate it too. No simulations please. I had this doubt before and that was mi conclusion. I may be wrong, but you have to show proof. Science <3 \$\endgroup\$ – Marcelo Coronel Apr 25 at 0:44
  • \$\begingroup\$ Hi Marcelo, thanks for the answer and the effort! I thought about it too and made another test, instead of the 16 LEDs in parallel which result in a current flow of 320mA with the current limit set on the TLC, I used a 16 Ohm resistor (6 x100 in parallel for the wattage) as a load, which will have an almost equal current flow. Now the fall time was at just less than a microsecond, not what the datasheet says, but much much better than before and something that I could definitely work with. So to me it seems that the capacitance of my specific load is the problem and a pull down actually helped \$\endgroup\$ – tlubes Apr 25 at 5:32
  • \$\begingroup\$ Yes, I tested it yesterday, the pull down resistor reduces the turn off time from miliseconds to the range of microseconds. Not ideal because of the little waste of power but it works. Still not the promised nanoseconds though. \$\endgroup\$ – Marcelo Coronel Apr 26 at 17:46

I believe that there is nothing wrong with the design. Something is wrong with the physical circuit. Three main candidates come to mind:

  1. The MOSFET is bad
  2. The TLC5940 and LED sub-circuit has some failure leading to unwanted coupling to the drain terminal.
  3. Some other unintended coupling to the drain terminal in the circuit

You tried multiple MOSFETS and got the same result, so that seems unlikely. But you can do some tests to nail it down and point toward the real culprit:

  1. Replace the MOSFET with a physical switch and see if you get the same result. Obviously that would completely exonerate the MOSFET and show that something else is wrong.
  2. If you have the same strange behavior with the switch, replace the TLC5940, or perhaps disconnect all but one LED from it to cut off most of the possible faulty connections to the drain terminal. Perhaps the TLC5940 and an LED has some fault that is providing this coupling.

You know if you work towards having a switch connected to a single LED/resistor combination, it has to work somewhere on that path. So the idea is to work your way toward that and identify what is failing. Maybe your circuit board has a flaw and is giving you some sort of coupling to the drain terminal, in which case even the switch powering an LED/resistor combination might show that behavior!

| improve this answer | |
  • 1
    \$\begingroup\$ +1 A good start for a new contributor ! :-). Welcome. \$\endgroup\$ – Russell McMahon Apr 25 at 2:56
  • \$\begingroup\$ Thanks for the suggestions. A test I did was swapping the LEDs with a resistor resulting in an equal current draw and it turned out that the fall time was much much better and very close to the on expected in the datasheet. So I came to the conclusion that the LEDs used are the high impedance component and a pull down resistor on the drain of the MOSFET helped me! \$\endgroup\$ – tlubes Apr 25 at 18:42

Wow. Lots of red herring answers to this question. This is a simple problem with a simple answer.

The MOSFET isn't turning off too slowly.

Those waveforms are measuring the voltage relative to ground, specifically the voltage at the MOSFET's drain.

LEDs are still diodes. They have intrinsic capacitance and a non-linear voltage drop. And MOSFETs do, in fact, have capacitances. One of interested here is the output capacitance, which is effectively a capacitor across the drain and source. It must discharge through these diodes, and that discharge will become exponentially slower (exactly like we see in the plots of the voltage). So of course the voltage at the drain decays slowly. You're just looking at the expected voltage decay curve for the output capacitance of the MOSFET being forced to discharge through the sub threshold leakage of the diodes. The capacitance is in hundreds of picofarads, but this discharge current is on the order of nano amps. Whenever the drive voltage is close to the voltage drop of the diodes, this becomes a lot more noticeable, where at higher voltages, it is less so as the decay doesn't slow down until a bit below the voltage drop of the diodes. But it is still there, just less visible on a graph. I would point out that with a drive voltage of 5V, and lest we forget that there is at least an additional 0.6-1.2V drop due to the low side driver chip (which is not using MOSFETs internally, but bipolar transistors) on top of the possibly 3V-3.4V drop for the LEDs... that's not much headroom. Such a decay would be that much more noticeable.

And I can prove it. If you place a load resistor in parallel with the diodes to ground, maybe 10K, you should see the voltage decay much more rapidly as now it has a linear resistive path to discharge through and not the exponential behavior of PN junctions.

My point is that the MOSFET is turning off. The voltage decay is both normal, expected, and unrelated to the other problems he's having. It is easily as well. Measure the current. Measure the current in series with the drain or source of the MOSFET. Measuring the voltage at the drain is not a correct way to determine turnoff in this circuit. Measuring current is the correct way to determine if the MOSFET is turning off or not. And I am sure it is turning off as fast as one would expect.

And, of course, if the MOSFET was truly turning off as slowly as the voltage is decaying at the measured node, then why can we see these:

enter image description here

Voltage regulators don't spike their output voltage like that if the load is decaying like the voltage measured. The only way we'd see a sudden spike on the power supply voltage like that is if the regulator experienced a sudden load step from heavy current draw to almost no current draw. It can't react instantaneously, so there is a brief period where the voltage goes out of regulation, specifically by being higher than it is supposed to be, before it can get the output back into regulation. This requires a large, fast load step.

A load step that could not occur if the MOSFET was not turning off as it should. One that certainly could not occur if it was turning off as slowly as the incorrect method being used to determine that (voltage) would have us believe.

There is such a load step in the voltage rail, which means the MOSFET is, indeed, turning off and slightly faster than that voltage spike on the power rails occurs.

Measure the current. You'll see that the current falls as quickly as you'd expect.

| improve this answer | |
  • \$\begingroup\$ Looks good. ie what Dwayne said in 3 lines. \$\endgroup\$ – Russell McMahon Apr 25 at 16:34
  • \$\begingroup\$ Thanks for the detailed explanation! \$\endgroup\$ – tlubes Apr 25 at 18:48
  • \$\begingroup\$ Nice insight about the spike in the output voltage as the MOSFET turns off. I agree that the MOSFET is turning off....but wouldn't you expect that immediately after turning off the MOSFET, while there is still a full 5V at the LED anode, the LED would still be in forward conduction and you would observe a very short period of extremely rapid decay until the LED voltage falls below threshold? \$\endgroup\$ – rpm2718 Apr 26 at 13:42

Links to datasheets ALWAYS a good idea.

Cin gate around 1400 pF depending on your conditions.
Rpullup 1 kΩ

Time constant on gate is T = RC = 1000 x 1400 E-12
= 1.4 µS

You are seeing a much longer gate turnoff time that that. Are you sure the 1 kΩ is not a 100 kΩ or so?

Failing that, it makes no great sense.
Look for something nonsensical :-)


... as you can see in the brown channel of the logic analyzer, the gate voltage behaves as expected. Its the Drain voltage that gives me this weird behavior. I also verified the resistance and tested with a range of other resistors (1k, 10k, 100k...)...same behavior.

Is there an unused select or address line on the HC595 floating when it should be strapped high or low? That would explain behaviour like this - or also random behaviour in other cases.

Here the floating line can follow some source (select line or ...) via leakage (in IC or external) with a long time constant due to pin capacitance and v high leakage resistance or bias current.

This is a very common class of behaviour with a floating pin.

| improve this answer | |
  • \$\begingroup\$ Thanks for the answer, but as you can see in the brown channel of the logic analyzer, the gate voltage behaves as expected. Its the Drain voltage that gives me this weird behavior. I also verified the resistance and tested with a range of other resistors (1k, 10k, 100k...)...same behavior. I will add a more detailed schematic with a better context of my project! \$\endgroup\$ – tlubes Mar 29 at 17:50
  • 1
    \$\begingroup\$ @tlubes Is there an unused select or address line on the HC595 floating when it should be strapped high or low? That would explain behaviour like this - or also random behaviour in other cases. Here the line follows some source (select line or ...) via leakage (in IC or external) with a long time constant due to pin capacitance and v high leakage resistance or bias current. \$\endgroup\$ – Russell McMahon Mar 30 at 1:12
  • \$\begingroup\$ No, no floating pins. All the pins of 74hc595 were tied to a level. I will debug further soon, this is just one of my side projects. I also noticed, that at less frequency the behavior was not as bad, but still way out of proportion when looking at the datasheet. \$\endgroup\$ – tlubes Apr 4 at 5:17
  • \$\begingroup\$ @RusselMcMahon I really appreciate your engagement to help! I edited my question to where its more clear what is going on. I used all new components and rebuilt everything twice, so I think I isolated all random problems at the best I could! \$\endgroup\$ – tlubes Apr 21 at 18:48
  • 1
    \$\begingroup\$ @tlubes Dwayne's answer may well identify the problem. ie a floating pin BUT the load is the pin that floats ! :-). Hopefully his solution works. It seems consistent with what you describe so far. \$\endgroup\$ – Russell McMahon Apr 22 at 1:11

A couple of thoughts.

  • try to use a lower rail for the LED, like 3.8V or so (just above your max Vf if possible.)
  • Use a N-FET or NPN transistor on each column to pull the anodes down when column is 'off'.

Using a lower LED voltage on its own rail will reduce power dissipation in the TLC current-source driver. And because, by nature, the LED transient currents are high, it doesn't hurt to isolate them on their own supply. And... less charge to bleed off when it comes time to blank the row.

Now, on to the problem you're seeing.

tl; dr: your LEDs are ghosting. You could get an exorcist, or... you need to pull down the anodes during the dead time.

Here is a relevant link on this very topic: Vertical ghosting on 64x32 1/16 RGB LED matrix panel

Why is this happening?

When the columm high-side FET is off, the LED current goes to almost zero. That's fine, but there is still leftover charge on the LED anodes, the traces, and the P-FET drain. Yes, those LEDs become capacitors.

What happens when the FET turns off is then:

  • LEDs conduct until they reach their forward voltage, Vf
  • LED current quickly decays to sub-Vf leakage, which is in the nA range

So any remaining charge bleeds off s-l-o-w-l-y through the sub-Vf biased LEDs, having nowhere else to go. This means that those LEDs are still very close to being 'on', even if just a little bit, during this sub-Vf threshold decay time.

And guess what? If the cathode voltage gets jacked up by activating another column, this couples to the 'off' column through their LED sub-Vf capacitance. And in the process, pushes the off-column anode voltage back above Vf, lighting the LEDs in the 'off' column.

That's ghosting, in a (nut) shell.

How to fix it?

Add an N-FET to each columm to bring the anode voltage low, forcefully, when that columm is off. The N-side pulldown will discharge that leftover voltage much faster than a pulldown resistor can do it. Not only does this fix ghosting, but it allows you to shorten blanking time considerably.

The N-FET can be a very cheap one like a 2N7002, less than 2 cents in volume. An NPN transistor can work too (about 1 cent for 2N3904), or even an open-drain inverting buffer.

| improve this answer | |
  • \$\begingroup\$ Thanks for the suggestions and the detailed explanations! I will lower the LED rail eventually. This is just a crude hobby project for me to learn so for no a pull down on the drain does the trick. But of course I want to improve and I ordered a MOSFET driver IC with the N channel and P channel FETs included. That should lead to an even better result. \$\endgroup\$ – tlubes Apr 25 at 18:54

I notice that each mosfet's gate low time is 0.27ms. Well, 0.27ms x 9 = 2.45ms but your cycle time is 4.5ms. Are you doing 2ms of processing inbetween each cycle around the strings when the display isn't being driven?

A usual way of driving an LED display is under interrupt control. Have a timer driven interrupt and each time the interrupt sub routine is executed the currently lit string is switched off and the next one switched on. Then there is no dead time during other processing.

You could make the display interrupt driven and if the problem is caused by the FET's switchoff time you could drive the display at a lower frequency (you shouldn't see any flicker at 80Hz). Then you can add 0.8ms "all gates high" dead time inbetween a string being switched off and the next one being switched on.

| improve this answer | |
  • \$\begingroup\$ Thanks for the answer. Actually my matrix is interrupt driven with TIMER0 of the atmega168p. The reason why there is some off time in the cycle is that I actually source the LED data from an SPI flash and setup the TLC5940 after I turned off the anodes of the LEDs. After everything is done and the latching of the TLC went through I enable the next row of anodes. Also my MCU only runs at 8MHz currently. There is still plenty of improvement to be done on the software side... \$\endgroup\$ – tlubes Apr 25 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.