MOSFET not turning completely off

Thread Starter

Nutshell

Joined Mar 5, 2017
17
Hello everyone,
I'm trying to design a simple controller for 2 RGB led strips using an STM32, which controls the gates of 6x IRL540, as shown in the simplified schematic (I've drawn only one FET, as they're all connected the same way). The PWM signal is controlled by potentiometers.
fet wiring.PNG
I tried different values for R1 and R2; currently, I'm using 470 for R1 and 10K for R2.
The circuit surprisingly works fine, but when I try to set the PWM signal to 0 the leds still softly flicker, as if the FET wasn't completely off.
Here's a list of things I tried to fix the problem:
- adding an if() to set the PWM to 0 if the analog input is under a certain threshold (so I get rid of small errors if analog input pin picks up values that are slightly higher than 0): this way I improved things a little;
- setting a different timer overflow value (=> changing the PWM frequency): no significant difference;
- varying R1 and R2 in these ranges: 220-1k for R1 and 5k-50k for R2. Lower values slightly reduced the problem, but it is still persistent;
- adding a TC4420 between a FET and the pin, with proper wiring: no significant difference (this was really surprising, I thought this would fix it).
Today I'm gonna try using IRL3803's instead of IRL540's to see if the problem's the Vgs.

Here's the code i'm using:

Code:
HardwareTimer t1(1);
HardwareTimer t4(4);
int r1;
int g1;
int b1;
void setup() {
t1.setPrescaleFactor(1);
t4.setPrescaleFactor(1);
t1.setOverflow(4095);
t4.setOverflow(4095); // this way I set the PWM resolution to 12 bit; frequency is 72MHz/4095 = around 17 kHz
pinMode(PA8, PWM);
pinMode(PB6, PWM);
pinMode(PB7, PWM);
pinMode(PB1, INPUT_ANALOG);
pinMode(PB0, INPUT_ANALOG);
pinMode(PA7, INPUT_ANALOG);

}

void loop() {
r1 = analogRead(PB1);
g1 = analogRead(PB0);
b1 = analogRead(PA7);

pwmWrite(PA8, r1);
pwmWrite(PB6, g1);
pwmWrite(PB7, b1);
}
Do you have any suggestions on how to turn those FETs completely off?
Thank you in advance!
 

Dodgydave

Joined Jun 22, 2012
9,923
Irl540 has a 1V minimum gate turn on, so i would use Irf540 or put Bat41 diodes in series with the gates R1, to increase the gate voltage, your output from the micro isn't going to zero volts long enough .

You could use a Totem pole output with a Npn and Pnp to drive the fets.

Note your Irl3803 has 1V gate voltage also.


2005FEB14_AMD_NT03.jpg
 
Last edited:

ebeowulf17

Joined Aug 12, 2014
3,275
Hello everyone,
I'm trying to design a simple controller for 2 RGB led strips using an STM32, which controls the gates of 6x IRL540, as shown in the simplified schematic (I've drawn only one FET, as they're all connected the same way). The PWM signal is controlled by potentiometers.
View attachment 148971
I tried different values for R1 and R2; currently, I'm using 470 for R1 and 10K for R2.
The circuit surprisingly works fine, but when I try to set the PWM signal to 0 the leds still softly flicker, as if the FET wasn't completely off.
Here's a list of things I tried to fix the problem:
- adding an if() to set the PWM to 0 if the analog input is under a certain threshold (so I get rid of small errors if analog input pin picks up values that are slightly higher than 0): this way I improved things a little;
- setting a different timer overflow value (=> changing the PWM frequency): no significant difference;
- varying R1 and R2 in these ranges: 220-1k for R1 and 5k-50k for R2. Lower values slightly reduced the problem, but it is still persistent;
- adding a TC4420 between a FET and the pin, with proper wiring: no significant difference (this was really surprising, I thought this would fix it).
Today I'm gonna try using IRL3803's instead of IRL540's to see if the problem's the Vgs.

Here's the code i'm using:

