Technical advice on P Channel Mosfet switching for LOW POWER MCU? - Page 1
Forum section: electronics / projects

author: solarbot
author_rank: Regular Contributor
timestamp: November 02, 2023, 03:33:38 pm
content: Hi, I've been plugging away at this problem for a while now and can't seem to get to the bottom of it so throwing it out there to see what others think?I have 2 identical setups: battery powered ATMEGA boards which use an FDV304p mosfet driven by the MCU to switch off the 3V3 running to the I2C sensors and SD card so as to save power. Measuring the current when the MCU is in deep sleep and the 3V3 sensor/SD power supply switched off I get two very different power consumptions: Board 1 @ 55uA and board 2 @ 275uA. The only difference I can find is the voltage measured on the 3V3 power rail when it is switched off by the FDV304p mosfet: Board 1 @ 4mV and board 2 @ 52mV. This has led me to the conclusion that it is something to do with the P mosfet circuit that is somehow causing this? I have changed the values of the gate and pullup resistors to various different values (0R ,1K, 10K, 1M in different positions) but couldn't see any difference in behaviour? Circuit below.I'm a bit stuck so any advice gratefully received - this difference makes a big difference to battery life as you can imagine!ThanksPS I can also see that when switched OFF, the 3V3 voltage on board 1 takes several seconds to reach 4mV whereas board 2 only takes a second or less to reach the higher 52mV value.

author: CountChocula
author_rank: Unknown
timestamp: November 02, 2023, 03:43:51 pm
content: Have you double checked the resistors? Perhaps you've wired in the wrong one, or maybe there's something wrong with them.What happens if we swap the mosfets between the two boards? Do they behave the same way, or does the unexpected behaviour transfer over?Finally—not an answer to your question, but you can eliminate one of the resistors in your circuit by simply connecting a 1M between the gate and VCC, and then connect the pin of your MCU to the gate. Pull down to turn it on, put in high-Z mode to turn it off. (In fact, I seem to remember that there's a way to set up ATMEGAs so that they maintain the state of their pins when in deep sleep mode—in that case, you should be able to do away with all resistors altogether.)

author: Peabody
author_rank: Super Contributor
timestamp: November 02, 2023, 04:49:40 pm
content: If the voltage on SWT2 is 3.3V when the mosfet is switched off, and assuming Vcc is also 3.3V, then the mosfet should be completely off, and I suspect you may have a back-feed problem with other lines going from the processor to the switched-off peripherals. Any lines which are high will source current into the peripherals through their protection diodes which go from the pins to their Vcc pins. You might try putting it into shutdown, then disconnecting all of those lines, then reconnecting them one at a time to see which ones make a difference in current. The SPI and I2C lines would be the main suspects since I think all of them are high at idle. The lines need to be active low or tristate during sleep, not active high or pulled up.

author: solarbot
author_rank: Regular Contributor
timestamp: November 02, 2023, 05:30:54 pm
content: @ CountChocula - many thanks, I've checked and check again to see if the reality of the circuits are the same - not to say that there is something still amiss, I will check again :-) I've replaced the mosfet and resistors and I get the same result so I guess that rules it out (this is on a PCB so the wiring is identical). Good idea to have a manual play with the voltage levels on the mosfet directly, I will do this. I haven’t heard of pin states being preserved at the point on going into LOW POWER mode but I will try to read up on this - the MCU I'm using is the ATMEGA1284P.@ Peabody - also many thanks, the voltage on SWT2 is indeed 3V3, on the other side of the gate resistor it is more like 3V (these voltages are the same on both boards as are the measured resistance of both resistors). I will copy the test code I'm using below on both boards which set all pins LOW and as INPUTS which hopefully deals with the possibility you mention?Code:#include "LowPower.h"const uint8_t pSWT = 19; // Mosdfet to switch periferal powervoid setup() {pinMode(pSWT, OUTPUT);delay (3000);digitalWrite (pSWT, LOW);delay (3000);digitalWrite (pSWT, HIGH);delay (3000);setPinsForSleep ();delay (3000);powerOff();}void loop() {}void powerOff(){LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);delay (10); //Time to settle}void setPinsForSleep (){digitalWrite (0, LOW);digitalWrite (1, LOW);digitalWrite (2, LOW);digitalWrite (3, LOW);digitalWrite (4, LOW);digitalWrite (5, LOW);digitalWrite (6, LOW);digitalWrite (7, LOW);digitalWrite (8, LOW);digitalWrite (9, LOW);digitalWrite (10, LOW);digitalWrite (11, LOW);digitalWrite (12, LOW);digitalWrite (13, LOW);digitalWrite (14, LOW);digitalWrite (15, LOW);digitalWrite (16, LOW);digitalWrite (17, LOW);digitalWrite (18, LOW);//digitalWrite (19, LOW); // 3V3 POWER SWITCHdigitalWrite (20, LOW);digitalWrite (21, LOW);digitalWrite (22, LOW);digitalWrite (23, LOW);digitalWrite (24, LOW);digitalWrite (25, LOW);digitalWrite (26, LOW);digitalWrite (27, LOW);digitalWrite (28, LOW);digitalWrite (29, LOW);digitalWrite (30, LOW);digitalWrite (31, LOW);digitalWrite (32, LOW);pinMode(0, INPUT);pinMode(1, INPUT);pinMode(2, INPUT);pinMode(3, INPUT);pinMode(4, INPUT);pinMode(5, INPUT);pinMode(6, INPUT);pinMode(7, INPUT);pinMode(8, INPUT);pinMode(9, INPUT);pinMode(10, INPUT);pinMode(11, INPUT);pinMode(12, INPUT);pinMode(13, INPUT);pinMode(14, INPUT);pinMode(15, INPUT);pinMode(16, INPUT);pinMode(17, INPUT);pinMode(18, INPUT);//pinMode(19, INPUT);pinMode(20, INPUT);pinMode(21, INPUT);pinMode(22, INPUT);pinMode(23, INPUT);pinMode(24, INPUT);pinMode(25, INPUT);pinMode(26, INPUT);pinMode(27, INPUT);pinMode(28, INPUT);pinMode(29, INPUT);pinMode(30, INPUT);pinMode(31, INPUT);pinMode(32, INPUT);}

author: PCB.Wiz
author_rank: Super Contributor
timestamp: November 02, 2023, 07:58:57 pm
content: You should identify where the current is going.Is the PFET not properly off, or is the MCU drawing different?Check all the MCU pins, as anything floating and not disabled can draw power.

author: Peabody
author_rank: Super Contributor
timestamp: November 02, 2023, 09:06:29 pm
content: I think the 3V on the other side of R4 may be your meter's influence, particularly with R4 being 1Meg. Have you tried changing R4 to 10K, or even 100R?

author: solarbot
author_rank: Regular Contributor
timestamp: November 04, 2023, 10:00:13 am
content: Thanks all. I've now measured each SMD pin of the 1284p on both boards when the board is in sleep mode - one board has mostly very low voltages (~0.0001) whilst the other board has all sorts going on varyiing from ~0.0001 through ~0.6 to ~0.15 so I'm now suspecting the MCU!? I will build another board to see what happens and report back :-)

author: wraper
author_rank: Unknown
timestamp: November 04, 2023, 10:06:12 am
content: What's the pint making R4 1M and R2 10K? It makes no sense as it ensures both slow switching and high power consumption when pulled down. It would make some sense if it was the other way around. Also you likely don't need R2 at all.

author: solarbot
author_rank: Regular Contributor
timestamp: November 04, 2023, 11:09:30 am
content: @ wraper, unfortunately I don't know the point :-) Would a better design be 10K for the gate resistor and no pull-up resistor? Thanks for any advice

author: wraper
author_rank: Unknown
timestamp: November 04, 2023, 11:41:59 am
content: Quote from: solarbot on November 04, 2023, 11:09:30 amYou don't need gate resistor to be more 1K and actually it's not required at all. Also there probably already is a pull-up in MCU which is ON by default before MCU is configured, depends on particular MCU, IIRC according to ATMEGA datasheets I looked in pull-up was enabled by default, but don't count on that as I haven't designed anything with those for a very long time. As of disabling power to I2C/SD card, there must be no voltage present on any I/O of those while no power is present. Otherwise their power will be fed from I/O through internal ESD protection diodes.

