Author Topic: MCU driving load switching P-MOSFET  (Read 13285 times)

0 Members and 1 Guest are viewing this topic.

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
MCU driving load switching P-MOSFET
« on: February 07, 2015, 05:08:51 pm »
I'm trying to use an AVR ATTiny48 to control the gate of a P-channel MOSFET in order to switch on/off a load from 5V. So to test it I've just built the attached schematic onto a breadboard. If I connect the gate directly to 5V and ground (still through R1) the drain voltage is what I expect, i.e. on when 0V is applied and off when 5V is applied. However if I connect the gate to the MCU (which I have programmed to turn the pin high and low every 1 second), the drain voltage stays at 0V regardless.

So why is the MOSFET not turning on when the MCU grounds the gate? I've checked on the scope and the gate is definitely going high and low at 1Hz, but somehow the MOSFET isn't turning on?

I appreciate the MOSFET I'm using is overkill but it's the only one I have to hand:
https://www.fairchildsemi.com/datasheets/FQ/FQP8P10.pdf
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #1 on: February 07, 2015, 05:15:30 pm »
Forgot to attach schematic.
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #2 on: February 07, 2015, 07:57:27 pm »
Yep, same ground and same 5V rail. The MCU drives the gate right down to 0V and right up to 5V.

I haven't configured the output pin with anything special so it should be pretty standard by default. Can't see anything in the datasheet to suggest otherwise. It's pulling the voltage down to 0V no problem so Vgs = -5V and it should turn on. There must be something funny going on with the ground of the MCU pin but it's going high/low just fine so the gate is charging and discharging correctly. The FET should turn on :/
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: MCU driving load switching P-MOSFET
« Reply #3 on: February 07, 2015, 09:51:58 pm »
That MOSFET is not logic level, so switching with 5V is borderline. Setting R1 to 10R might help.
Bob
"All you said is just a bunch of opinions."
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #4 on: February 07, 2015, 10:48:52 pm »
Yeh max Vgs is -4V so -5V is enough, which I know from connecting the gate directly to +5V. Reducing the current limit resistor doesn't help - driving the gate directly from the GPIO pin results in the same behaviour.
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #5 on: February 07, 2015, 11:28:33 pm »
I always add an extra npn transistor to buffer the uc i/o and get the gnd level matching with the mosfet, esp with larger voltages like 12 to 36V that is good practice. Try it should work.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #6 on: February 07, 2015, 11:40:55 pm »
Given the 10k resistor, Vgs is hardly the issue.

I would double-check ground and connection. I would also check if the mcu's output pin is in the right mode and has its pull-up turned up without having a pull-up resistor. For safety, I would put a 10k pull-up and try again.
================================
https://dannyelectronics.wordpress.com/
 

Offline mij59

  • Frequent Contributor
  • **
  • Posts: 693
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #7 on: February 08, 2015, 05:12:07 am »
The nominal gate source voltage of the mosfet is -10V, driving the mosfet with -5V will barely turn it on.
Changing the gate resistor has no effect.
Use a proper logic mosfet.
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #8 on: February 08, 2015, 10:40:40 am »
I would also check if the mcu's output pin is in the right mode and has its pull-up turned up without having a pull-up resistor. For safety, I would put a 10k pull-up and try again.

The output pin isn't open drain/collector so, it's tri-state, so adding an external pull-up just holds the line high permanently.

The nominal gate source voltage of the mosfet is -10V, driving the mosfet with -5V will barely turn it on.
Changing the gate resistor has no effect.
Use a proper logic mosfet.

Yes I think you're right, it's not the right transistor for the job. It was all I had to hand so I tried it. But it does say in the 'On Characteristics' table that the gate threshold voltage is -2V min to -4V max. However looking further down at Figure 2 it suggests that you need -10V as you say to fully turn it on. But either way I know that -5V is enough because it turns on and off when I hook the gate directly to the 5V rail and ground.

I'll get some more appropriate mosfets but I'd still like to understand why this one doesn't work. The mosfet and the MCU are on the same ground and the gate discharges just fine so Vgs becomes -5V just like when I tie it to ground. What could be preventing current flowing through the source-drain channel?
 

Offline mij59

  • Frequent Contributor
  • **
  • Posts: 693
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #9 on: February 08, 2015, 11:01:54 am »


I'll get some more appropriate mosfets but I'd still like to understand why this one doesn't work. The mosfet and the MCU are on the same ground and the gate discharges just fine so Vgs becomes -5V just like when I tie it to ground. What could be preventing current flowing through the source-drain channel?

The mosfet could be damaged, did you measure Vgs ?
 
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #10 on: February 08, 2015, 12:05:38 pm »
-driving the mosfet with -5V will barely turn it on.-

More than enough for this case. The issue here is that when driven by a mcu, the mosfet failed to behave the same as driven by a 5v logic signal.
================================
https://dannyelectronics.wordpress.com/
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #11 on: February 08, 2015, 12:37:02 pm »
Yeah my guess is that the output of your uC is current limited and the gate is known capacitive so you
might have a "slow"slope. You're in the twilight zone of the gate spec and I know from power electronics that you want the gate voltage to switch as fast and "hard" as possible
and this takes energy. So that is why I suggested placing a NPN in front.
So take this piece of schematic and replace R44 and R52 with 10k and since you have 5V and you want to go as near as 0V as possible on the gate
you might try R68 2k2 and R61 180ohms or even a bit lower if it still doesn't behave properly.
This will take you 5 minutes so try it and tell me if it than works.
If it does you know the fault is in the output of your microcontroller which can be normal since some outputs can be shortprotected or current limited to 15mA or so.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #12 on: February 08, 2015, 01:13:12 pm »
He's only switching at one hertz so gate capacitance and resistor are a non issue.

He's demonstrated that the mosfet can switch on 5v signaling, just not with the mcu.

Your circuit is essentially what he implemented, if you think the gpio driver as the pnp.

The issue is definitely not the mosfet.
================================
https://dannyelectronics.wordpress.com/
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: MCU driving load switching P-MOSFET
« Reply #13 on: February 08, 2015, 02:37:44 pm »
He's only switching at one hertz so gate capacitance and resistor are a non issue.

If it's essentially an RC circuit, couldn't the time constant be much longer than 1s?

Although Mosfet is not exactly like an RC, so if doesn't get below threshold it never will.

The K20 like other 3.3V has very limited current sink/source on IO pins, enough for an LED that's about it. I would use some sort of gate driver.

Bob
"All you said is just a bunch of opinions."
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: MCU driving load switching P-MOSFET
« Reply #14 on: February 08, 2015, 02:40:18 pm »
What if you remove the 1s switching and just drive the pin low?  Does the fet ever turn on?  What about if you ground the pin with a jumper while the uC is driving it low, does the fet turn on then?  If so what changed?  Have you tried scoping the voltage drop across the 470R resistor?

As was mentioned before, the rated Vgs of a mosfet is not when it's on, it's the earliest point at which it will start to conduct current.  If you look at the test conditions, the rated Vgs is when Vds=Vgs at 250uA Id, that's hardly "on".  In order to consider the fet "on" you at least need to drive it past the inflection point when it switches from a negative temperature coefficient to positive, which is somewhere in excess of 6v on that unit.  Double the rated Vgs isn't a bad rule to go by either.

I think 1s just might not be long enough to get the gate low enough to conduct through that 10k resistor without a significant voltage drop.  You could also try switching to a much larger load resistor.  Also, are you watching the voltage with a dmm or scope?  The "on time" might be so short with that load resistor and a 1s on/off period that you can't catch it with a dmm.
« Last Edit: February 08, 2015, 03:02:04 pm by suicidaleggroll »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #15 on: February 08, 2015, 03:20:18 pm »
-it's essentially an RC circuit, couldn't the time constant be much longer than 1s?-

What's the capacitance need to produce a time constant of 1s with a 470 ohm resistor? What is the mosfet gate capacitance?

Once you have those numbers, the answer is self evident.
================================
https://dannyelectronics.wordpress.com/
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #16 on: February 08, 2015, 04:02:44 pm »
Your circuit is essentially what he implemented, if you think the gpio driver as the pnp..
No it is not thats the point. A GPIO can be a monstrosity, it can be a floating input, a soft or hard output and has all kinds of protection if only diodes. i once shorted an gpio hard as can be and it still survived. A single fet would have died.
It is simple if a switch to ground makes the fet conduct and the gpio on pushpull low is not they are not the same. At least he should measure Vgs in both situations they can and will not bevrhe same.

BTW it is a NPN  ;)
« Last Edit: February 08, 2015, 04:04:55 pm by Kjelt »
 

Offline jmsc_02

  • Regular Contributor
  • *
  • Posts: 63
  • Country: es
Re: MCU driving load switching P-MOSFET
« Reply #17 on: February 08, 2015, 04:14:08 pm »
Remove the resistor of the gate, the MOSFET is enabled with voltage, not current like BJT transistors.

