Author Topic: Delayed (hold down button) power on.  (Read 5566 times)

0 Members and 1 Guest are viewing this topic.

Offline LEDAeroTopic starter

  • Regular Contributor
  • *
  • Posts: 77
  • Country: nz
Delayed (hold down button) power on.
« on: January 15, 2015, 09:57:21 am »
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...

 

Offline Falcon69

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #1 on: January 15, 2015, 09:59:36 am »
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?
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: Delayed (hold down button) power on.
« Reply #2 on: January 15, 2015, 10:35:05 am »
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
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Delayed (hold down button) power on.
« Reply #3 on: January 15, 2015, 11:58:58 am »
Quote
how is this done?

Through software, I suppose:

Code: [Select]
  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.
================================
https://dannyelectronics.wordpress.com/
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: Delayed (hold down button) power on.
« Reply #4 on: January 15, 2015, 11:08:06 pm »
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.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Falcon69

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #5 on: January 15, 2015, 11:38:15 pm »
Won't he need a debounce circuit for the switch though?  Or does the software account for that?
 

Offline LabSpokane

  • Super Contributor
  • ***
  • Posts: 1899
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #6 on: January 16, 2015, 02:41:33 am »
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.
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #7 on: January 16, 2015, 03:02:22 am »
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
Complexity is the number-one enemy of high-quality code.
 

Offline LEDAeroTopic starter

  • Regular Contributor
  • *
  • Posts: 77
  • Country: nz
Re: Delayed (hold down button) power on.
« Reply #8 on: January 16, 2015, 06:32:44 am »
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.
 

Offline Falcon69

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #9 on: January 16, 2015, 06:42:41 am »
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.
 

Offline LabSpokane

  • Super Contributor
  • ***
  • Posts: 1899
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #10 on: January 16, 2015, 07:05:19 am »
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.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: Delayed (hold down button) power on.
« Reply #11 on: January 16, 2015, 09:51:32 am »
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
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Delayed (hold down button) power on.
« Reply #12 on: January 16, 2015, 12:59:56 pm »
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.
Complexity is the number-one enemy of high-quality code.
 

Offline LEDAeroTopic starter

  • Regular Contributor
  • *
  • Posts: 77
  • Country: nz
Re: Delayed (hold down button) power on.
« Reply #13 on: January 19, 2015, 06:21:12 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf