PIC Auto shutdown after inactivity

Discussion in 'Embedded Systems and Microcontrollers' started by dmarciano, May 20, 2012.

  1. dmarciano

    Thread Starter Member

    Oct 10, 2007
    21
    0
    I building a data logger and I basically want to have the PIC automatically running all the time, but after periods of inactivity have it go into a Sleep or Idle state. Coming out of Idle or Sleep would be accomplished by the use of Interrupts, but I'm having a little difficulty in figuring out how to actually detect a period of inactivity? I was thinking about after a function completes have it jump to a sub which would count a specified amount of time and then enter the sleep state, however at the same time I need to poll a number of pins for a change (can't use interrupts for all of them I don't think). I'm not expecting anybody to provide full source code, but if anybody has a link to anything describe theory or ideas to do this it would be greatly appreciated. I know there is probably a better way to do it then anything I thought of. Thanks in advance.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    The interrupt on change function looks at several pins at the same time, and if any of this number of pins change then the device interrupt fires and the device wakes. Just how many pins varies by device, so it should be on the short list when choosing which PIC to use.

    How to detect a period of inactivity is a more esoteric parameter and really depends on your specific application. I would wonder if simply going to sleep at the end of handeling a task would be OK. Then the next change input change (or polling) would wake you up and get handled.
     
  3. coldpenguin

    Active Member

    Apr 18, 2010
    165
    9
    Ernies abswer is most suitable, but I think this more closely answers the question you asked.
    In your main function, which I guess checks for activity, then branches to a routine if activity needs to be logged, increment a counter. If you have gone to a sub, reset counter to 0.
    If counter > defined time, then sleep, after ensuring there is a suitable interrupt.
     
Loading...