If you want to feel safe for your MCU, put a signal transistor for buffer.
i am doing a great effort to get my english plugin up and running, but it has its bugs and "zero days" fails so please, help me to improve it!
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #18 on: February 08, 2015, 04:46:50 pm »
So take this piece of schematic and replace R44 and R52 with 10k and since you have 5V and you want to go as near as 0V as possible on the gate
you might try R68 2k2 and R61 180ohms or even a bit lower if it still doesn't behave properly.
This will take you 5 minutes so try it and tell me if it than works.
If it does you know the fault is in the output of your microcontroller which can be normal since some outputs can be shortprotected or current limited to 15mA or so.

This doesn't work either. The high output of the I/O pin drops to <2V and at the base of the NPN the voltage is ~500mV.

He's only switching at one hertz so gate capacitance and resistor are a non issue.

He's demonstrated that the mosfet can switch on 5v signaling, just not with the mcu.

Your circuit is essentially what he implemented, if you think the gpio driver as the pnp.

The issue is definitely not the mosfet.

Yes, the current rating of the I/O pin isn't the problem - it discharges the mosfet gate just fine. The I/O pin driven voltage at the mosfet gate is a good square wave with sharp edges so it's nothing to do with that.

What if you remove the 1s switching and just drive the pin low?  Does the fet ever turn on?  What about if you ground the pin with a jumper while the uC is driving it low, does the fet turn on then?  If so what changed?  Have you tried scoping the voltage drop across the 470R resistor?

No the mosfet doesn't turn on at all with the i/o pin driven low. If I ground it with a jumper then yes it does turn on, and in fact it remains on until the MCU drives the pin high again. If I ground it quickly and at the right time I can see on the scope that the mosfet remains on for a short while until the MCU turns it off. The voltage drop across the 470R is nothing - the full 5V square wave is hitting the mosfet gate.

I think 1s just might not be long enough to get the gate low enough to conduct through that 10k resistor without a significant voltage drop.  You could also try switching to a much larger load resistor.  Also, are you watching the voltage with a dmm or scope?  The "on time" might be so short with that load resistor and a 1s on/off period that you can't catch it with a dmm.

I have a 10k trimmer for the load and it doesn't turn on at all even at a short.

At least he should measure Vgs in both situations they can and will not bevrhe same.

How exactly - I don't want to hook my scope up to Vgs because I'm powering the circuit from a mains PSU so hooking my scope ground clip to the gate/source will create a ground loop..

Using a DMM doesn't seem to work. Measuring Vgs with the DMM alone registers nothing - just 0V on the DMM. But if I connect the scope again to measure the gate voltage it comes back to life but the gate is now switching between 5V and ~2.5V instead of 5V and 0V. Removing the DMM makes it go back to 5V swing. I've no idea.. maybe it's a crap DMM (it was only cheap).
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #19 on: February 08, 2015, 05:03:29 pm »
This doesn't work either. The high output of the I/O pin drops to <2V and at the base of the NPN the voltage is ~500mV.
This can not be right. The Io only has 20k to ground and it drops to 1V?
Or you made an error in the wiring (measure impedance from gpio to ground with multimeter should be 20k) or you defined the io pin wrongly it should be pushpull.
 

Offline mij59

  • Frequent Contributor
  • **
  • Posts: 693
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #20 on: February 08, 2015, 05:04:50 pm »
I think this getting dangerous, don't think your know what you doing.

Please post the complete schematic and some photo's of the circuit.
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #21 on: February 08, 2015, 05:05:58 pm »
Next step discoonect gpio and connect a led and resistor of 270 ohms and see if it can deliver that current to the led without problem.
And try both ways sourcing AND sinking.
« Last Edit: February 08, 2015, 05:08:28 pm by Kjelt »
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #22 on: February 08, 2015, 05:41:13 pm »
This can not be right. The Io only has 20k to ground and it drops to 1V?

Yeh this didn't make any sense. So I checked the code again and yes I'd set the pin to an input not an output. It's now working just fine with the pin as an output. Apologies - silly mistake. But hey, I've wasted a couple days of my life trying to get this working so I won't make that mistake again, that's for sure.

So with the pin set to input all I was doing was enabling and disabling the internal pull-up resistor. But the gate voltage was still going high/low so I still don't understand how the mosfet wasn't turning on?
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: MCU driving load switching P-MOSFET
« Reply #23 on: February 08, 2015, 07:07:01 pm »
So with the pin set to input all I was doing was enabling and disabling the internal pull-up resistor. But the gate voltage was still going high/low so I still don't understand how the mosfet wasn't turning on?

