Author Topic: MCU driving load switching P-MOSFET  (Read 13284 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf