Single button uC control - Page 1
Forum section: electronics / projects

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 12:46:35 am
content: I need absolute minimum current from a ATTiny24A when not in use. The circuit runs from a 9V battery, and although the uC is pretty good when in sleep mode, I still need a regulator running to keep the uC powered, so current consumption will be too high.My only control is a single momentary PB switch that must switch the device on and off and change modes.I've come up with the circuit attached, but before I build and test one I thought I'd try to get some opinions from people here.The idea is that at application of the 9V nothing will happen.Pressing the button will power up the microcontroller. The first thing the uC will do is switch on Q4 which will latch the power supply on.Now, for each press of the button, PB0 is pulled low so the program knows to change modes.Holding the button down for 2 seconds will tell the program to switch off Q4 and wait. That way, when the button is released Power will be removed from the chip and we are back where we started.Can anyone see a simpler (cheaper) way of achieving what I want? See any problems with the idea?Maybe there is a readily available chip designed for this job that I don't know about?

author: mariush
author_rank: Super Contributor
timestamp: October 09, 2012, 01:04:27 am
content: Dave did a video about latching on/off button, see his videos for an alternate circuit.There are chips that can do power on / off with delay but they're expensive... 2-4$:http://www.digikey.com/product-detail/en/LTC2954CTS8-2%23TRMPBF/LTC2954CTS8-2%23TRMPBFTR-ND/1232658See the PMIC - Power Supply Controllers, Monitors section, then filter by push button, on/off controller.

author: Rerouter
author_rank: Super Contributor
timestamp: October 09, 2012, 01:05:19 am
content: the idea isnt all that bad, you just have to be aware of what the pins do during a brownout,

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 01:37:22 am
content: Thanks for the replies.At $2+ that chip would just about double my component cost for the whole device.Brownout won't be a problem. I'll enable the brownout reset so the output pins go to high impedance when the supply is too low.

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 09, 2012, 01:54:40 am
content: what is PB0. input? output? i guess its input (high impedance), dont you need any pull up on Q3's collector to avoid floating PB0? nice idea though

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 02:09:39 am
content: PB0 can be configured either as an input or output (as can all the port pins). In this case, it would be configured as an input with an internal pullup.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: October 09, 2012, 04:11:34 am
content: You could try the little dual MOSFET chips that are used for the power button on a PC. They are very cheap and require no currect to drive them (unlike a BJT).

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 04:53:58 am
content: I guess you're talking about the little 6 pin ones? I'll look into that, but thought they'd be much more expensive. Although, it would save on a few resistors.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: October 09, 2012, 05:22:16 am
content: Quote from: Mike Warren on October 09, 2012, 04:53:58 amYes, I had to fix a motherboard a few years back and managed to find them at Rockby for almost nothing.

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 05:31:00 am
content: They'd need to be less than 5c in reel quantities. The transistors I was planning to use are about 2.8c.I've found a few N-channel at around 5c so far. Looking for P-channel at the moment.

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 05:36:16 am
content: Best I've been able to find so far is 16.2c for P-ChannelThere's also the advantage that the BC848 and BC858 are standard parts I use in a lot of other devices. I hate it every time I need to bring in a new part.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: October 09, 2012, 05:50:41 am
content: Quote from: Mike Warren on October 09, 2012, 05:36:16 amYes, that's true. Also trade off the board real-estate (if it is critical) and component loading, placement times with more components vs a single SO package. These are factors that only you can determine are important.I thought that the FETs would be dirt cheap since they are used all over the place in PC's these days, but maybe not as cheap as the jelly-beans.

author: deephaven
author_rank: Frequent Contributor
timestamp: October 09, 2012, 12:22:33 pm
content: Exactly how much standby current can you stand? An MC78LC50NTRG linear regulator has a quiescent current of around 1uA so couldn't you use that and just put the micro to sleep?

author: Mike Warren
author_rank: Unknown
timestamp: October 09, 2012, 12:36:06 pm
content: It's a little expensive at 45c in reel quantities, but it's something to think about. But I think no current in the off state would be best anyway.However, that sound nice for another project.Thanks for the suggestion.

