long countdown timer, how to save power?


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    Any idea what Darrel was talking about when he was saying it could be done without using an interrupt?
    I think what he was talking about is that you can use the WDT to wake up the PIC here and there and check the interrupt flag bits for Timer1 manually rather than have Timer1 provide the wakeup. Then reset the interrupt flag bits and go back to sleep.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think something like this would work. (untested)
    Code:
    <font color="#000000"><b>TMR1IF  </b><font color="#008000"><b>VAR </b></font><b>PIR1</b>.<font color="#800000"><b>0
    
    </b></font><font color="#0000FF"><b><i>;Countdown from
    </i></b></font><b>Years     </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>0
    </b></font><b>Days      </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>30
    </b></font><b>Hours     </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>4
    </b></font><b>Minutes   </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>12
    
    </b></font><b>TheCount  </b><font color="#008000"><b>VAR WORD</b></font>[<font color="#800000"><b>2</b></font>]
    
    <font color="#008000"><b>ASM  
    </b></font><font color="#000080">TotalSeconds = _Years*31536000 + _Days*86400 + _Hours*3600 + _Minutes*60
        MOVE?CW TotalSeconds &amp;&amp; 0xFFFF, _TheCount
        MOVE?CW TotalSeconds &gt;&gt; 16, _TheCount + 2
    </font><font color="#008000"><b>ENDASM
    
    </b></font><b>T1CON </b>= <font color="#800000"><b>%00001011                  </b></font><font color="#0000FF"><b><i>; T1 OSC ON, Timer ON
    
    </i></b></font><b>Main</b>:
        <b>TMR1IF </b>= <font color="#800000"><b>0                     </b></font><font color="#0000FF"><b><i>; clear the Timers IF flag
        </i></b></font>@ <font color="#008000"><b>SLEEP
        </b></font>@ <b>NOP                        
        TheCount </b>= <b>TheCount </b>- <font color="#800000"><b>2        </b></font><font color="#0000FF"><b><i>; subtract 2 seconds
        </i></b></font><font color="#008000"><b>IF </b></font><b>TheCount </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN           </b></font><font color="#0000FF"><b><i>; if low Word is 0
            </i></b></font><font color="#008000"><b>IF </b></font><b>TheCount</b>(<font color="#800000"><b>1</b></font>) = <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN    </b></font><font color="#0000FF"><b><i>;   check high Word
                </i></b></font><font color="#008000"><b>HIGH </b></font><b>PORTB</b>.<font color="#800000"><b>0           </b></font><font color="#0000FF"><b><i>;   count complete, turn a pin on
                </i></b></font><font color="#008000"><b>STOP
            ENDIF  
            </b></font><b>TheCount</b>(<font color="#800000"><b>1</b></font>) = <b>TheCount</b>(<font color="#800000"><b>1</b></font>) - <font color="#800000"><b>1  </b></font><font color="#0000FF"><b><i>; not finished dec high Word
        </i></b></font><font color="#008000"><b>ENDIF
    GOTO </b></font><b>Main
    </b>
    Make sure the WDT, VREF and anything that draws current is turned off.

    HTH,
    &nbsp; DT

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel. Nice work as usual.

    I assume that GIE and TMR1IE have to be set in order for this to work?

    The only thing i might add is TMR1H.7=1 so that it will wake up every second instead of every 2 seconds.

    *edit* Was just looking at the data sheet, and half answered my own question. So now i'm assuming that I need GIE clear and TMR1IE set.
    Last edited by Kamikaze47; - 26th June 2008 at 19:12.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    I assume that GIE and TMR1IE have to be set in order for this to work.

    The only thing i might add is TMR1H.7=1 so that it will wake up every second instead of every 2 seconds.
    You need to leave GIE OFF, since there's no Handler for it to jump to.
    But I think you're right, you may have to turn TMR1IE on to get it to Wake-Up.

    TMR1H.7=1 will work too. But it's waking up twice as often as needed, and will use twice the power.

    And after a month, a 1 second difference is less than the error rate, so attempting to get 1 second accuracy is futile at best.

    DT

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    True enough. The only reason i may want to do it is so that i can watch the seconds count down when the LCD is switched on (will have a pushbutton in series with the LCD power so its only on when u press the button). I guess its a weigh-up between battery life and pretty counting seconds
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    True enough. The only reason i may want to do it is so that i can watch the seconds count down when the LCD is switched on (will have a pushbutton in series with the LCD power so its only on when u press the button). I guess its a weigh-up between battery life and pretty counting seconds
    Should be easy enough to change the counting rate/wake up rate dynamically if you end up using the TMR1 method as described above.

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    good idea... if i tie the lcd's power pin to an input pin i can tell if the button is pressed and switch to counting seconds.

    Thanks guys, u've been a big help.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

Similar Threads

  1. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. Replies: 5
    Last Post: - 24th February 2009, 18:55
  4. dual 7-segment countdown timer code
    By dr.ragh in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 30th April 2007, 13:19
  5. Long Timer
    By Tissy in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 1st November 2005, 17:24

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