Resistors in a Mosfet Circuit

I ran across this post on mosfets:

I'd like to ask about these resistors.

R1 protects from parasitic capacitances in the mosfet that can generate currents which may find their way into your mcu and damage it?

R2 mainly controls that floating voltages dont accidentally activate the gate.

Ok how would I go about calculating the resistor values for this? Say Im using a 12V source for a solenoid and an IRLB8721 n-mosfet. I believe I need the mosfet datasheet to somehow calculate the currents generated by it in order to determine the resistor values.

For the R2 it seems easy enough, if 5v is the max voltage across a pin, if the Vth for that mosfet is 2.35V then I would need to keep the possible floating voltage below that value right? I'm thinking a voltage divider?

I understand the pull down resistor R2:

What we want is to complete a circuit or short the pin circuit to ground only when it is off. A connection to ground will so that but cause a problem when the pin goes high.

So R2 is the path the current takes when in the open circuit case when there might be floating voltages. Since we have a possible 5V we make sure very little current can go down R2, so if we make it 10,000O then only about 0.33mA will flow to ground when the pin is high.

Now R1...

Marciokoko:
I ran across this post on mosfets:
Byte and Switch (Part 1) - Jason Sachs

I'd like to ask about these resistors.

R1 protects from parasitic capacitances in the mosfet that can generate currents which may find their way into your mcu and damage it?

Well it limits the maximum current spikes seen by the pin's output transistors. Its not parasitic capacitance,
MOSFET gates are basically one plate of a capacitor.

R2 mainly controls that floating voltages dont accidentally activate the gate.

Yes and also the device doesn't fry from being half-on-half-off.

Ok how would I go about calculating the resistor values for this? Say Im using a 12V source for a solenoid and an IRLB8721 n-mosfet. I believe I need the mosfet datasheet to somehow calculate the currents generated by it in order to determine the resistor values.

Set R1 to prevent your microcontroller pin being damaged, R2 = almost anything so long as its much bigger than R1.

For the R2 it seems easy enough, if 5v is the max voltage across a pin, if the Vth for that mosfet is 2.35V then I would need to keep the possible floating voltage below that value right? I'm thinking a voltage divider?

Voltage divider isn't relevant, R2 keeps the gate at 0.00V when the microcontroller pin is high-Z.

Ok so here is the hand diagram I came up with (im working on the fritzing) and the wiring of the actual thing.

I KNOW the wiring cant go on a breadboard because the leads might melt, but I want to simply make sure the connections are correct. Im going to get a protoboard to solder everything together.

So Im attaching the picture of the actual wiring and the diagram. Wiring based on a diagram has proven tricky at times (for me) so Im just making sure :slight_smile:

The hand diagram has 4 scenarios (A-D) but Im using A which seems to be the more complete set up.

"im working on the fritzing"

Why? Those hand drawn schematics gets across what you are doing soooo much better.
If anything, go to www.expresspcb.com and use the schematic capture tool there.

Of A, B, C, I think C is the best schematic. As an engineer, that's how I would draw it. The rest are ways you might give it to a summer intern to wire it up. D might be used for a classroom discussion.

I like A because it has both resistors and yes, its more of a demo drawing. B is basically the same but without the pull-down resistor. But I agree, they are simpler and more visual. D I like because its the drawing I saw in many youtube videos about mosfets that I used to learn about mosfets recently. So its the image engraved in my head about how mosfets work and i can see the carriers and depletion regions in my head.

Im not an engineer by any means but I did like C very much and it was the last one I found. I liked it because it places each component at the voltage potential it should be.

None are as clear as the circuit in the embeddedrelated posting (even though that
uses the wrong symbols for ground and for the power MOSFET)

C is the best - clear, abstract, the right way up

You mean this one:

diagram.jpg

When you mean they use the wrong symbol for the mosfet I understand, but I thought ground could be a triangle? Maybe not cause it would get mistaken for a gate or diode?

down triangle is negative supply, up triangle is positive supply, horizontal line is signal ground.

With single supply rails the convention is normally to use ground and +ve supply, certainly
for logic chips its pretty universal in practice - but it was only a minor quibble, the diagram
is very clear which is the main point.