author: gxti
author_rank: Frequent Contributor
timestamp: October 09, 2012, 01:58:39 pm
content: There are packages with complementary transistor pairs that you can wire however you like, available in both BJT and MOSFET. Saves a little board area.BJT pair for 4 cents:http://www.digikey.com/product-detail/en/MBT3946DW1T1G/MBT3946DW1T1GOSTR-ND/918650MOSFET pair for 7 cents:http://www.digikey.com/product-detail/en/DMC2400UV-7/DMC2400UV-7DITR-ND/2918383

author: perfect_disturbance
author_rank: Regular Contributor
timestamp: October 09, 2012, 09:34:15 pm
content: Newb Warning!!!OK so a bit of a newbie here but I'm working on sort of the same thing. I don't need the button to double as input to the micro I just want the button to power the circuit on and micro pin PB17 to power the circuit off. I've attached the schematic of what I've come up with so far. I have no clue what types of mosfets to use I just through in a couple common to-92 ones.Will this work? and what kinds of mosfets are the best for this?

author: andyturk
author_rank: Frequent Contributor
timestamp: October 09, 2012, 11:22:49 pm
content: http://electronics.stackexchange.com/questions/31794/implement-microcontroller-power-switch-and-re-use-the-button-for-other-features?lq=1

author: perfect_disturbance
author_rank: Regular Contributor
timestamp: October 10, 2012, 05:00:51 pm
content: Thanks for the point to the stack exchange circut I may end up using that one.As a beginner I'm also curious if the one I drew up would work.After looking at it a little longer I think I found an error I had the gate for q3 pulled up to the input voltage. What I really need was to have it pulled down so it starts low until I send microcontroller pin PB17 high.I also spent some time looking at possible parts to use for the 2 mosfets and think a BS170 and a VP2106N3-G may do the trick.I've attached an updated schematic. What do people think is this a workable solution?Thanks.

author: andyturk
author_rank: Frequent Contributor
timestamp: October 10, 2012, 10:37:57 pm
content: @p_dI'm a noob too, so my advice is worth *less* than what you pay for it. ;-)However, I recently learned a little about this type of circuit with a failedexperiment.You didn't specify the range of your input voltage, but I'd guess that it may be higher than what your mcu can handle since it looks like Q3 is intended to switch that voltage onto the gate of Q2 without frying the I/O pin. Couldn't you use a diode instead? That's a simpler part and a logic high appearing on PB17 should be enough to turn on Q2 even with the diode drop. The diode would protect the mcu from the unregulated voltage input.Is D1 to protect against reverse voltage (i.e., batteries in backwards)? Note D1 will drop up to 0.6v from your input. If your source is already close to what the regulator spits out, D1's voltage drop might cause problems.Have you thought about switch bounce? The voltage regulator circuit probably won't care, but your mcu might start doing strange things if it doesn't get a clean start at power-on.Lastly, the LM2940 datasheet says that Cout should be at least 22uF, but you've specified only 0.1uF.BTW, it's kinda fun to just dive in and build a simple circuit like this even if you're not sure it'll work. No matter what, you'll learn something along the way.

author: perfect_disturbance
author_rank: Regular Contributor
timestamp: October 11, 2012, 12:59:58 am
content: Quote from: andyturk on October 10, 2012, 10:37:57 pmThe input voltage is about 9V the circuit is intended to be powered by a 9v battery. This is higher than the microcontroller can handle but that isn't why I put in Q3. Q3 is to switch off Q2 after it has started. I guess I could have used the P-channel mosfet connected directly to the output pin of the micro I may try that.I'm ok with the diode drop I'll be burning off way more than the .6v in the regulator anyway. I have considered using 4AA's and that's why originally I put a low dropout regulator in there. However with the switch to a 9v I forgot to switch the regulator to an lm7805 but I did switch the output cap.

author: andyturk
author_rank: Frequent Contributor
timestamp: October 11, 2012, 02:33:51 am
content: Quote from: perfect_disturbance on October 11, 2012, 12:59:58 amSo what's going on at PB17? The two different flavors of FETs give me fyslexic dits... It's a shutdown signal from the mcu? I.e., logic 1 means "turn me off" and logic 0 or floating means "keep me running"?