Code:
HardwareTimer t1(1);
HardwareTimer t4(4);
int r1;
int g1;
int b1;
void setup() {
t1.setPrescaleFactor(1);
t4.setPrescaleFactor(1);
t1.setOverflow(4095);
t4.setOverflow(4095); // this way I set the PWM resolution to 12 bit; frequency is 72MHz/4095 = around 17 kHz
pinMode(PA8, PWM);
pinMode(PB6, PWM);
pinMode(PB7, PWM);
pinMode(PB1, INPUT_ANALOG);
pinMode(PB0, INPUT_ANALOG);
pinMode(PA7, INPUT_ANALOG);

}

void loop() {
r1 = analogRead(PB1);
g1 = analogRead(PB0);
b1 = analogRead(PA7);

pwmWrite(PA8, r1);
pwmWrite(PB6, g1);
pwmWrite(PB7, b1);
}
Do you have any suggestions on how to turn those FETs completely off?
Thank you in advance!
17kHz seems unnecessarily high. Slower PWM frequency should mean looser requirements in terms of switching speed, gate drive, totem poles, etc.

I have to admit though, I'd still expect off to be off regardless. I'm not sure what explains your dim flicker. Have you tried scoping the PWM pin outputs, or even just tried a regular meter on them? Is it possible logic low output is simply too high of voltage, not close enough to ground for the FET you're working with?
 

Thread Starter

Nutshell

Joined Mar 5, 2017
17
Irl540 has a 1V minimum gate turn on, so i would use Irf540 or put Bat41 diodes in series with the gates R1, to increase the gate voltage, your output from the micro isn't going to zero volts long enough .

You could use a Totem pole output with a Npn and Pnp to drive the fets.

Note your Irl3803 has 1V gate voltage also.


View attachment 148979

Thank you for the fast reply! I don't have any bat41 now, so I'll go for the totem pole. I'll post whether it works or not tomorrow.
Just a couple of questions:
- even though the output pin's current is quite low, can I connect the PWM pin to Q1 and Q2 with no resistor in between?
- is there any recommended value for the resistor between PWM and ground, or for Rgate?
- the bat41 would solve the problem thanks to the voltage drop across it, right?
 

Dodgydave

Joined Jun 22, 2012
9,923
The toem pole will ground the fet faster and discharge it's internal capacitor faster, you're better to use a Gate resistor to ground to ensure the fet turns off, i usually use a gate resistor of 4K7 to 10K, and a gate/source resistor of 1K.

The Bat41 is a Shottkey diode of 450mV, try an ordinary 1N4001 type.
 

Thread Starter

Nutshell

Joined Mar 5, 2017
17
17kHz seems unnecessarily high. Slower PWM frequency should mean looser requirements in terms of switching speed, gate drive, totem poles, etc.

I have to admit though, I'd still expect off to be off regardless. I'm not sure what explains your dim flicker. Have you tried scoping the PWM pin outputs, or even just tried a regular meter on them? Is it possible logic low output is simply too high of voltage, not close enough to ground for the FET you're working with?
Thanks for your reply! I tried using PWM frequencies all the way down to 1 kHz (and up to 282 kHz just for fun, on a separate board) with no significant improvements. As you mentioned, I guess the problem is the low output being too high for the FET. I'll try doing what Dodgydave suggested and I'll let you guys know if it worked.
 

be80be

Joined Jul 5, 2008
2,051
Your using arduino ide I have had to right the pin low to get the leds off using pwm.

Code:
digitalWrite(YOURPIN, LOW);
 
Last edited:

ebp

Joined Feb 8, 2018
2,332
Actually, after writing all of the following I think the answer is probably very simple - there is crud on the analog signal you are reading.
~~~~~~~~~~~~~~~

Something very strange is afoot if the gate driver IC failed to fix the problem. At the very least, the driver should have changed something.

More info is required:
The code suggests each strip has 3 FETs for each of 3 colors and that both FETs for a particular color are driven from the same pin - yes, no?
What is the nature of the connections between the FETs and the processor? short and direct? cable? long uncabled wires?
Where was the driver IC located when it was tried? near the processor or near the FETs?
Did the driver have local power supply decoupling?
If you connect whatever is going to the FET gate to ground at the processor board does it keep the LEDs from flickering?
If not, happens if you remove everything from the FET gate but the resistor between gate and source?
Where is the resistor between gate and source located physically (at FET or distant)?
Does the flickering appear like it might be "crosstalk" from color to color? Does it stop if all drivers are set to zero?
What kind of power supply for the LEDs?

