Waking from sleep using a button press, not an external int.

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

Hi Folks,

I have a battery powered project that I'd like to use power-saving mode on. As I'm using a 32.768kHz crystal asynchronously on timer2 of a mega8 this should work pretty well.

The timer overflows ever 1 second, I plan to wake the device, increment the time keeping function, and put it back to sleep. The problem I have is that I have already etched the board and assembled the device and I don't have a button available on INT0 or INT1. Do you think it would work to check a button pin during the ISR and if it is held 2 consecutive times (2 seconds) then switch back from sleep mode? Will there be any time-keeping issues with this scenario?

Before I hash out all the code I'd like to some opinions as to whether this is an acceptable way of doing things. Psuedo code of the way I think this would work:

ISR(TIMER2_OVF_vect)
{
  Increment the time keeping variables
  if (program settings denote sleep mode)
  {
    if(read a button = btn is pressed)
    {
      if(++button press tracker = 2)
      {
        set program to stay awake
      }
      else 
      {
        set button press tracker to 0
      }
    }
    if(program still set for sleep mode)
    {
      put uC back to sleep
    }
  }
}

Please note I have not used the sleep modes before.... I'm asking for opinions on the concept of waking with this method rather than how exactly to put it to sleep, etc.

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

Certainly you can look for a long signal like that to awake. But there are other options, depending on available pins:

-- Analog comparator
-- Tn (timer-as-counter)

but these may not be available in deep sleep.

If you switch to the Mega88 [family], then you can use the pin-change interrupt to wake from any sleep mode, and have many more power-saving features in the bargain.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Certainly you can look for a long signal like that to awake. But there are other options, depending on available pins:

-- Analog comparator
-- Tn (timer-as-counter)

but these may not be available in deep sleep.

If you switch to the Mega88 [family], then you can use the pin-change interrupt to wake from any sleep mode, and have many more power-saving features in the bargain.

Thanks Lee. I'm going to give the code a try.... if I can't get it to work I did check the m88 datasheet and it seems to be a direct pin-replacement for the mega8 so that is definitely a viable solution.