Timer and long (hours) sleep period - how to?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938

    Default Timer and long (hours) sleep period - how to?

    Hello,

    I need to record temperature & humidity over days with a sample frequency of 15 minutes.

    Since the PIC will be battery powered, I think about putting it to SLEEP until the next sample record happens.

    According to my PIC's data sheet (16F88 - 4MHz), the TMR0 won't be able to wakeup during SLEEP mode.

    What is the best way to time the PIC for long sleep periods?
    Roger

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Have a look at the SLEEP section of your datasheet, look what could Wake-Up your PIC. WatchDog timeout is one of those... if my memory serves me well.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Hello,

    I need to record temperature & humidity over days with a sample frequency of 15 minutes.

    Since the PIC will be battery powered, I think about putting it to SLEEP until the next sample record happens.

    According to my PIC's data sheet (16F88 - 4MHz), the TMR0 won't be able to wakeup during SLEEP mode.

    What is the best way to time the PIC for long sleep periods?
    Watchdog Timer at max time out is about 268 seconds, set up a counter, 3 time outs will get you 13.4 minutes (give or take). The watchdog timer isn't all that accurate. You can however use TMR1 with a low power crystal on it and prescale that a bunch, but again, you'll end up waking every so often and using that same counter to get your 15 minutes.

    You could use a 4 wind up clocks and some lever switches to reset your PIC every 15 minutes

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default What is exactly the Watchdog ment for?

    I'll try this one.

    But what is the Watchdog exactly ment for? I thought it is some kind of internal controlling timer.

    Why wouldn't I use a "timer" to do this job? There are 3 available timers in 16F88...
    Roger

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    I'll try this one.

    But what is the Watchdog exactly ment for? I thought it is some kind of internal controlling timer.

    Why wouldn't I use a "timer" to do this job? There are 3 available timers in 16F88...
    A watchdog timer is used when the program running 'goes nuts'. When it's running, you have to periodically reset the WDT. If you don't reset it, the WDT will execute a processor reset.

    There is 3 timers available, but they all use power to run them. The WDT uses a lot less power, even though it's not quite as accurate.

    Check your PBP and/or PIC manual for the CLRWDT instruction. It should become clear as mud to ya.

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default What am I missing?

    Well, after some readings today, I thought I would have won this challenge easely on my own, but... still searching my way in the myst after hours.

    Here is my simple test code:
    Code:
    ' Fuses
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
    @ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
    
    '-------------------------------------------------------------------------------
    ' Register settings
    OSCCON       = %01100000    'Internal RC set to 4MHZ
    OPTION_REG   = %00001111    'enable PORTB pullups, prescaler to WDT, rate 1:128 
    WDTCON       = %00010111    'Prescaler 1:65536, WDT ON
    
    '-------------------------------------------------------------------------------
    ' Init
    LED1 var PORTB.0
    
    '-------------------------------------------------------------------------------
    ' Program
    MAIN:
        if STATUS.4 = 0 then    'a WDT Time-Out occured
            CLEARWDT            'clear Watchdog Timer
            toggle LED1
        endif
        goto main
    
    end
    On the top of this, pre- & postscalers are not clear to me, even after reading the datasheet 3 times (must be my poor english... and my math too).

    A.- The prescaler rate is set in the OPTION_REG bits 2-0. Am I right to say that this prescaler becomes the postscaler when affected to WDT (OPTION_REG.3=1)?

    B.- At 4MHz, 1 Tosc is about 1µs. Shall I understand that, if my program would work, my LED should toggle every 128x65536=8'388'608µs=8,388...seconds? I feel this is wrong, but I don't know why.

    C.- Should I handle the WDT as an interrupt and make a routine for this (reading the datasheet it looks not to be the case, but...)?

    D.- In several block diagrams, I noticed that the WDT uses the 31,25kHz osc freq. Does this mean I have to set my oscillator to 31,25kHz (I tried this - doesn't make it better working)?

    My brain needs a break; going for some dishwashing... ;-)
    Roger

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Any code sample using WDT please?

    I really need some help on this one. Does anybody have a code sample using Watchdog timer?

    I read the "Watchdog Timer Operation" datasheet, but it is still not very clear to me.

    Here is my piece of code (that works) when I don't use the WDTCON postscaler:
    Code:
    ' Fuses
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
    @ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
    
    '-------------------------------------------------------------------------------
    ' Register settings
    OSCCON       = %01100000    'Internal RC set to 4MHZ
    ANSEL        = %00000000    'Disable Analogue Inputs
    OPTION_REG   = %00000111    'enable PORTB pullups, prescaler to WDT, rate 1:128
    'WDTCON       = %00000001    'Prescaler 1:32, WDT ON
    
    '-------------------------------------------------------------------------------
    ' Init
    LED1 var PORTB.0
    
    '-------------------------------------------------------------------------------
    ' Program
    MAIN:
        toggle LED1
        NAP 7
        goto main
    
    end
    If I use SLEEP instead of NAP, I can set up the sleeping time up to more than 18 hours.

    It looks as the pre- or postscaler don't affect the sleep period... (?)

    I'm completely lost....
    Last edited by flotulopex; - 4th January 2007 at 17:35.
    Roger

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Well, after some readings today, I thought I would have won this challenge easely on my own, but... still searching my way in the myst after hours.

    Here is my simple test code:
    Code:
    ' Fuses
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
    @ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
    
    '-------------------------------------------------------------------------------
    ' Register settings
    OSCCON       = %01100000    'Internal RC set to 4MHZ
    OPTION_REG   = %00001111    'enable PORTB pullups, prescaler to WDT, rate 1:128 
    WDTCON       = %00010111    'Prescaler 1:65536, WDT ON
    
    '-------------------------------------------------------------------------------
    ' Init
    LED1 var PORTB.0
    
    '-------------------------------------------------------------------------------
    ' Program
    MAIN:
        if STATUS.4 = 0 then    'a WDT Time-Out occured
            CLEARWDT            'clear Watchdog Timer
            toggle LED1
        endif
        goto main
    
    end
    On the top of this, pre- & postscalers are not clear to me, even after reading the datasheet 3 times (must be my poor english... and my math too).

    A.- The prescaler rate is set in the OPTION_REG bits 2-0. Am I right to say that this prescaler becomes the postscaler when affected to WDT (OPTION_REG.3=1)?

    B.- At 4MHz, 1 Tosc is about 1µs. Shall I understand that, if my program would work, my LED should toggle every 128x65536=8'388'608µs=8,388...seconds? I feel this is wrong, but I don't know why.

    C.- Should I handle the WDT as an interrupt and make a routine for this (reading the datasheet it looks not to be the case, but...)?

    D.- In several block diagrams, I noticed that the WDT uses the 31,25kHz osc freq. Does this mean I have to set my oscillator to 31,25kHz (I tried this - doesn't make it better working)?

    My brain needs a break; going for some dishwashing... ;-)
    A) Yes, that particular divider unit is a prescaler for TMR0 and a postscaler for WDT, assignable to either TMR0 or WDT, not both (actually, it can be, but that's beside the point for now).

    B) WDT is driven by internal (nominal) 31.25Khz clock source. 1/31250 = 32us... 32us * 128 * 65536 = 268.435456 seconds, 4minutes+28.36992seconds.

    C) A WDT timeout does one of two things: Either it wakes a PIC up from SLEEP (section 15.13.1) in which case it will start execution at the instruction following the SLEEP, or it'll do a PIC RESET (Table 15-2, 15-3 and 15-4).

    D) WDT clock is an independant clock source (section 15.12.1

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Replies: 5
    Last Post: - 24th February 2009, 18:55
  4. long countdown timer, how to save power?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 15th November 2008, 05:15
  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