Author Topic: Single button uC control  (Read 13906 times)

0 Members and 1 Guest are viewing this topic.

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Single button uC control
« on: October 09, 2012, 12:46:35 am »
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?


 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5359
  • Country: ro
  • .
Re: Single button uC control
« Reply #1 on: October 09, 2012, 01:04:27 am »
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/1232658

See the PMIC - Power Supply Controllers, Monitors  section, then filter by push button, on/off controller.

 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4720
  • Country: au
  • Question Everything... Except This Statement
Re: Single button uC control
« Reply #2 on: October 09, 2012, 01:05:19 am »
the idea isnt all that bad, you just have to be aware of what the pins do during a brownout,
 

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #3 on: October 09, 2012, 01:37:22 am »
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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11727
  • Country: my
  • reassessing directives...
Re: Single button uC control
« Reply #4 on: October 09, 2012, 01:54:40 am »
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 ;)

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #5 on: October 09, 2012, 02:09:39 am »
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.
« Last Edit: October 09, 2012, 02:12:25 am by Mike Warren »
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Re: Single button uC control
« Reply #6 on: October 09, 2012, 04:11:34 am »
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).
Was it really supposed to do that?
 

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #7 on: October 09, 2012, 04:53:58 am »
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.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Re: Single button uC control
« Reply #8 on: October 09, 2012, 05:22:16 am »
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.

Yes, I had to fix a motherboard a few years back and managed to find them at Rockby for almost nothing.
Was it really supposed to do that?
 

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #9 on: October 09, 2012, 05:31:00 am »
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.
 

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #10 on: October 09, 2012, 05:36:16 am »
Best I've been able to find so far is 16.2c for P-Channel

There'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.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Re: Single button uC control
« Reply #11 on: October 09, 2012, 05:50:41 am »
Best I've been able to find so far is 16.2c for P-Channel

There'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.

Yes, 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.

Was it really supposed to do that?
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: Single button uC control
« Reply #12 on: October 09, 2012, 12:22:33 pm »
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?
 

Offline Mike WarrenTopic starter

  • Supporter
  • ****
  • Posts: 439
  • Country: au
    • Personal Website
Re: Single button uC control
« Reply #13 on: October 09, 2012, 12:36:06 pm »
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.
 

Offline gxti

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Re: Single button uC control
« Reply #14 on: October 09, 2012, 01:58:39 pm »
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/918650

MOSFET pair for 7 cents: http://www.digikey.com/product-detail/en/DMC2400UV-7/DMC2400UV-7DITR-ND/2918383
 

Offline perfect_disturbance

  • Regular Contributor
  • *
  • Posts: 150
  • Country: us
Re: Single button uC control
« Reply #15 on: October 09, 2012, 09:34:15 pm »
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?
 


Offline perfect_disturbance

  • Regular Contributor
  • *
  • Posts: 150
  • Country: us
Re: Single button uC control
« Reply #17 on: October 10, 2012, 05:00:51 pm »
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.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Single button uC control
« Reply #18 on: October 10, 2012, 10:37:57 pm »
@p_d

I'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 failed experiment.

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.
 

Offline perfect_disturbance

  • Regular Contributor
  • *
  • Posts: 150
  • Country: us
Re: Single button uC control
« Reply #19 on: October 11, 2012, 12:59:58 am »
@p_d

I'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 failed experiment.

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.

The 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.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Single button uC control
« Reply #20 on: October 11, 2012, 02:33:51 am »
Q3 is to switch off Q2 after it has started.
So 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"?
 

Offline perfect_disturbance

  • Regular Contributor
  • *
  • Posts: 150
  • Country: us
Re: Single button uC control
« Reply #21 on: October 11, 2012, 02:49:39 am »
Q3 is to switch off Q2 after it has started.
So 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"?

Yeah 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?

 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Single button uC control
« Reply #22 on: October 11, 2012, 01:46:36 pm »
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?
Sounds 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.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Single button uC control
« Reply #23 on: October 11, 2012, 01:55:55 pm »
For what it's worth, here's my latest attempt.
 

Offline ju1ce

  • Regular Contributor
  • *
  • Posts: 96
  • Country: fi
Re: Single button uC control
« Reply #24 on: October 11, 2012, 02:14:04 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->