This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Watch Dog Timer!

Hi, I need to know how to use the WDT in the P89LPC932. I have selected its internal oscillator as the clock source. However, I do not know if it would consume more power than selecting the PCLK as its clock source.
Also, how can I find out if the WDT is working fine. Do I need an infinite loop on this function? When do I call it?
I have select WDTE = 1; and WDSE = 0; in the UCFG1 register. Sorry for so many questions, but I am still a beginner on this.
Thank you


void Watch_Dog (void)
{
EA = 0;
WDCON = 0x05; //start WDT, and select WD oscillator
WDL = 0xFF;
WFEED1 = 0x0A5; //feed sequence
WFEED2 = 0x05A;
EA = 1;
}

Parents Reply Children
  • I am willing to help, but do not have the time to read the datasheet for you

    Erik

  • Erik, I had to go way from this question, because as you have seen I have to take care of other parts of my program like the external interrupt.
    To see if the WDT resets (i guess (meaning it is working fine)) could I cause a software reset? what about if it does not work fine...how do I do that.
    There is register called AUXR1 which has a bit for sotfware reset. This will be a good way to know if the WDT is reseting! or do you have a better idea.
    Thank you!

  • There is register called AUXR1 which has a bit for sotfware reset
    The bit is a bit more intricate than that. You must toggle it after a cold reset to get any use out of it.

    Erik

    PS in 'standard 51 language' AUXR1 is not not a register, it is a SFR.

  • I will toggle the SFR AUXR1. But do you think it will be a good exercise...?
    Let me just make sure...if the WDT resets (works fine) then a software reset should happens by if I set up AUXR1 correctly...right?
    Then toggle that pin. And this should repit.
    Right?
    Thanks

  • then a software reset should happens by if I set up AUXR1 correctly
    No, the bit - not "pin" - indicates that a sw reset took place, ir does not make it happen.

    If you just want to test the watchdog insert a while(); temporarily.

    Erik

  • OK, Erik I will do this today and let you know thank you. I still have not resolved my problem with the external interrupt and Power Down, but that will be a different question at a different time.

  • Erik below is the program I am using to test the WDT. I run it by using only the simulator and it worked fine (I think). This is the sample program "blinky" where port 2 shifts from right to left and left to right. The way I have it here is as follows: as soon as it finishes shifting from right to left, it initializes the WDT and after an overflow, occurs it resets the program.
    I am still a bit confused. What about in my real application when should I called or initialized the WDT.
    For what I understand the WDT should always overflow. If it does not (underflowing) then it means a software error while executing occured. therefore, the WDT will cause an system reset. Right?
    How can I keep a count of WDT underflowing... is there an interrupt for it, or just when it is used as a timer. If so what else should be included there. I have never worked with WDT before so this is new to me.

    Thanks for your help.

    #include <Reg932.h>
    #include <stdio.h>
    #include <String.h>
    UCFG1 = 0x88;

    void init(void);
    void brkrst_init(void);
    void Initialize_the_Puppy(void);
    #define KICK_THE_PUPPY WFEED1 = 0x0A5; WFEED2 = 0x05A;
    void delay (unsigned int cnt)
    {
    while (--cnt);
    }

    void Main(void)
    {
    brkrst_init();
    {
    unsigned char i;
    P2M1 = 0;
    for(;;)
    {
    for (i = 0x01; i; i <<= 1)
    { P2 = i; // simulate running lights
    delay (50000);
    }
    Initialize_the_Puppy();
    for (i = 0x80; i; i >>= 1)
    { P2 = i;
    delay (50000);
    }

    }
    }
    }

    void brkrst_init(void) // This function allows ISP entry through the UART break detect
    {
    //AUXR1 |= 0x40; // enable reset on break detect, pg. 102
    SCON = 0x50; // select the BRG as UART baud rate source, pg. 60
    SSTAT = 0x00; //Timer1
    BRGR0 = 0x70; // 9600 BAUD at @ 7.373MHz internal RC oscillator
    BRGR1 = 0x04;
    BRGCON = 0x03; // enable BRG, pg. 59
    }

    void Initialize_the_Puppy(void)
    {
    EA = 0;
    WDCON = 0x05; //start WDT, and select WD oscillator
    WDL = 0xFF;
    KICK_THE_PUPPY
    EA = 1;
    AUXR1 = 0x08;
    AUXR1 ^= ~0x08;
    while(1); // for test
    }

  • I am still a bit confused. What about in my real application when should I called or initialized the WDT.
    For what I understand the WDT should always overflow. If it does not (underflowing) then it means a software error while executing occured. therefore, the WDT will cause an system reset. Right?


    Feed the puppy or it bites

    The way a watchdog is used is that at strategic places in your program you feed it (feed sequence: see dxatasheet). If to much time passes between feeds a reset happens.

    Erik

  • Erik can you give me hints on where could be those strategic places in a program? Also, what about keeping track of the times when the WDT underflows...how would I do that.
    Thank you, you have been a great help.

  • Goto http://www.embedded.com and do a search on watchdog to access this and other nice articles on the subject.

    http://www.embedded.com/design_library/esd/hi/OEG20030115S0042

    -Walt

  • can you give me hints on where could be those strategic places in a program
    how can I? it varies from program to program.

    Erik

  • can you give me hints on where could be those strategic places in a program
    NOT in ISRs, that will defeat the purpose

    Erik

  • That is good to know. Now I think I know where to use it. but what about keeping track of every time when the WDT underflows...how would you do that.

  • That is good to know. Now I think I know where to use it. but what about keeping track of every time when the WDT underflows...how would you do that
    1) you have the softstart status bit
    2) why would you want to, it never should

    Erik

  • Erik I lost you here!
    1) you have the softstart status bit? What is that

    2) why would you want to, it never should...I just want to keep a record of the times the WDT served the micro.
    Also, how many times should I call "initialize the puppy"...I mean the feeding process should be endless or just once.
    Thank you