When you set the PWM output to zero, what voltage do you measure from pin to processor board ground? FET gate to source?
 

Thread Starter

Nutshell

Joined Mar 5, 2017
17
Ok so I found out that pushing the frequency to the maximum (around 280kHz) apparently solves the problem, even though it leads to 2 minor issues:
- PWM resolution is now 8-bit (256 steps) which isn't the best one;
- only like a quarter of the potentiometer changes the led brightness significantly.
So this leaves me with a possible solution, but I still want to try to solve the problem for lower frequencies, I might learn something new.

Your using arduino ide I have had to right the pin low to get the leds off using pwm.

Code:
digitalWrite(YOURPIN, LOW);
Thank you for your reply, but I don't think that's the problem here. pwmWrite(MYPIN, 0) function is pretty much the same as digitalWrite(MYPIN, LOW), just with a different resolution.

More info is required:
The code suggests each strip has 3 FETs for each of 3 colors and that both FETs for a particular color are driven from the same pin - yes, no?
What is the nature of the connections between the FETs and the processor? short and direct? cable? long uncabled wires?
Where was the driver IC located when it was tried? near the processor or near the FETs?
Did the driver have local power supply decoupling?
If you connect whatever is going to the FET gate to ground at the processor board does it keep the LEDs from flickering?
If not, happens if you remove everything from the FET gate but the resistor between gate and source?
Where is the resistor between gate and source located physically (at FET or distant)?
Does the flickering appear like it might be "crosstalk" from color to color? Does it stop if all drivers are set to zero?
What kind of power supply for the LEDs?

When you set the PWM output to zero, what voltage do you measure from pin to processor board ground? FET gate to source?
Hello and thanks for your reply!
- I actually forgot to mention that as of now the code only supports one strip, as I just wanted to see if it worked properly. When the problem will be solved, I'll add 3 more PWM pins (so the answer is no, those 3 pins will only control 1 FET each);
- FETs and other components are connected to the STM32 via jumpers on a breadboard;
- The IC was way closer to the FET it was driving; can you explain me the reason behind this question? You got me curious.
- No decoupling, it was directly connected to the supply;
- I'm not sure I fully understood your question; if you're asking me if the gate-ground resistor is connected to the STM32 ground pin, then yes;
- So you basically mean only removing R1, or also the PWM pin connection?
- the resistor is located at a distance < 1cm from the FET;
- That's the problem, it doesn't stop if i set to 0 every single pin. It also persists with a single FET wired, so no color crosstalk i guess (or, at least, it's not just that);
- power's supplied by an LTC3780; I also tried using 3-4 different 12V wall adapters, no difference.

I measure 115mV between PWM pin and ground; around 109mV between gate and source.

Actually, after writing all of the following I think the answer is probably very simple - there is crud on the analog signal you are reading.
So I should add filter capacitors, right?
 

ebeowulf17

Joined Aug 12, 2014
3,275
Ok so I found out that pushing the frequency to the maximum (around 280kHz) apparently solves the problem, even though it leads to 2 minor issues...
I could be wrong, but I have a sneaking suspicion that when you set PWM to zero, you're still not getting 100% off. Depending on how the PWM code is written, you might still be getting tiny blips of on time at each cycle before it turns back off again, and depending on the subtleties of the code (timer interrupts vs scheduled items checking time in a loop, beat frequencies between PWM frequency and clock frequency, etc...) it could behave differently based on changing frequency.

If I were in your shoes, I'd put an oscilloscope on the PWM pin output to see if it's going high sometimes as I suspect.

An even simpler test would be doing as @be80be suggested, writing a digital off instead of PWM zero when you want them totally off.

I could be way off on this, but it's such a simple thing to check; it's much easier to write a digital off than it is to rewire a bunch of stuff!
 

Sensacell

Joined Jun 19, 2012
2,761
Divide and conquer.

There are two reasons why this might be happening:

1) The FET is really not turning all the way off.

2) Your PWM is still feeding pulses, when you think it should not be.

Focus on dividing the problem in two, then focus on fixing the thing that is broken.
 

Thread Starter

Nutshell

Joined Mar 5, 2017
17
I'm back after some testing, here are some results:
- adding filter caps: no substantial difference (tested at 1kHz and 17kHz);
- setting pin as LOW (code below): LEDs flicker differently (less blinks/second, blinks are brighter) (tested at 1kHz and 17kHz, at lower frequencies dimming was nicer to see);

Code:
void setup() {
... // most of the code is the same as before
pinMode(PA8, OUTPUT);
...
}
void loop() {
r1 = analogRead(PB1);
...
if (r1>320) { //a threshold to prevent input precision-related issues
analogWrite(PA8, r1/16);
}
else {
digitalWrite(PA8, LOW);
}
}

I could be wrong, but I have a sneaking suspicion that when you set PWM to zero, you're still not getting 100% off. Depending on how the PWM code is written, you might still be getting tiny blips of on time at each cycle before it turns back off again, and depending on the subtleties of the code (timer interrupts vs scheduled items checking time in a loop, beat frequencies between PWM frequency and clock frequency, etc...) it could behave differently based on changing frequency.

If I were in your shoes, I'd put an oscilloscope on the PWM pin output to see if it's going high sometimes as I suspect.
Unfortunately I don't have an oscilloscope at the moment. You could be right on the FETs not being fully off, but at max frequency (timer overflow set to 255) I literally can't see even the minimum flicker, until the PWM signal gets to values like 40/255. When "fully" off, I measure a gate-source voltage of around 100mV.

Divide and conquer.

There are two reasons why this might be happening:

1) The FET is really not turning all the way off.

2) Your PWM is still feeding pulses, when you think it should not be.

Focus on dividing the problem in two, then focus on fixing the thing that is broken.
That's the way to go! I'll focus more on the pin-gate connection now.

So I discovered I either lost or burned out all PNP transistors I had laying around, so I'll buy some of them along with bat41's to try what Dodgydave suggested.
 

Ford Prefect

Joined Jun 14, 2010
201
Hello everyone,
I'm trying to design a simple controller for 2 RGB led strips using an STM32, which controls the gates of 6x IRL540, as shown in the simplified schematic (I've drawn only one FET, as they're all connected the same way). The PWM signal is controlled by potentiometers.
Do you have any suggestions on how to turn those FETs completely off?
Forgive me for butting in, but I had much the same problem several months ago.
I designed and built a circuit switching on and off a LED striplight but the MOSFET was not turning completely off. After a while I discovered that adding a 10k resistor between the Drain of the MOSFET and the power rail solved this problem. My circuit does not use PWM.
See this and this Hope this helps.

Dark Light Circuit-3.jpg
Dark Light Circuit-v3.jpg
 

Thread Starter

Nutshell

Joined Mar 5, 2017
17
Forgive me for butting in, but I had much the same problem several months ago.
I designed and built a circuit switching on and off a LED striplight but the MOSFET was not turning completely off. After a while I discovered that adding a 10k resistor between the Drain of the MOSFET and the power rail solved this problem. My circuit does not use PWM.
See this and this Hope this helps.
Thank you for replying! Unfortunately the 10k drain-12v resistor didn't make a substantial difference in my case; I'll try with different values at different frequencies.

Time for more testing results:
- I managed to get some bat46's as my local store didn't have bat41's; datasheets look pretty similar though, so imo they should work the same in this application. With that diode between the PWM pin and gate resistor, the led blinking is considerably reduced at higher frequencies, being 99% unnoticeable at 17kHz. The piece of strip I'm testing the setup with draws 17 mA (when connected directly to the power supply, it draws 18 mA), so I can get around 94% of maximum brightness with a simple circuit and a 12-bit resolution PWM signal with this setup; an acceptable solution I would say.
- I finally tried the totem pole configuration (building it on a breadboard was a pain, though) and it works slightly better than the diode setup, allowing me to use half the frequency with no noticeable blinking(about 8.79kHz); I had to remove the resistor between gate and ground though, as it made dimming look worse (there was a huge brightness difference between 95% and 100% duty cycle). Power usage is similar to the diode setup.
Combining the diode and the totem pole, I managed to get rid of the flicker at 4.4kHz, but there's an annoyingly big brightness difference at some point, similarly to the totem pole + resistor setup.

