long countdown timer, how to save power?


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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

  4. #4
    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.

  5. #5
    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

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


    Did you find this post helpful? Yes | No

    Default

    OK, the 32.768kHz crystals I ordered finally arrived, so i'm trying to get this working, but it looks like the timer is not waking up the PIC.

    I tested the timer by itself and its happily overflowing every 2 seconds, but either its not running when in sleep mode, or it is and the overflow isnt waking up the PIC.

    Code:
    ADCON0=%00000000
    ADCON1=%01111111
    T1CON=%00001111
    
    TMR1IE VAR PIE1.0
    TMR1IF VAR PIR1.0
    
    TMR1IE=1
    
    
    '... main code here - calls countdown suburoutine ...'
    
    
    countdown: 
    LCDOUT $FE,1,$FE,2,"Starting"
    TMR1IF=0
    @ SLEEP
    @ NOP      
    LCDOUT $FE,1,$FE,2,"Time Remaining"
    GOSUB update_lcd
    GOSUB update_time_vars
    IF timeup=1 then RETURN
    GOTO countdown
    I get "Starting" displayed on the LCD, but that's it, I never see "Time Remaining".

    Any ideas?

    edit: config, in case its relevant:

    Code:
            __CONFIG    _CONFIG1H, _INTIO2_OSC_1H 
            __CONFIG    _CONFIG2H, _WDT_OFF_2H
            __CONFIG    _CONFIG3H, _MCLRE_ON_3H
            __CONFIG    _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    Ok, I answered my own question

    After looking at the interrupt logic diagram in the data sheet, I realised that I also had to set PEIE in order for TMR1 overflow to wake the PIC. So I added:

    Code:
    PEIE VAR INTCON.6
    PEIE=1
    And all is working good.
    "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