author: perfect_disturbance
author_rank: Regular Contributor
timestamp: October 11, 2012, 02:49:39 am
content: Quote from: andyturk on October 11, 2012, 02:33:51 amYeah that's right. The button turns it on and it runs until the micro turns it off by sending PB17 high.So here is another idea I had after reading @p_d's post. My only question is if PD4 (I switched pins on the mcu but it's the same function as PB17) is floating until the mcu is done booting and I can set it low. So if the user lets up the button before the mcu boots (maybe a couple seconds) then the P-Channel MOSFET will go high and kill the power to the mcu. Is that the case? Which is better this idea or my previous one?

author: andyturk
author_rank: Frequent Contributor
timestamp: October 11, 2012, 01:46:36 pm
content: Quote from: perfect_disturbance on October 11, 2012, 02:49:39 amSounds like a race condition. Hopefully you can write the code so that the mcu will enable its own power as the first thing it does out of reset. Also, you'll have unregulated voltage appearing on PD4.

author: andyturk
author_rank: Frequent Contributor
timestamp: October 11, 2012, 01:55:55 pm
content: For what it's worth, here's my latest attempt.

author: ju1ce
author_rank: Regular Contributor
timestamp: October 11, 2012, 02:14:04 pm
content: If you have a microcontroller and a DC-DC converter with enable input, it really is as simple as producing an OR gate with diodes for power button and a microcontroller output. Connect the output of this makeshift logic gate to the enable input of the DC-DC converter. When MCU starts, it should pull the beforementioned output high. When it's time to shut down, the MCU should bring the output low.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: October 11, 2012, 02:44:52 pm
content: Hi,Please correct me if I'm wrong.From post #21, in the diagram, you have PB4 pulled up to 9v via a 10k resistor.First problem is, relative to ground pb4 will be at 9v and 10k will pass 9/10k=0.9mA.It's been known for pic's to be powered through their input pins, and 0.9mA is plenty if its running at 32khz.Also 9v on an input referenced to ground will forward bias the intrinsic protection diodes.You could clamp the pin with a zener to protect the micro but that would still draw power from your battery and still power the micro when you think it's off.Also, if you thought it was working, setting the output pin to a 1 to keep the circuit powered, and someone comes along and presses the power on button, you now have a output pin shorted to groundyou'd need another series resistor to the input pin to protect it from a short to ground.Just an observationMr Smiley

author: andyturk
author_rank: Frequent Contributor
timestamp: October 11, 2012, 04:05:25 pm
content: Quote from: ju1ce on October 11, 2012, 02:14:04 pmHi ju1ce,In my lastexperiment, I did use two diodes. In the new one, I decided to actually switch VIN because the MCP1640 requires 90% of VIN to appear on the enable pin to turn the thing on.If the circuit is using two fresh alkaline batteries, @1.65v each, that puts VIN at 3.3v and the enable threshold at 2.97v. No problem for a mcu running at 3.3v, right? However, with a diode in the way, the enable signal will lose up to 1v which would mean the mcu wouldn't be able to keep the boost converter running. A Schottky diode with a .25v drop would probably work, but there wouldn't be much room for error.A diode *would* work in place of Q3, but it seemed simpler to use the same transistor twice. The N-MOSFETs are pretty cheap too. The only other embellishment on the soft power part of the circuit is a capacitor to de-bounce the switch.

author: ju1ce
author_rank: Regular Contributor
timestamp: October 11, 2012, 07:00:26 pm
content: Quote from: andyturk on October 11, 2012, 04:05:25 pmThat's a valid point. Well, it just goes to show there's no hard-and-fast solutions.

author: perfect_disturbance
author_rank: Regular Contributor
timestamp: October 11, 2012, 11:35:56 pm
content: Quote from: Mr Smiley on October 11, 2012, 02:44:52 pmI'm planning on running an ATMega328 at 16Mhz I'm not sure if it would have the same problem as being powered through the input pin.Thanks for the catch on shorting the output to ground.So would the circuit in 17 be better? I'm honestly more comfortable with how it works anyway.