I have a project using an ATmega processor that I would like to turn on and off using a held-down button (2 secs, as a yardstick).
For things like mobile phones, MP3 players, tablets, PCs, etc. - how is this done? Is there some standard IC that I can integrate? Even my coffee machine does it...
Hopefully you bright buggers on here will have the answer - the Arduino people suggested I use one of these, but make it hard to get to...
maybe have it operate a transistor which drains a capacitor, when capacitor drops below a certain voltage, it turns the circuit off? Might take a large capacitor though, maybe a 1000uF?
You do it in software - MCU lives in sleep mode wen "off", wakes on the button input, software measures button-down time to decide whether to turn on or not. If necessary, use load switch(es) to control power to any external hardware that can't be put in a low-power mode
how is this done?
Through software, I suppose:
if button isn't pressed, reset button_pressed and button_pressed_count;
else button_pressed_count ++;
if button_pressed_count > DESIRED_BUTTON_PRESS_CNT, button_pressed |= BUTTON_LONG_PRESSED;
It is essentially a state machine.
You can do a true power-off mode, not just sleep, using a FET or LDO with enable line. The gate/enable line is connected to both the MCU and the button. When the button is pressed it pulls the line low and enables the FET/LDO, turning the micro on. The micro then waits two seconds and starts holding the line low itself, so that even if the user lets go of the button it remains turned on. It can then turn itself off by simply releasing the line.
You can, but you need to be careful about what happens when the MCU's supply drops below normal operating voltage as it turns off - you need to avoid glitches that may make it turn on again.
If you're using anything bigger than a coin cell, sleep power will usually be small compared to battery self-discharge, so this would be the "default" way to do it where possible as it requires the minimum of components and maximum flexibility in how something can be woken up.
Won't he need a debounce circuit for the switch though? Or does the software account for that?
If you want do this with an arduino, you can use to boot time as the delay. Yes, it's a shit-rigged way to do it, but it works. Stuff a MOSFET in front of the VCC, then use the momentary switch to turn on the MOSFET. Once the arduino boots, have the code latch on the MOSFET with a digital output and turn on an LED to let the user know that it's latched into the ON mode. The Arduinos reset line will power down the device.
Won't he need a debounce circuit for the switch though? Or does the software account for that?
Software can easily debounce the switch.
Here's a good article on switch debouncing that covers both hardware and software debouncing:
http://www.ganssle.com/debouncing.htm
I guess I was looking to find out how cell-phones do it - my old Ericcson is powered off - the battery has been taken out and replaced.
When I come to turn it on, I have to hold the button down for a certain time before the unit comes on - or is that all just consumer perception - it actually started being powered as soon as the battery got installed and the hold-to-power is just a software trick?
You can do a true power-off mode, not just sleep, using a FET or LDO with enable line. The gate/enable line is connected to both the MCU and the button. When the button is pressed it pulls the line low and enables the FET/LDO, turning the micro on. The micro then waits two seconds and starts holding the line low itself, so that even if the user lets go of the button it remains turned on. It can then turn itself off by simply releasing the line.
Having said that, modern MCUs sleep at such insanely low current anyway it's hardly worth bothering with. Sub 5uA should be easy on a MEGA. You need to connect the button to a GPIO with async interrupt capability, so that the interrupt will be triggered even in sleep mode. Synchronous interrupts need the MCU, or at least the CPU clock, to be running.
That sounds more like it. An LDO is a Low DropOut regulator? And I'm not up to FET yet in my 'Dummies Guide to Electronics', so I suspect this is beyond my abilities right now and I need to keep working through the book - and take the Arduino recommendation of recessing a switch
Doing some reading, the Atmega328P that I will be using has six sleep modes - the most frugal of which is SLEEP_MODE_PWR_DOWN, which uses 0.36 mA. That's less than half an amp in a year. Assuming I use batteries which hold their charge for that period - like low self-discharge NiMH - it makes sense to do it in software, like you say.
Thanks to all for your replies - very thought provoking.
LEDAero,
I have a Galaxy mini S4 and it also does that as well. Every cell phone i have owned does that. I believe it is made like that to keep the phone from turning on (or off) in the event it is in your pocket or something and the on/off switch is touched briefly, which otherwise would turn the phone off.
FETs are no-brainer devices as switches. You can do it.
If you're working in the arduino environment, there is a library that enables the sleep functions without having to mess with writing to registers directly. I haven't played with it yet, so I don't know how well it has been implemented.
And the hold to turn on is not just a perception, it is a feature.
Won't he need a debounce circuit for the switch though? Or does the software account for that?
Software can easily debounce the switch.
Here's a good article on switch debouncing that covers both hardware and software debouncing:
http://www.ganssle.com/debouncing.htm
No need for much debouncing as you're not counting presses - worst case you go through a few sleep/wake cycles before actually powering up, which doesn't matter, otherwise just add a few mS delay after wake before looking at the button state. If you're using a crystal or resonator thn the start-up time will cover any bounce time
Software can easily debounce the switch.
Here's a good article on switch debouncing that covers both hardware and software debouncing:
http://www.ganssle.com/debouncing.htm
No need for much debouncing as you're not counting presses - worst case you go through a few sleep/wake cycles before actually powering up, which doesn't matter, otherwise just add a few mS delay after wake before looking at the button state. If you're using a crystal or resonator thn the start-up time will cover any bounce time
It just seems inelegant to me to let it thrash around a few times when a few lines of C would prevent it.
FETs are no-brainer devices as switches. You can do it.
If you're working in the arduino environment, there is a library that enables the sleep functions without having to mess with writing to registers directly. I haven't played with it yet, so I don't know how well it has been implemented.
And the hold to turn on is not just a perception, it is a feature.
I will do more digging, thanks.