IRL540 --- PWM control by ESP32

Thread Starter

Doceave

Joined Nov 16, 2019
49
The load in this case is a resistive wire used to heat a small sample of fluid to a precise temperature. A temperature PID control loop will modulate a 128Hz PWM output to keep the temperature on target.

My isssue:
> An ESP32 has no problem switching the IRL540 MOSFET on and off by means of setting a GPIO pin to 1/0 --- this with R1 10kOhm and R2 1kOhm
> If I set the GPIO pin (12 or 13) to PWM with frequency of 128Hz, and any duty cycle is selected, the heater appears to remain fully switched on
- My suspicion is that the MOSFET is not being effectively turned off

Would an expert kindly assist me with selecting values for R1 and R2 which would reliably allow the MOSFET to function with the given load at PWM frequencies as high as 512Hz? A few lines on motivation for the values chosen would also go a long way to helping others who may have similar problems.

Many thanks.

1581890719603.png
 

Marc Sugrue

Joined Jan 19, 2018
222
Your switching frequencies are relatively slow, maybe the issue resides in the component choice? First thing would be to check the Gate/Source voltage of the mosfet and see if the PWM is going fully on and Fully 0V. Let us know the voltage levels / waveforms as this will give us a clue of whats happening.

Checking the FET datasheet I suspect that as the device you are using is a very high gain and is almost fully on as far as your circuit is concerned with a Gate/Source voltage of Vgs = 2V (your load is 12V @ 5Ohm = 2.5A ) it may not be fully switching off if your PWM source isn't going fully down to 0V.
Below this Vgs (2V) you will still be in its linear region which means there will still be sufficient Volts to turn on the FET in its linear mode which would be sufficient to put some current into your resistive load. To work around this you may need to consider a different FET or Transistor.

You could try halving the Value of R1 to something like 4k7 which would help discharge the gate source capacitance quicker but as stated previously your frequency is slow so i suspect the issue is more to do with the sensitivity of your FET against such a small load..
 
Last edited:

Thread Starter

Doceave

Joined Nov 16, 2019
49
Thanks for the reply Marc

I too thought that, given the slow switching frequency, that the FET should behave much the same as with manual switching via the REPL...

Without fancy equipment measuring the PWM output voltages may be tricky --- the multimeter samples quite slowly. Although, if I set PWM to say 100% of duty_cycle and 0% of duty cycle I could measure and confirm these voltages...

Halving R1 is easy to do --- will do this also following the above.

If this fails to sort things out a PCB re-design with a transistor driving the FET may be called for.

Will revert with results ASAP.
 

Jony130

Joined Feb 17, 2009
5,487
Are you sure that your MOSFET is connected in the right way? And that you did not swap the source terminal with the drain?

Also, is your heater OFF when you set the PWM pin to low state?
 

Thread Starter

Doceave

Joined Nov 16, 2019
49
Are you sure that your MOSFET is connected in the right way? And that you did not swap the source terminal with the drain?

Also, is your heater OFF when you set the PWM pin to low state?
Hi there Jony130 --- I have assemble the circuit as per the silkscreen layer on the PCB. Thus, unless there was an error in the symbol design in the EDA software, unlikely an error. Further the MOSFET switches fine if switched manually. E.g.

heaterpin.value(1)
heaterpin.value(0)
 

sagor

Joined Mar 10, 2019
903
Try moving R1 to between R2 and the Gate. It might provide a bit faster discharge of the Gate capacitance. Also, when dropping the pin to zero, does it really go to zero, or does it float down slowly (relatively). Put a scope on that line if you have one and observe the pulse train.
Verify the ground for the +12V (Vh) is attached to the same ground as the micro and the MOSFET.
What happens if you select a low duty cycle like 10% and slow the PWM frequency down lower, does it still lock up "on"?
 

wayneh

Joined Sep 9, 2010
17,496
Verify the ground for the +12V (Vh) is attached to the same ground as the micro and the MOSFET.
Agreed. This is often overlooked. Verify wiring of adequate gauge for the current, otherwise "ground" floats up when current flows.

@Doceave, How certain are you that you're getting a PWM output as you expect? Have you played with an LED project first, to get it working?
https://techexplorations.com/guides/esp32/begin/pwm/
 

Thread Starter

Doceave

Joined Nov 16, 2019
49
Hi there Wayneh

I have done the following:
> Verified that ground on the ESP32 and the MOSFET are the same
> Verified that the MOSFET is in correctly
> Verified that manual (I.E. very low frequency switching works)
> Verified that with PWM set to 100% the PWM pin voltage is 4.9V relative to ground
> Verified that this pin is also in the mv range when PWM set to 0%

I then switched out R1 for a smaller value (about 5kOhms; by soldering two SMD 10k resistors on top of one another!!)
> As suggested by Sagor --- this on the assumption that this would discharge the gate quicker
>........ aaaand......
> That worked :)
> PW< frequency now set to 1000Hz and I can cycle nicely up and down from 0 to 128 of 1024 without a problem (above 128/1024 and the heating coil gets too hot to touch rapidly)

I take this as solved... IRL540 needs help switching off :)

You have all been extremely generous with your knowledge.
 

wayneh

Joined Sep 9, 2010
17,496
I take this as solved... IRL540 needs help switching off :)
My perspective is a little different. It feels to me that the ESP32 is not sinking current as well as it sources current. IMHO, you shouldn't need R1 at all to help discharge the gate. The fact that you do points to something about the ESP32. (This might be perfectly expected behavior.) Anyway, glad to hear it's working.
 

danadak

Joined Mar 10, 2018
4,057
Something is wacky. You state the PWM high level is 5V, yet the ESP32 PWM
runs off its power, which is a max of 3.6V.

Second, the IRL540 Rdson is specd at a min of 4V Vgson, so the ESP32 can never quite fully
turn it on.

You have limited, via 1k ohm in gate, max available gate current to charge/discharge
the IRL540s gate C. That will leave the IRL540 on in linear region longer than normally
desired, eg. dissipating un-necessary power. I would be more inclined to use 100 ohms
or less.


Regards, Dana.
 

Thread Starter

Doceave

Joined Nov 16, 2019
49
Something is wacky. You state the PWM high level is 5V, yet the ESP32 PWM
runs off its power, which is a max of 3.6V.

Second, the IRL540 Rdson is specd at a min of 4V Vgson, so the ESP32 can never quite fully
turn it on.

You have limited, via 1k ohm in gate, max available gate current to charge/discharge
the IRL540s gate C. That will leave the IRL540 on in linear region longer than normally
desired, eg. dissipating un-necessary power. I would be more inclined to use 100 ohms
or less.


Regards, Dana.
Wow I wish I had your experience in this field.... With all the advice integrated from this thread, however, the circuit is working and I am closer to knowing how it all works :)
> I forgot about an NPN transistor that I added to drive the FET (running from the 5V supply of the development board)
> I will experiment with smaller resistance at the gate

Keep well.
 

ebeowulf17

Joined Aug 12, 2014
3,307
Wow I wish I had your experience in this field.... With all the advice integrated from this thread, however, the circuit is working and I am closer to knowing how it all works :)
> I forgot about an NPN transistor that I added to drive the FET (running from the 5V supply of the development board)
> I will experiment with smaller resistance at the gate

Keep well.
Wait! When did you add the NPN? That changes everything.

How is it configured? If you want useful comments on resistor values and expected performance, we need to know what your actual circuit is! Could you share an updated schematic?
 
Top