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.
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:
Do you have any suggestions on how to turn those FETs completely off?
Thank you in advance!
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.
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);
}
Thank you in advance!