Simple 1 switch power control/user input

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am working on a hobby project, which includes a small graphics lcd, 3AAA battery holder, an opamp, and a micro. I'm at the point where I will mount the breadboards in a box, and decided I didn't want a normal on/off switch because of several reasons- I don't like on/off switches, I don't like more holes in the box than needed, and I hate finding the power was left on accidentally. For various reasons, I also don't want to use any low power sleep mode and just want to power everything off by keeping power from the 3.3v regulator (MCP1700). Current draw when on is <20ma.

So, I want to power up the device with a single push button switch, and also use that switch as the only user input switch (to cycle between pages viewed on the lcd). The device will power off by inactivity timeout. 1 switch, no thought required to operate it- just keep pushing the only switch in sight.

What I came up with is the circuit below, from parts I already had, and trying to get as minimal as possible. It seems to get enough current with the 4.7k resistor to get to a point where the micro can turn on Q2 (10k works mostly, but not 100%, so I dropped it down to 4.7k).

Is there a simpler/better way to do this? (with simple/common components). I'm on shaky ground using the power via R1 into an i/o pin to jump start the micro. I have been playing with it for a few days, and it continues to work reliably, though. Also, what is a good way to measure low current? I can check the voltage drop at R1 when off, which is ~1mv (decent Fluke meter), so I calculate about ~200nA (if actually 2mv, ~400na). If that is actually the case, then I think that is plenty good for the batteries being used.

Thanks for any better ideas.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps feeding micro via separate low loss regulator and use pin change interrupt for waking up is an option.
The rest of the circuit shall be fed via BJT/FET switch as above.
Powering processor via momentary button is, say, a bit unusual and the operation may vary upon voltage, temperature etc.
No offense since OP solution works - just an alternative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The previous circuit has been working fine for a while now. I now want to put in on a little circuit board I'm designing, and want to make a little change. Instead of 3xAA for power, I want to use 1xAA, with a boost regulator (MCP1640 unless there is better out there). I will be switching the battery power before it gets to the boost regulator. Here is the new circuit-

I don't have a p-channel mosfet to test this yet, any reason it will not work as intended? (Vgs threshold is listed as -0.6v typical, -1v max).

(R1 keeps Q2 off. PWRON goes to an input on the micro, which seems to provide a path to ground, turning on Q2. PWREN is set to input/pullup on soon in init code, turning on Q1. Then PWRON is set to input/pullup on to be used as a normal switch. PWREN controls power, and can turn everything off until switch pressed.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that you might have a race condition happening here.

The PWRON switch relies upon the GPIO protection diode to connect to ground, thus turning on your P channel mosfet and powering up your converter and then the AVR. As I understand it all GPIOs are tristated during AVR bootup which then kills your ground for the PWRON before your code gets to enable the PWREN line.

But you could probably make it work with a cap across your R1.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I hate to say this here, but I'm using a pic24 at the moment. My first circuit has been working without fail for almost 2 months. But I'm unsure that the switch to a mosfet for Q2 (and the lower battery voltage) will work as I think it will.

(the switch works as depicted when connected to an 'analog' pin, but not when connected to a digital only pin)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is how I did it in Elmcie: http://www.aplomb.nl/TechStuff/E...

A GIF is worth a thousend words   They are called Rosa, Sylvia and Tessa, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. I like seeing examples of how others do this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm feeling a bit dumb, plons, I don't see how you can use the button for the Null function without the device turning off. Can you possible give a brief explanation?

John

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was initially confused, also. It looks to me that the pin is set to pullup on, and the relatively high internal pullup value means the input reads low until the button is pressed. then the 9v from 4.7k causes the input to read high. I think.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The trick lies in what the AVR-pin does with the signal Pwr_hold_null: instead of driving that with a hard high, the pin remains an input, just the internal pullup is activated. That is sufficient to keep Q2 on. The voltage on Pwr_hold_null is less than 1V, so reading it results in a 0. Pressing Sw3 rises the voltage to 3.5V or more, so reads as a 1.

Edit: it took me more than 7 minutes to answer ;)