So both of Dodgydave's suggestions were valid solutions for my problem (not when combined, though), with personal preference for the totem pole configuration
.
Thank you all for your help!
 

ebp

Joined Feb 8, 2018
2,332
"I measure 115mV between PWM pin and ground; around 109mV between gate and source."

Those voltages make no sense. The output is CMOS which should be pulling the pin actively to ground through a few tens of ohms, at most. The FET gate has a pull-down resistor. The voltage should be much much lower. I am assuming there is no internal or external pull-up resistor on the pin, but that should be verified.

Here's what I would do (with original circuit without any driver, transistors, diodes, etc.):
  1. Move the gate pull-down resistor right to the FET. If a plug-in breadboard is being used, put its leads in holes immediately adjacent to the FET pins to remove any possibility of dubious connection.
  2. Set the processor output LOW.
  3. With the meter negative lead right at the FET source pin measure the gate voltage right at the gate, the output pin of the processor and the ground on the processor board.
  4. Remove R1 and repeat the voltage measurements.
 

BobTPH

Joined Jun 5, 2013
3,025
I think you have the problem wrong. Everything you have said points to the PWM signal not actually going to 0 duty cycle. It looks to me like the PWM is putting out one cycle of ON even when you set the duty cycle to 0. This would explain the measured voltage on the output pin (which is actually pulsing but averaged by you meter), and it would explain why using the highest frequency makes the LED dimmest.

Have you tried forgetting the PWM and simply setting to the output pin to low? If it goes off then, that would be additional evidence for my theory.

Bob
 

ebeowulf17

Joined Aug 12, 2014
3,275
I think you have the problem wrong. Everything you have said points to the PWM signal not actually going to 0 duty cycle. It looks to me like the PWM is putting out one cycle of ON even when you set the duty cycle to 0. This would explain the measured voltage on the output pin (which is actually pulsing but averaged by you meter), and it would explain why using the highest frequency makes the LED dimmest.

Have you tried forgetting the PWM and simply setting to the output pin to low? If it goes off then, that would be additional evidence for my theory.

Bob
I strongly suspected that too, but in post 12 he says he tried that and still got the flicker. I'm at a loss now.
 

ebeowulf17

Joined Aug 12, 2014
3,275
I apologize if I missed this in earlier posts, but what is the power supply situation? Is it a battery, a linear supply, an SMPS? What about decoupling caps for the microcontroller and any other ICs in the circuit? Are those all in place appropriately?

If digitalwrite(low) doesn't fix it, and all the various diodes, totem poles, and pull down resistors you've tried don't fix it, that leaves me wondering if you might have a really noisy power.
 

ebp

Joined Feb 8, 2018
2,332
He does mention power supply tests.

Because of the large drain to gate capacitance in FETs it is possible for fast-rising voltage on the drain to couple to the gate sufficiently to cause at least partial turn-on. This problem is greater with FETs with low gate threshold voltage.
 

ebeowulf17

Joined Aug 12, 2014
3,275
He does mention power supply tests.
Yes, I did just notice the line about using an LTC3780 and also trying several alternate supplies.

That still leaves the question of what's dropping voltage to supply the STM32. I haven't seen any mention of decoupling caps on the STM32 either. Finally, I wonder about the ground connection between the STM32 ground and the FET source. If there are multiple power supplies involved, and at least one of them is a switcher, there could be lots of noise, so any imperfection in the ground connections could push the Vgs around.

Because of the large drain to gate capacitance in FETs it is possible for fast-rising voltage on the drain to couple to the gate sufficiently to cause at least partial turn-on. This problem is greater with FETs with low gate threshold voltage.
That's an interesting point. What would cause that sort of fast-rising voltage on the drain? I assume that would have to be power supply noise, right? Or does this thought point to some other problem/solution that I'm not understanding?

(Notice I'm shifting gears at this point - I've pretty much given up on knowing enough to be helpful in this thread; now I'm just hoping I can learn something from this thread.)
 
Top