Motors, MOSFET switching, and 1-wire interference

Here is the TLDR: Why did problems with this circuit resolve by reducing the MOSFET gate resistor value?

I made a temperature controller that both heats and cools a chamber. The chamber is cooled by fans that circulate the air to a refrigerator after the servo has opened the flap to the duct inside the fridge. Temperature is read by 5 different ds18b20 sensors, with one of those providing the input for the PID controller.

I initially bench tested the controller using a single 12 V fan without the capacitors in the diagram and it worked flawlessly. After I hooked it up to the rest of the hardware, I immediately had problems with the ds18b20 sensors giving readings of -127C. I added the capacitors to the fans and it helped but did not completely fix the problem. I also added 0.1uF caps to the ds18b20 line and the the 5V PSU (GND to VCC), without effect. I tried other things too, including moving wiring around to reduce EMI.

Finally, I temporarily bridged the 1k Ohm gate resistor of the MOSFET with a 300 Ohm resistor (so now actual resistance is about 230 Ohm) and this seems to have fixed the problem. But I don't know why! I understand that the MOSFET should now be turning on quicker, but I can't see how that would affect the interference that I was seeing on the 1-wire bus (though it was almost exclusively happening during switching, and not while the fans were running). Maybe the EMI is still there but the duration is lower so the effect is not as pronounced? I dunno. Could someone explain this?

Edit: Yes, the NodeMCU is connected to GND, I was rushing and forgot to add that! ... and 230 Ohms is probably not sufficient to protect the NodeMCU pin (I calculated 275 Ohms for that - max 12mA at 3.3V).

The engineers I worked with usually specified gate resistors of about 50 Ohms.

The way you have the two gate resistors creates a voltage divider therefore the gate to source voltage is reduced.

Move the 10k to the left of the 1k, change the 1k to 470/220R .

1 Like

If your MCU pin can comfortably supply 20 mA, then the current limiting resistor (the 1k in your diagram) needs to be 250 ohms (5V/0.02mA). the higher the resistance, the longer it takes for the mosfet gate to fully charge up.
The reason for the resistor is that the gate is essentially a capacitor, and theoretically could sink a very large current for a very short duration as the MCU drives the output high.
The gate discharge resistor can be any large value. One could touch the gate of an active mosfet and discharge the gate and turn off the mosfet.
LarryD's suggestion of moving the resistor to left also makes sense.

Got to it before I did - by a few hours. :grin:

The conceptual problem here is that the FET gate does not "need to be pulled down".

The reason for the pull-down resistor is that until initialised, the microcontroller does not control its output pin. The microcontroller is the problem, not the FET, so the pull-down resistor goes at the microcontroller output, not the FET gate. :+1:

The reason for the the pull-down resistor is to keep the fet off, whether the microcontroller is there or not, initialized or not.
Lets say there is no MCU pin connected to the gate of the fet; it has low capacitance, and we cannot determine what effects stray voltages will have. On startup, the Atmega pins should be high impedance and not responsible for keeping the fet off.
Now lets say there is an MCU pin that is not connected to the fet gate; it can be in any state and it will have no effect on our fet, but the concern for the fet remains the same.
The reason for the resistor from the MCU to the gate is for current limiting from the output pin of the MCU.

The location of 10K pulldown is not critical. As shown (voltage divider), the gate will see 3.0V as opposed to 3.3V if the 10K is at the output pin. VGSth is well below this (2.0V), so no problem.

The series gate resistor is driving an input capacitance of 1700pF. The higher the PWM frequency (1kHz default, 40kHz max), the more time is spent in the "ohmic region" rather than the preferred "saturation region" (see figure 6 , page 8). Reducing the gate resistance decreases the time spent in the "ohmic region".

Then we do not have a working circuit, so that is clearly entirely spurious! :roll_eyes:

It has sometimes been suggested that you may wish to be able to disconnect the FET. That is still not a problem as both resistors will always be on the FET side of the assembly with the pull-down on the microcontroller side of the series resistor. This is because you do not wish the wiring capacitance to be added to the FET gate capacitance. :face_with_raised_eyebrow:

But VGSth is irrelevant to the operation of this circuit. :astonished:

Can you please post some images of your project showing especially the fan wiring?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

This is a very interesting discussion but entirely misses the OP's question

The original explanation was about the reason for the value of the pull down resistor, and had nothing to do with the location of the resistor or its philosophical underpinnings.

This is a part of the longer explanation which may have been missed. The point remains that the risk to the circuit is from the fet coming on for a few microseconds before the MCU pin reaches a defined state. The fet turning on unexpectedly is the problem to the device connected to the fet.

It is quite relevant to the whole of the discussion, which is about the behaviour of the circuit with changes in resistance, as mentioned by the OP.

Thanks for replies and the discussion! I permanently changed the gate resistor to 300 Ohms and moved it to the right of the pulldown resistor. It seemed to be working well either way, but does this mean the circuit will reach Vgs faster or only that the final voltage will be higher?

For clarification, I am NOT switching the fans using PWM. I'm using something similar to the relay output example from the PID library (Arduino-PID-Library/PID_RelayOutput.ino at master · br3ttb/Arduino-PID-Library · GitHub).

I did this for 2 reasons: (1) I didn't like how the fan behaved under PWM during testing (it was a different 12V fan but it did not turn on at all at low PWM values), and (2) I am also using a similar method to switch a relay that controls the heater.

Now I wonder if I was using PWM for the fans, would the more frequent switching cause this problem to show up again?

PWM control of small fans can be problematic at lower speeds, as you found out. Computer CPU fans, which are designed for PWM use, will have 4 wires including one for speed feedback control.

It is likely that in your application, simple fan on-off control will work. Remember that the air circulates only when the servo opens a flap to the duct, which is also an on-off situation?

Yes, the flaps are open all the time when the unit is in cooling mode. The flaps close when it goes into heating mode as the heaters are inside the main chamber. So the flaps are not moving with each switch of the fans.

Using QuickPID, you can debounce the relay and still have the full control range (0 to windowSize). Example

Are you getting reasonable results with the PID library?

Heh, heh, you missed the point completely. Do you know the significance of VGSth?

I don't like the looks of your fan ground, should have a wire straight from the MOSFET source back to the 12V PS - terminal, then a wire from there to MCU GND

No need to side track this discussion any more

So far so good but I've only used it with the heater so far. Changing the tuning parameters makes a big difference, though I haven't quite figured out what they should be yet, nor have I tried the autotune library. Honestly, a PID is probably overkill for this because I just need to maintain a steady temperature and a simple thermostat would have probably been just fine. I suppose one advantage will be reaching the set temperature quickly when the unit has been turned off.

Thanks. I understand. In reality, it is how you describe. The diagram is not really to scale and the components are laid out a little differently.