Attachment(s): 

A GIF is worth a thousend words   They are called Rosa, Sylvia and Tessa, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clever. Thanks.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got my boards from itead studio (3 weeks to get), soldered up a couple boards, and it works (with a little mod).

some pictures-
http://www.mtcnet.net/~henryvm/5...

a 1uf cap was added on the p-ch pullup to get the micro to boot-
http://www.mtcnet.net/~henryvm/5...

Yay!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

curtvm wrote:
a 1uf cap was added on the p-ch pullup to get the micro to boot-
... and that is what I suggested "way back when"... glad you got it to work.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the suggestion. I probably was not thinking about it at the time, but the idea was planted in my brain and came back to me when needed.

I'm still not sure why the original PNP version works without it, though.

I made the mistake of taking a circuit that worked for months (PNP version), and creating a new mosfet version without testing it. I did create the board with the various circuits separate, and jumpers needed to tie different sections together. That way I could easily change the way it works. Instead of the boost regulator, I decided to use a li-ion battery instead, along with a charger circuit (cheap sot6 part) using a usb mini-b as the charging source. That is working good, too.

Right now, I have it setup so all the power is switched through the mosfet circuit. Later, if I want to use the rtcc (if I use the microsd, time would be nice), I'll use the mosfet switch to turn off all other parts and have the micro powered on all the time (the micro has a rtcc but not a bat input, so needs power all the time and will be put in deep sleep, with the switch then wired up to the wake pin).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The easiest way to do this is to "bootstrap" the micro power with the pushbutton a cap and a resistor, long enough to be able to have the micro startup and take over holding the PWREN signal high by itself from a GPIO. Instead of routing the pushbutton to the micro, use the 3.3v source on one side to charge a cap on the other side, that will in turn discharge through a resistor into VCC for long enough time for the AVR to startup. As soon as the micro powers up have it drive the PWREN line. Shutdown involves simply pulling that line low.

If you want to get fancy you can have the micro beep or light a led when it has control, to tell the user he can let go of the power switch now... Add in a diode and another resistor, and you can still use the switch as an active high switch for general purpose.

Obviously this has implications for programming where you would need to hold the power high. Consider adding in a jumper header.

PS If your regulator has an enable pin (most switchers do), you can also just bootstrap THAT pin, and you can save the regulator's quiescent power consumption PLUS the switching circuitry consumption while off.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that you may have missed Curt's requirement to be able to reuse SW1 for another purpose after it achieves the power on operation.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It doesn't affect that requirement, you can still reuse the switch for general purpose after, the only constraint is it has to be active high... Look at the attached schematic. It is similar to John's, I only added the schottky to reuse the pushbutton, and the RC filter to help decay a momentary touch of the button a little smoother. It allows you to guarantee that a single touch startup will occur by supplying a buffer for the startup time your particular micro might need to keep the PWREN pin high.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep, that would work also ... with the differences being that yours uses 7 components compared with Curt/John's 6. And your switch operation is referenced to the positive rail while his is referenced to the more usual ground. Both have their merits. Cats and skinning techniques.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That doesn't gain me anything, though. I have this circuit working fine now-
http://www.mtcnet.net/~henryvm/5...

I'm still not sure if the micro is providing a ground, or is being sourced through the switch. I'll have to hook up my scope to the switch pin and the P-drain to see what is happening.

In any case, its working. I think with a few more parts a single pin solution is there, but I will need 2 pins anyway if I decide to change the power scheme (and don't want to be a pin short later). I may decide later to use the mosfet switch to control power to the other parts, and then use the push switch on the wakeup pin.

I'm always open to better solutions, though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course John's solution is good too, he manages to save one component by using the AVR's pull-up. But that will only work on AVR's, AND you have to be careful of the MOSFET you choose, one with a high gate charge might cause some issues if driven from higher impedance... ;)

Last Edited: Mon. Jan 23, 2012 - 11:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

..except I'm using a pic24.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This might be something worth looking at:
http://cds.linear.com/docs/Datasheet/2955f.pdf