Sleep when inactive ... how ?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104

    Default Sleep when inactive ... how ?

    I'm sure this is simple but I can't find the answer (even with the new improved search engine) so perhaps I'm phrasing the question wrong.

    I want a 16F628 to go to sleep when inactive for say 60secs.
    The code I'm using is constantly looping looking for a trigger signal to go low before firing a camera but I'd like it to power down completely if nothing happens for say 60secs and wake up again and start monitoring the trigger if a PORTB pin changes state.

    Thanks, Andrew

  2. #2
    Join Date
    Aug 2005
    Location
    down south
    Posts
    90


    Did you find this post helpful? Yes | No

    Default

    not sure if this is what your looking for but is what I do with my camera


    ON INTERRUPT GoTo TAKEPIC 'ON PIR TRIP WAKE UP
    INTCON=$90 'ENABLE .2 INTERUPT
    " be nice it's people like me that make people like you look smart"
    yes I read the datasheet, of the 300 pages I understood 10

  3. #3
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Possibly

    The thing is I want an LCD to display some relevant info for a short time after the shot is taken but then go to sleep.

    I suppose I could use a timer overflow to trigger the SLEEP command, and reset the timer everytime something happens to keep it awake ?

    Running at 4MHz can I count to 60secs with an internal timer or do I need to use the timer overflow to increment a "second counter" ?

    Andrew

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    The easiest way would be to count down 60 x 1 second delays using pause. After that time, simply put your PIC to sleep. The delay can be reset by the Interrupt occurence.

    Code:
    ISR:
    
    ....
    ....
       SleepTimeOut = 60
    
    INT_RETURN
    
    main:
    ...
    ...
       if SleepTimeOut <> 0 then 
              pause  1000
              SleepTimeOut = SleepTimeOut-1
       else
              @ sleep   ' use the ASM sleep command
              @ nop     ' some pics need these 2 nops (the datasheet will tell)
              @ nop
       endif
       goto main

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Andrew

    If your program loops ...

    just count how many loops in a minute ... and go to an @sleep command if value reaches the loops per minute value ...

    just need to add a counter and a test in your loop ...

    Non-blocking solution ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    So Alain,

    One thing that I always find difficult to answer, how can you work out how many clock cycles are used by a particular group of PBP instructions ? I could test it empirically but there must be a way of calculating it.

    Thanks, Andrew

  7. #7
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    The easiest way would be to count down 60 x 1 second delays using pause. After that time, simply put your PIC to sleep. The delay can be reset by the Interrupt occurence.

    Code:
    ISR:
    
    ....
    ....
       SleepTimeOut = 60
    
    INT_RETURN
    
    main:
    ...
    ...
       if SleepTimeOut <> 0 then 
              pause  1000
              SleepTimeOut = SleepTimeOut-1
       else
              @ sleep   ' use the ASM sleep command
              @ nop     ' some pics need these 2 nops (the datasheet will tell)
              @ nop
       endif
       goto main
    Would work but then I need to rewrite my code - I don't trigger off an interrupt but instead look at PortB which holds not just the trigger signal but also a small keypad. The unit I'm making isn't just a simple "fire", there is also a small menu system to enter a few system parameters.

    Not impossible to rewrite but perhaps I'll just count how many times I loop and conditionally branch ..

    Thanks, Andrew

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. 16F628A current high during sleep
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th October 2006, 10:21
  4. Wierd sleep issue
    By orca in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th March 2006, 22:06
  5. SLEEP Command and Interupts 16F648A
    By ghoot in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 28th May 2004, 18:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts