We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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; }
for debugging purposes, I recommend that you make a macro e.g. KICK_THE_PUPPY so that you can enable the watchdog for non-debug and disable it for debug in one place (the first 'kick' enables the wd forever). A simple way to test the WD functioning during development is just to start kicking it and it must then time out. Erik
Erik, do you know where can I find samples of this function. On how to use the WDT. I am working on the "KICK_THE_PUPPY". Thank you
do you know where can I find samples of this function. Not a function, make a macro of the two writes (see datasheet). Erik
Erik, this is what I did. I do not understand what is going on here. cacn you explain. I am sorry, but this is more complicated than I thought. I opened the WDT peripheral, but all I see is numbers running and running. Help. #include <Reg932.h> #include <stdio.h> void init(void); void brkrst_init(void); void Kick_the_Puppy(void); void Main(void) { init(); brkrst_init(); Kick_the_Puppy(); } void init(void) { P1M1 = 0x00; // Quasi-bidirectional P1M2 = 0x00; P2M1 = 0x00; // push pull output P2M2 = 0xFF; P0M1 = 0x00; P0M2 = 0xFF; //Output ES = 1; // enable UART interrupt EA = 1; } 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 Kick_the_Puppy(void) { EA = 0; WDCON = 0x05; //start WDT, and select WD oscillator WDL = 0xFF; WFEED1 = 0x0A5; //feed sequence WFEED2 = 0x05A; EA = 1; while(1); }
Only the a5/5a load is required to keep the watchdog alive so the code should be
#define KICK_THE_PUPPY WFEED1 = 0x0A5; WFEED2 = 0x05A; void Initialize_the_Puppy(void) { EA = 0; WDCON = 0x05; //start WDT, and select WD oscillator WDL = 0xFF; KICK_THE_PUPPY EA = 1; while(1); // for test }
I have no Idea how to find out if it does reset? uhmm...what about an LED lighting after a reset? if this is a good idea, where in the code should I place that instruction...sorry, but I have no idea, but I want to learn this please. Thank you
there is/are a/some bit(s) for "reset cause" read up on therm and you will know how Erik
Are you talking about the Reset Pin Enable (RPE) bit or the R_EX (external reset flag)? Thank you
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 }