Hi there,
I have a question about mosfet. How do you know and dimension the resistors?
I've seen online a current limiting resistor between the gate and the mcu most of the time. And in some ocasions I've seen a second resistor (if I got it right is a pull-down resistor) between gate and ground...
So how do I know if I need one or two resistors? Do I actually need a pulldown even if it's a logic gate? How can I calculate the values of those eventual 2 resistors? What could be the consequences of a bad resistor dimensioning? How would the answers to these question change with a "non-logic gate" transistor?
A pulldown resistor is required to put the MOSFET into a known state during the short startup period when the Arduino pins are all INPUTs and your code hasn't started yet.
The gate resistor is used to limit the initial inrush current into the gate capacitance when the capacitor is at 0V and the pin is trying to drive 5V. I would pick a resistor for something like 40-100mA in this condition. 40 is the "absolute max" for the Arduino pin but exceeding that for a nanosecond won't be a problem. Other components in the chip will limit the current.
If the gate resistance is larger, the switching is slower. If the load is very high power then slow switching leads to
lots of heat in the device (if PWM is used). Basically you design to a loss-budget - power losses are principally
on-resistance losses (I-squared-R) and switching losses (proportional to PWM frequency, switching time and
load power)
Making the gate resistor too small means larger currents flow in the Arduino pin that the absolute max
values in the datasheet. MOSFETs are massive capacitive loads (many nanofarads) for a simple logic signal
to drive (like trying to drive 100's of meters of cable).
If you need to PWM large output powers you should use a MOSFET driver chip so the switching losses aren't
huge. MOSFET driver chips can switch the device nice and fast (100's of mA or even a few amps into the
gate), reducing switching losses.
A 10k or 100k to ground is all you need on the pin to discharge the gate when the circuit is off.
So, something like 100~150ohm for the current limiting and 10kOhm for the pull-down will do it?
Should I worry about the voltage divider? (I'm aware we'r talking about less than 0.1v... but just want to make sure)
And how do I calculate the losses if I plan to do pwm? I.e. (This is not my current application but just to understand) drive a 12v / 500mA motor with a 20kHz pwm.
100-150Ohm plus 10K seem like good values to use. No, I would not normally worry about the voltage divider with those values.
Losses with PWM can get complex. Usually the best way is to hook up your circuit and see how hot the MOSFET gets. At the Arduino's default PWM frequency, it's not normally a problem. Calculating it would require deeper knowledge of the MOSFET than just what's in the datasheets. A simulation may be useful but it would take a while to learn how to drive the simulation program and you wouldn't know if your result was in the right ballpark until you built the circuit and validated that the simulation was configured correctly.