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
    952


    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 18:35.
    Roger

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    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....


    Then keep it simple and use sleep and nap. They're already there for you to use and they power down the PIC to save battery power. They're totally WDT driven and don't rely on the PIC system clock (i.e. 4mhz, 20mhz, whatever). So you can set your register options for the slowest possible clock speed, wait for the sleep/nap to finish, do some checks or whatever, then when the time is right, crank up the clock speed and go.

Similar Threads

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