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
  • 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
    }

Reply
  • 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
    }

Children