MCU driving load switching P-MOSFET - Page 1
Forum section: electronics / general

author: Digibin
author_rank: Regular Contributor
timestamp: February 07, 2015, 05:08:51 pm
content: 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

author: Digibin
author_rank: Regular Contributor
timestamp: February 07, 2015, 05:15:30 pm
content: Forgot to attach schematic.

author: Digibin
author_rank: Regular Contributor
timestamp: February 07, 2015, 07:57:27 pm
content: 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 :/

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: February 07, 2015, 09:51:58 pm
content: That MOSFET is not logic level, so switching with 5V is borderline. Setting R1 to 10R might help.

author: Digibin
author_rank: Regular Contributor
timestamp: February 07, 2015, 10:48:52 pm
content: 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.

author: Kjelt
author_rank: Super Contributor
timestamp: February 07, 2015, 11:28:33 pm
content: 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.

author: dannyf
author_rank: Super Contributor
timestamp: February 07, 2015, 11:40:55 pm
content: 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.

author: mij59
author_rank: Frequent Contributor
timestamp: February 08, 2015, 05:12:07 am
content: 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.

author: Digibin
author_rank: Regular Contributor
timestamp: February 08, 2015, 10:40:40 am
content: Quote from: dannyf on February 07, 2015, 11:40:55 pmThe output pin isn't open drain/collector so, it's tri-state, so adding an external pull-up just holds the line high permanently.Quote from: mij59 on February 08, 2015, 05:12:07 amYes 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?

author: mij59
author_rank: Frequent Contributor
timestamp: February 08, 2015, 11:01:54 am
content: Quote from: graymp89 on February 08, 2015, 10:40:40 amThe mosfet could be damaged, did you measure Vgs ?

author: dannyf
author_rank: Super Contributor
timestamp: February 08, 2015, 12:05:38 pm
content: -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.

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 12:37:02 pm
content: Yeah my guess is that the output of your uC is current limited and the gate is known capacitive so youmight 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 possibleand 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 gateyou 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.

author: dannyf
author_rank: Super Contributor
timestamp: February 08, 2015, 01:13:12 pm
content: 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.

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: February 08, 2015, 02:37:44 pm
content: Quote from: dannyf on February 08, 2015, 01:13:12 pmIf 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.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 08, 2015, 02:40:18 pm
content: What if you remove the 1s switching and just drive the pin low? Does the feteverturn 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" youat leastneed 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.

author: dannyf
author_rank: Super Contributor
timestamp: February 08, 2015, 03:20:18 pm
content: -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.

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 04:02:44 pm
content: Quote from: dannyf on February 08, 2015, 01:13:12 pmNo 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

author: jmsc_02
author_rank: Regular Contributor
timestamp: February 08, 2015, 04:14:08 pm
content: 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.

author: Digibin
author_rank: Regular Contributor
timestamp: February 08, 2015, 04:46:50 pm
content: Quote from: Kjelt on February 08, 2015, 12:37:02 pmThis 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.Quote from: dannyf on February 08, 2015, 01:13:12 pmYes, 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.Quote from: suicidaleggroll on February 08, 2015, 02:40:18 pmNo 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.Quote from: suicidaleggroll on February 08, 2015, 02:40:18 pmI have a 10k trimmer for the load and it doesn't turn on at all even at a short.Quote from: Kjelt on February 08, 2015, 04:02:44 pmHow 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).

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 05:03:29 pm
content: Quote from: graymp89 on February 08, 2015, 04:46:50 pmThis 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.

author: mij59
author_rank: Frequent Contributor
timestamp: February 08, 2015, 05:04:50 pm
content: 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.

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 05:05:58 pm
content: 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.

author: Digibin
author_rank: Regular Contributor
timestamp: February 08, 2015, 05:41:13 pm
content: Quote from: Kjelt on February 08, 2015, 05:03:29 pmYeh 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?

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: February 08, 2015, 07:07:01 pm
content: Quote from: graymp89 on February 08, 2015, 05:41:13 pmWell, you don't get much current through a high impedance input.

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 07:20:32 pm
content: Thats were the capacitance of the gate comes in I guess.Anyway good that it is solved.

author: Digibin
author_rank: Regular Contributor
timestamp: February 08, 2015, 07:39:37 pm
content: Quote from: donotdespisethesnake on February 08, 2015, 07:07:01 pmWell no, but the gate voltage fell to 0V regardless, so Vgs was still -5V, so the mosfet should have been on.

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 08:28:18 pm
content: Quote from: graymp89 on February 08, 2015, 07:39:37 pmHow 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?

author: Kjelt
author_rank: Super Contributor
timestamp: February 08, 2015, 08:39:20 pm
content: 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 resultYou can try this yourself ofcourse.

author: dannyf
author_rank: Super Contributor
timestamp: February 08, 2015, 11:55:38 pm
content: QuoteNo path for the gate charges to bleed.

author: Alexei.Polkhanov
author_rank: Frequent Contributor
timestamp: February 09, 2015, 01:25:27 am
content: 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.

author: Kjelt
author_rank: Super Contributor
timestamp: February 09, 2015, 06:02:47 am
content: Quote from: Alexei.Polkhanov on February 09, 2015, 01:25:27 amTS just wanted to understand an experiment not a solution

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 09, 2015, 06:19:13 pm
content: Quote from: Kjelt on February 08, 2015, 08:28:18 pmWhy not? I don't have experience with that particular chip, but all of the ones I've used let you enable pull down resistors.

author: Kjelt
author_rank: Super Contributor
timestamp: February 09, 2015, 09:43:50 pm
content: Quote from: suicidaleggroll on February 09, 2015, 06:19:13 pmOk well I only used MCU's which had internal pull up resistors. Which MCU you used has internal pull down resistors?

author: dannyf
author_rank: Super Contributor
timestamp: February 09, 2015, 10:20:38 pm
content: Some of the stm32 chips have configurable pull up and pull down.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 09, 2015, 10:35:24 pm
content: MSP430 can do up or down as well.The DIR register controls whether it's an input or an outputThe REN register enables/disables the pull resistorThe 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 enabledIf 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.

author: Rudolfo
author_rank: Contributor
timestamp: February 12, 2015, 07:27:44 pm
content: 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 inhttp://www.ichaus.de/wp1_mcu_interface.