0
\$\begingroup\$

I'm new to electronics. If I say anything that's presumptuous or just flat out weird or wrong, please point it out. There are many gaps in my knowledge.

I'm working on a simple personal project. I want to use a PIC16F88 microcontroller to toggle an LED on and off at regular intervals. I'm using this LED. If I'm interpreting the datasheet correctly, this LED is happiest when it can draw 30mA - which I'm told is quite greedy for a little LED like this. In any case, the PIC16F88 would struggle to source or sink this much current on any of its I/O pins, so the solution seems to be to use a BJT or MOSFET.

I decided to use this MOSFET - which seems a little overkill, but it's what I had available. The plan is to configure a pin on the microcontroller as a digital output, and then in software just set that pin HIGH, then sleep, then set it LOW, sleep, repeat. This signal would trigger the gate of the MOSFET and allow the desired current to flow through the LED (with a 100 Ohm resistor in series with the LED).

Here's where my questions start:

In my configuration, the PIC16F88 outputs a LOGIC HIGH at +5V. If my digital output pin is directly connected to the gate of the MOSFET, do I need to limit the current of this pin in any way, like with a resistor? I mean, I know I'll have to limit the voltage to the gate (the datasheet says the MOSFET expects a typical Gate Threshold Voltage of +2V, with a maximum of +3V), but what about the current? I certainly wouldn't want the microcontroller to try and source more current than is desirable for the I/O pins, so in a sourcing configuration, around 1.6mA? Less than that? I'm basing that guess on an answer I got for a different question I posted about the same microcontroller, where the user @glen_geek writes:

It appears that an I/O pin can sink current (8.5mA) with less stress than it can supply current (1.6mA). These are not limits, but are a single data point within the maximum limits stated elsewhere (Section 18.0 states that maximum current on any one I/O pin shouldn't exceed 25mA).

I don't really have room for experimentation, because I don't have access to a multimeter at the moment. How would I even know how much current my pin-to-gate connection is drawing? I realize that MOSFETs are voltage-controlled devices, so does any of this even matter? Does the MOSFET only draw as much current as it needs at the gate (does that even make sense)? I also know you can have voltage without also having current... is it kind of one of those things? You can tell I'm flailing at this point.

Finally, one more tangential question: Is it possible - or does it even make sense - to achieve a configuration in which the pin is sinking current (which would be desirable apparently because the microcontroller can do this more easily), and in doing so, triggering the gate of the MOSFET? I thought about this for a while but it doesn't really possible - perhaps not even useful, seeing as how I'd be using a MOSFET to do the heavy lifting anyway.

Thanks for any feedback.

\$\endgroup\$
3
  • \$\begingroup\$ I would prefer the jellybean 2N7000 which is actually specified and guaranteed for your 5V drive. It may even be the same die, but the BS170 is only specified at Vgs of 10V. With resistance of < 5.3 ohms at 4.5V drive the 2N7000 will drop less than 0.11V at 20mA. \$\endgroup\$ Sep 26, 2019 at 1:08
  • \$\begingroup\$ Thank you @Spehro Pefhany for your feedback. I will take this into consideration, but what exactly does it mean to say that the "BS170 is only specified at Vgs of 10V"? Does that mean, in my case, that the resistance between drain and source will be unnecessarily high? \$\endgroup\$
    – Paul M.
    Sep 26, 2019 at 14:38
  • \$\begingroup\$ It means that it could be. There is no guarantee, and no testing. Chances are extremely high it will be just fine, especially for driving an LED where you won’t notice a bit higher Rds(on) but it’s a bad habit to trust what is not guaranteed in the data sheet. \$\endgroup\$ Sep 26, 2019 at 15:05

2 Answers 2

2
\$\begingroup\$

1) "If I'm interpreting the datasheet correctly, this LED is happiest when it can draw 30mA" - It's not very clear in the datasheet, but you don't have to feed the LED the full 30mA. Less will do. It depends on how bright you would want the LED to be. You could start with 10-20mA or so. I'd expect even 5mA to be enough for the LED to light up.

2) "If my digital output pin is directly connected to the gate of the MOSFET, do I need to limit the current of this pin in any way" - No, you don't have to limit the current. Just apply 5V straight to the gate, no problem. The gate will draw minimal current when switching from high to low and vice versa, and no current at all when the gate voltage is constant. The gate of a MOSFET basically behaves like a small capacitor.

3) "I know I'll have to limit the voltage to the gate (the datasheet says the MOSFET expects a typical Gate Threshold Voltage of +2V, with a maximum of +3V)" - You don't have to limit the voltage to the gate either. The maximum of 3V the datasheet states is about the Threshold voltage. This is the voltage needed to start turning the MOSFET on. According to the datasheet the MOSFET typically turns on at 2V, but it could be as high as 3V before it turns on. That doesn't say anything about the maximum voltage at the gate, which is 20V according to page 1 of the datasheet. With a 5V supply, it's impossible to reach 20V, so apply the 5V straight to the gate. It's even better to apply more voltage to the gate, as more voltage on the gate means less Rdson - less resistance between source and drain when the MOSFET is on.

4) Make sure the gate of the MOSFET doesn't 'float'. So either program the microcontroller that the output is always either high (5V) or low (0V), and never high-impedance (input), or tie a large resistor (maybe somewhere between 10k and 200k) from the gate to ground to pull the gate low when the output of the microcontroller is in tri-state. If you don't do this, the state of the MOSFET will be undefined when the microcontroller output is in tri-state.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
  • \$\begingroup\$ Thank you @MartinF! Your comments make a lot of sense and are super helpful for me. I'll have to digest this, but don't be surprised if I have more questions later. \$\endgroup\$
    – Paul M.
    Sep 25, 2019 at 21:12
1
\$\begingroup\$

A MOSFET gate takes very little current and can be driven directly from the output. Your 2-3V threshold voltage is perfect for a 5V circuit.

If you want to reverse the logic, you could use a P-channel MOSFET on the high side of the LED, or invert the signal to the low side N-channel MOSFET. Luckily, based on the first answer, this will not be necessary.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the input. When you say "Your 2-3V theshold voltage is perfect for a 5V circuit", you mean that I shouldn't even worry about limiting the +5V from my output pin? If so, how would I have surmised that on my own? Thanks also for the comment about MOSFET types, I'll have to do more research. \$\endgroup\$
    – Paul M.
    Sep 25, 2019 at 20:46
  • 1
    \$\begingroup\$ You shouldn't generalise: *A mosfet [...] can be driven directly from the output". For this mosfet and this application, it will do. Generally, you should not look at the threshold voltage to determine if your IC can drive the mosfet, because the Rdson may still be quite high near the threshold voltage. Better be guided by the conditions given for the "Static Drain–Source On Resistance" or even better, check Fig 5 \$\endgroup\$
    – Huisman
    Sep 25, 2019 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.