Watchdog timer to check inputs?

Discussion in 'Embedded Systems and Microcontrollers' started by skybox, Jul 29, 2009.

  1. skybox

    Thread Starter Active Member

    Mar 2, 2009
    Hi guys,

    I want to minimize power consumption on my pic (an 18 series). Can I use a watchdog timer to check for any changes on some of the inputs I am monitoring and go back to sleep?

    I want to monitor a pin every 15 ms, check the state, if high, increment a counter than go back to sleep. Do this over and over.

    Thanks! i will be using the C18 compiler.
  2. nanovate

    Distinguished Member

    May 7, 2007
    Isn't there a pin change interrupt that can wake you from sleep? INT0
  3. RiJoRI

    Well-Known Member

    Aug 15, 2007
    The WDog should reset the system. It's used for runaway code, which implies something has gone wrong, you don't know what it is, so, as we said in my childhood, "Do-Over!", so it will re-initialize the counter you are trying to use.

    It would be better to use a timer and its interrupt to do what you want. (Also, it's "better form" to do it that way.)

  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    Like nanovate said, waking up from the pin change interrupt or the external interrupt is the way to go.
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    True, that is one use for the watchdog timer, however if you put the processor to sleep the watchdog timer can be used to wake it up after a predetermined period. In this case the program will simply resume from where it left off and no reset will be issued.
  6. skybox

    Thread Starter Active Member

    Mar 2, 2009
    Thanks for the replies guys. From my reading and research, yes the watchdog timer can reset a PIC if it goes in an infinite loop depending on the WDT bit settings; however,it can also be used to wake up the processor after a pre-determined time like AlexR mentioned.

    My first design was to use an external interrupt; however, it was determined that using a WD timer to wake up after every 20 ms, check any inputs for changes, if there are changes add to a counter, if counter goes over a specific value, do something would be the best way to go for power saving.

    I'll give this technique a try and let everyone know how it goes. Thanks for all the replies!