Well, you don't get much current through a high impedance input.
Bob
"All you said is just a bunch of opinions."
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #24 on: February 08, 2015, 07:20:32 pm »
Thats were the capacitance of the gate comes in I guess.
Anyway good that it is solved.
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: MCU driving load switching P-MOSFET
« Reply #25 on: February 08, 2015, 07:39:37 pm »
Well, you don't get much current through a high impedance input.

Well no, but the gate voltage fell to 0V regardless, so Vgs was still -5V, so the mosfet should have been on.
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #26 on: February 08, 2015, 08:28:18 pm »
Well no, but the gate voltage fell to 0V regardless, so Vgs was still -5V, so the mosfet should have been on.
How can you pull it low with a GPIO configured as input? The GPIO can be floating or it can be pullup but it can not be pulldown.  ;)
So I am not sure what you measured but i think you might have made a measuring mistake for instance that the instrument that did the measurement pulled the gate voltage down at the time of measurement?
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #27 on: February 08, 2015, 08:39:20 pm »
To verify I did a short experiment, took a (logic) P-fet connected it to +5V and an electronic load 100mAmps.
Let the Gate float and then with a Fluke multimeter in VDC position with the ground to the ground measured the gate voltage and it was enough to make it conduct, eg the mosfet went on.
Removing the multimeter the Fet stayed on. Again measuring the gate but this time in reference to the +5V was enough to shut the Fet off.
Not very surprising since the impedance of a multimeter might be 20 Mohms or more, still the impedance of the gate of a FET is Gohms. So your measurement influenced the result  ;)
You can try this yourself ofcourse.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #28 on: February 08, 2015, 11:55:38 pm »
Quote
I still don't understand how the mosfet wasn't turning on?

No path for the gate charges to bleed.
================================
https://dannyelectronics.wordpress.com/
 

Offline Alexei.Polkhanov

  • Frequent Contributor
  • **
  • Posts: 684
  • Country: ca
Re: MCU driving load switching P-MOSFET
« Reply #29 on: February 09, 2015, 01:25:27 am »
I am not sure why nobody suggested to use MOSFET Driver with compatible input (3.3V, TTL etc).  For example Micrel's MIC4452 will work well. (http://www.mouser.com/ds/2/495/mic4451-242003.pdf) or Elantec EL7104C. These ones I use, for some reason.
There is a whole bunch from Analog devices: http://www.analog.com/en/power-management/mosfet-drivers/products/index.html. Many have multiple inputs/multiple outputs - very convenient.


 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #30 on: February 09, 2015, 06:02:47 am »
I am not sure why nobody suggested to use MOSFET Driver with compatible input (3.3V, TTL etc).
TS just wanted to understand an experiment not a solution  :D
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: MCU driving load switching P-MOSFET
« Reply #31 on: February 09, 2015, 06:19:13 pm »
How can you pull it low with a GPIO configured as input? The GPIO can be floating or it can be pullup but it can not be pulldown.  ;)

Why not?  I don't have experience with that particular chip, but all of the ones I've used let you enable pull down resistors.
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MCU driving load switching P-MOSFET
« Reply #32 on: February 09, 2015, 09:43:50 pm »
Why not?  I don't have experience with that particular chip, but all of the ones I've used let you enable pull down resistors.
Ok well I only used MCU's which had internal pull up resistors. Which MCU you used has internal pull down resistors?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: MCU driving load switching P-MOSFET
« Reply #33 on: February 09, 2015, 10:20:38 pm »
Some of the stm32 chips have configurable pull up and pull down.
================================
https://dannyelectronics.wordpress.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: MCU driving load switching P-MOSFET
« Reply #34 on: February 09, 2015, 10:35:24 pm »
MSP430 can do up or down as well.

The DIR register controls whether it's an input or an output
The REN register enables/disables the pull resistor
The OUT register sets the output value if the pin is set to an output, or it sets pull up/down if the pin is set to an input and REN is enabled

If the OP's chip works in a similar way, then if he configured the pin as an input with the pull resistor enabled, flipping the OUT register high and low would switch back and forth between pull up and pull down as he described.
« Last Edit: February 09, 2015, 10:37:01 pm by suicidaleggroll »
 

Offline Rudolfo

  • Contributor
  • Posts: 30
Re: MCU driving load switching P-MOSFET
« Reply #35 on: February 12, 2015, 07:27:44 pm »
Interfacing the micro to power output has some special pitfalls like level shifting, ground loops or flowing outputs of the micro I/O-ports after reset. I used a design checklist like in http://www.ichaus.de/wp1_mcu_interface .
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf