EEVblog Electronics Community Forum
Electronics => Beginners => Topic started by: eevdude on September 24, 2020, 04:18:32 pm
-
Hi Everyone,
just for some background - I haven't done any electronic design since college (etching boards, basic soldering and understanding) so i'm a bit rusty and out of touch, anyway I found Dave's videos and they have been very useful. I'm working on a few small mcu battery powered devices, and i'd like to make a generic small cr2032 powered mcu board to use in a few projects (trying to keep it small and basic components)
I've got a roughly working circuit after seeing eevblog's latching circuit and browsing the internet, but i'd like to keep it as small as possible. At the moment i'm using a 2n3906 transistor as I have no mosfets to test with. Please forgive the circuits i'm using easyeda and haven't drawn a circuit for a long while!
[attach=1] [attach=2]
Couple of issues, sometimes (i guess due to switch bounce) the mcu gets into a unknown state and I have to remove the battery to get it into a stable state. I thought I might be able to fix this by adding a reasonable sized cap, but having tried that, it didn't seem to work. Is there something I'm missing or any suggestions on a fix?
Also I believe I should replace this with an surface mount mosfet for better battery use, although I'm a bit confused as to which I would need - would I need an N channel mosfet, with a rds-on min of less than 2?
Also if anyone can spot any other issues please let me know - thanks in advance!
-
Your 2N3906 is shown upside down in the schematic. The emitter should be connected to the battery. How is it in the actual circuit? Otherwise, it looks ok to me. If there is a bounce issue, it probably will be solved with a mosfet because you can add gate capacitance. But I guess the other possibility is that the processor is coming up with the latch pin active high before your software brings it low. You could test that by adding a diode in that line so the GPIO can only bring it low. But usually GPIOs come up tristate, so that's not the likely explanation. Bounce is more likely.
-
Hi Peabody, thanks for the reply - yes it's upside down, I think i hit the flip shortcut key accidentally, still getting used to the software. It's working in the circuit so I assume it's ok ;)
How do I work out a suitable mosfet to use? I've read some of the info, but it's not clicking yet - I guess I need rsd-on min to be < 2 and it needs to handle a hundred milliamps or so, and p channel (I think i got confused before and said n channel). Is there a simple way to go from transistor to mosfet? I guess i'll order some just to double check.
I'll try the diode, but if it is the bounce, is there an easy way of fixing that? (like a capacitor on the mcu vcc in?) I still need to be able to use the switch as an input, as there's only one switch on the tiny board, and if I place this board + an expansion board in a box, I would have to unscrew it to remove the battery.
Thanks again
-
The problem with using the bipolar PNP is that you have to maintain the base current to keep the power on. If you have any switch bounce, so the base current temporarily switches off, then the PNP will turn off too. A big cap might solve the problem, but it would just depend on how bad the bouncing is, and probably wouldn't be reliable.
But to maximize battery life, you'll want to use a mosfet anyway - a P-channel. It's gate is like a capacitor. So once the switch grounds the gate long enough to turn on the mosfet, the gate capacitance is discharged, and then even if the switch bounces the gate can only be recharged through the 100K resistor, which will take some time before the mosfet actually turns off. And you can even add a small capacitor in parallel with the 100K resistor, and that will increase the gate capacitance and take even longer to turn off. Or you could raise the 100K to 220K or even 470K.
I think the key factors for mosfet selection are the voltage and current limits, neither of which is really relevant here, and the GS threshold voltage and RDSon. The threshold voltage is the GS voltage differential at which the mosfet starts to conduct. You would need one that turns on well before the 3.3V level - something like 1V maybe so it will be fully on when GS gets to 3.3V. And RDSon is just the resistance across the mosfet when it's fully on. Take a look at the DMP1045U. I think it will function as a nearly ideal switch for you.
But there is another problem, and that is that the GPIO pin that maintains the power on (PWRLATCH) will go to ground when you try to turn power off. And that will keep the PNP or mosfet turned on. So you need another stage to this - an NPN or N-channel mosfet that controls the gate of the P-channel. That second stage will turn on only when the controller is running. See attached pic. The base resistor of the NPN can actually be much higher than the 10K shown - it can be 100K or more.
-
Awesome thanks for that - the mosfet description makes the most sense. I'm still not quite reading the mosfet datasheet correctly - how do i know the minimum voltage to turn it on? Is it the Gate Threshold Voltage VGS(TH) -0.3 -0.55 -1.0 (min typ max).
Also if i'm not using the button to power the mcu off, only on + function, would i still need the transistor for pwrlatch? I think not, but i guess you could be pressing the button while the mcu is trying to turn off, but if it's a wake up button, do something for x time and sleep, i guess the code would need to reset the power off latch countdown timer so it doesn't miss the power off and stay awake for ever.
Anyway that solves my original questions thanks!!!
-
Awesome thanks for that - the mosfet description makes the most sense. I'm still not quite reading the mosfet datasheet correctly - how do i know the minimum voltage to turn it on? Is it the Gate Threshold Voltage VGS(TH) -0.3 -0.55 -1.0 (min typ max).
The table entry right below the threshold voltage is Static Drain-Source On-Resistance, which gives you some examples of on-resistance at GS voltages above the threshold. There's also Figure 2 - Typical Transfer Characteristics - which varies with temperature. But as you can see, the DMP1045U can easily handle a few hundred milliamps at not much above the threshold.
Also if i'm not using the button to power the mcu off, only on + function, would i still need the transistor for pwrlatch? I think not, but i guess you could be pressing the button while the mcu is trying to turn off, but if it's a wake up button, do something for x time and sleep, i guess the code would need to reset the power off latch countdown timer so it doesn't miss the power off and stay awake for ever.
I don't understand your question. Both your circuit and mine provide for turning on the power by pressing a button. And both require GPIO output to keep it on after the button is released. But to turn it off you would have to detect the button press in your code, wait for the button to be released after any bouncing, and then turn off the GPIO that's been maintaining power. So there's no direct power-down by pushing the button. That would be a different circuit.
There is an internal protection diode going from each GPIO pin to Vcc. But if the power is off, Vcc will be at ground. If the P-channel mosfet gate, or the PNP base, is directly connected to a GPIO, then you have a current path from the gate or base to ground through the protection diode. So the transistor would never turn off. Adding the NPN stage means the GPIO has to supply current to keep the power on, which of course can't happen when the power is off. I think you would need the NPN for PWRLATCH no matter how you trigger the power-down. Here's Dave's video on how the protection diodes work:
https://www.youtube.com/watch?v=2yFh7Vv0Paw (https://www.youtube.com/watch?v=2yFh7Vv0Paw)
-
just another exercise for single mcu pin switch press detection and self power latch. it may work it may not. fwiw..
-
Thanks Mechatrommer - I'll look at the alternate circuits for inspiration as well (maybe for other breakout boards and mcus).
Peabody - thanks for the explanation, i got confused about the pnp transistor working because the pin has to go high, totally makes sense with a p-channel mosfet that the mcu will not be able to switch off because of the pin going to gnd, will use a transistor as suggested thanks!
-
The ATtiny24A has some low power operating modes -- check out "power-down mode", "idle mode" and "standby mode" in the datasheet.
It may be possible to have the microcontroller continuously powered and your on/off control is just a switch connected to a GPIO line which wakes it up.
Update: Just wanted to add that another power saving measure is to use a lower clock speed - especially when the mcu is idling.