PIC32MX534F064H resets after clearing Watchdog timer

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
nexy_sm
Posts: 17
Joined: 27 Jan 2013 19:42

PIC32MX534F064H resets after clearing Watchdog timer

#1 Post by nexy_sm » 12 Aug 2017 19:08

Hi all guys,

I am sorry to address this problem once again on this forum (although previous topic was in another sub forum) but it seems I am not able to solve this problem.

Namely, I use MINI-32 development board which has PIC32MX534F064H. I use HID Bootloader from MikroE and also MikroC for PIC32 (although the problem is the same when usin XC32 compiler).

So, whenever I want to clear watchdog timer MCU resets. Here is my test program:

Code: Select all

void main() {
  AD1PCFG = 0xFFFF;                          // configure AN pins as digital
  WDTCONSET = (1 << 15);                     // start watchdog timer
  TRISD = 0;                                 // set direction to be output
  TRISG = 0;                                 // set direction to be output

  LATD = 0;                                  // turn OFF the PORTD leds
  LATG = 0;                                  // turn OFF the PORTG leds
  
  while (1) {
  //  WDTCONSET = 0x01;                        // kick the dog!!
    DATA = ~DATA;                            // Toggle DATA LED
    Wait();                                  // 1s pause
    STAT = ~STAT;                            // Toggle STAT LED
    Wait();                                  // 1s pause
  }
}
If I uncomment clearing of the watchdog timer inside the while loop the processor will reset te watcdogtimer, it will turn the LEDs on and then restart.

If I move clearing of the watchdogtimer outside the while loop, it wont restart.

Additionally, windowed watchdog mode is disabled by default (cleared bit).
Could anybody provide some working example of watchdogtimer usage for this processor.

Thanks for your suggestions in advance.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: PIC32MX534F064H resets after clearing Watchdog timer

#2 Post by p.erasmus » 14 Aug 2017 06:55

Hi

Code: Select all

//  WDTCONSET = 0x01;                        // kick the dog!!
I did not use the PIC32 WDT however a quick look in the data sheet tells me this is only switching the WDT ON or Off shouldn't you be clearing the WDTCLR bit to clear the watchdog ?
Just my thought at the moment
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

nexy_sm
Posts: 17
Joined: 27 Jan 2013 19:42

Re: PIC32MX534F064H resets after clearing Watchdog timer

#3 Post by nexy_sm » 14 Aug 2017 22:46

p.erasmus wrote:Hi

Code: Select all

//  WDTCONSET = 0x01;                        // kick the dog!!
I did not use the PIC32 WDT however a quick look in the data sheet tells me this is only switching the WDT ON or Off shouldn't you be clearing the WDTCLR bit to clear the watchdog ?
Just my thought at the moment
Hi, actually not. Bit 0 is used (when set) to clear the watchdog timer. Bit 15 is used to turn on/off the watchdog timer.

However I have some new interesting examples. Here is the code:

Code: Select all

void main() {
  AD1PCFG = 0xFFFF;                          // configure AN pins as digital
  WDTCONCLR = 0x02;                          // disable windowed mode
  WDTCONSET = (1 << 15);                     // start watchdog timer

  
  TRISD = 0;                                 // set direction to be output
  TRISG = 0;                                 // set direction to be output
  
  LATD = 0;                                  // turn OFF the PORTD leds
  LATG = 0;                                  // turn OFF the PORTG leds
  
  if (RCON & 0x10){
     STAT =1;
     DATA = 1;
     while(1);
  }
  while (1) {
    DATA = ~DATA;                            // Toggle DATA LED
    Wait();                                  // 1s pause
    WDTCONSET = 0x01;                        // kick the dog!!
    STAT = ~STAT;                            // Toggle STAT LED
    Wait();                                  // 1s pause
    WDTCONSET = 0x01;                        // kick the dog!!
  }
}
I burned this program directly with programmer. The period of the watchdog timer was set to 1024ms and in this case everything works fine - the MCU is never reset by the watchdog timer. However, if I set period of the watchdog timer to 2048ms or more, it resets the MCU immediately after i clear it. This looks like the problem with windowed mode, but as far as I can see it is disabled by default, although I also disabled it in the code.

Now, I have the following question: Is it possible to clear the watchdog timer as fast as possible without problems?

Best and thanx!

ilferrari
Posts: 195
Joined: 18 Nov 2013 09:09

Re: PIC32MX534F064H resets after clearing Watchdog timer

#4 Post by ilferrari » 15 Aug 2017 09:28

Hi, have you had a look at this topic:

WDTCLR_bit = 1; resets the microcontroller

nexy_sm
Posts: 17
Joined: 27 Jan 2013 19:42

Re: PIC32MX534F064H resets after clearing Watchdog timer

#5 Post by nexy_sm » 15 Aug 2017 22:40

ilferrari wrote:Hi, have you had a look at this topic:

WDTCLR_bit = 1; resets the microcontroller
@ilferrari you are God, thank you very much. The thread you linked helped me solve this problem, and I couldn't solve it for almost two years in summary.

I can say without any doubt that this was the nastiest problem since I am dealing with microcontrollers.
In summary, the problem is that mikroelektronika treats unused bits from the configuration registers (Devcfgx) as 0s. When somebody burns such program with the PicKit, one of the unused bits is actually activating the windowed mode of the watchdog timer (at least on PIC32MX534F064H, and other MCUs listed in the post above) which makes the whole mess. I changed the hex file by hand and now everything works.

ilferrari
Posts: 195
Joined: 18 Nov 2013 09:09

Re: PIC32MX534F064H resets after clearing Watchdog timer

#6 Post by ilferrari » 16 Aug 2017 08:55

Sorry to hear you had such problems with it. You are one of many. ME have been aware of this bug for 5 (five) years, and have still not fixed it. It's a waste of time reporting bugs on the forum because they go down the memory hole.

Post Reply

Return to “mikroC PRO for PIC32 General”