author: wraper
author_rank: Unknown
timestamp: November 04, 2023, 11:45:02 am
content: Also since current is different on two boards, consider possible current leakage through the flux you used while soldering.

author: slugrustle
author_rank: Frequent Contributor
timestamp: November 04, 2023, 06:17:13 pm
content: Quote from: wraper on November 04, 2023, 11:41:59 amIf the P-MOSFET is switching a capacitive load, a small gate resistance risks massive inrush current and MOSFET SOA violation when the MCU turns on the MOSFET. It's probable that the I2C sensors and SD card on the switched rail have bypass capacitors. It would be a good idea to check MOSFET SOA at turn on and to also check for any droop in the main 3.3V rail at MOSFET turn on.

author: miket6000
author_rank: Contributor
timestamp: November 04, 2023, 07:54:04 pm
content: Agree, a gate drive resistor should be placed by default. If necessary you can use it for slew rate control for either output capacitor charging or EMI.Even if we don't take that in to account, how fast is the micro pin going to charge/discharge the gate capacitance? What currents will that cause to flow in the gate circuitry, and what EMC issues or worst case damage can that cause? For an rapidly changing signal the gate drive can start to become a significant power draw on a micro pin. A small gate resistor (even if only a few ohms) allows you to adjust this easily in the future if necessary without a board spin and for minimal cost.Only if I was exceptionally space or cost constrained would I consider omitting one, and only then after convincing myself that the benefit outweighs the risk.

author: solarbot
author_rank: Regular Contributor
timestamp: November 05, 2023, 05:20:24 pm
content: Thanks all. As I had been playing around with resistor values, including no gate resistor, I wonder if I damaged the MCU? I'm just waiting for parts before building a new one - I would be happy if I could repeat the results I'm getting from board 1 even though it seems the gate resistor, at 1M, is way too high and the 10K pull-up isn't needed (this switches on for 4 seconds very 10 minutes so switching speed and EMF are presumably not worth worry about?). The SD card and sensors have decoupling capacitors at 100nF and I can see a short peek in the current when the loop runs on waking so perhaps this confirms a likely damaged MCU - I will report back after a new test board gets built :-)

author: solarbot
author_rank: Regular Contributor
timestamp: November 20, 2023, 03:07:00 pm
content: Hi all, as promised here is what I found down this particular rabbit hole in the hope that it helps others with a similar question:For the FDV304 P channel mosfet I found a gate resistor of 1M and a pullup resistor of 10K works fine at 3V3. The problem I was seeing had been caused by the DS3231 RTC which has a reset function on pin 4, I had this pulled up to 3V3 but importantly in this case, mistakenly, the unswitched rail. This was causing current leakage onto the 3V3 switched rail, luckily I don't need this function so I removed the pullup resistor from the RTC reset pin and my problem was solved! I now have a sleep current measured at 2uA with the periferals turned off, this is probably as good as I will get and gives about 6 months of life from 2 AA batteries.I was looking in the wrong place.... but as with all these things I've learnt a lot.Thanks for all the input, much appreciated.

author: Peabody
author_rank: Super Contributor
timestamp: November 20, 2023, 04:11:57 pm
content: For the benefit of future readers of this thread, it should be said that a 1Meg gate resistor is several orders of magnitude greater than a normal value. To switch the mosfet's state, gate capacitance has to be overcome. The larger the gate resistor, the slower that process takes place. That means the mosfet spends more time in between on and off, and dissipates a lot more heat as a result. Using a value no higher than a few hundred ohms charges or discharges the gate faster.The /RST pin of the DS3231 is an odd duck. The datasheet describes it as an input/output pin, and it appears to only relate to whether there is currently power on Vcc. It doesn't actually reset the RTC at all, and does not affect its operation. The datasheet also says you should NOT connect an external pullup resistor to it. I've never seen a circuit that uses this pin.

author: solarbot
author_rank: Regular Contributor
timestamp: November 20, 2023, 06:22:33 pm
content: @ Peabody, I agree about a pullup on the RTC reset pin - I don't know why I used one as it clearly says not to in the datasheet! As for the mosfet, I have not experimented, all I know is that it works but I will experiment further and learn something new.