1

I have a PIC32 reset function:

  void reset_cpu(void)
  {
        WDTCON=0x8000;
        EnableWDT(); // enable the WDT 
        ClearWDT(); 
        while(1){};
  }

It works on a PIC32MX360F512L but not on a PIC32MX695F512L. It just spins forever. Can anyone tell me why, or suggest another way to reset my processor?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Dennis Kerrisk
  • 2,715
  • 2
  • 17
  • 22

2 Answers2

1

If you are using plib.h, you can simply call this function:

void reset_cpu(void)
{
    SoftReset();
    while(1){};
}

This has the advantage to trigger an instant reset. From reset.h:

How it works: The following steps are performed by this function:

  • Step 1 - Execute "unlock" sequence to access the RSWRST register.
  • Step 2 - Write a '1' to RSWRST.SWRST bit to arm the software reset.
  • Step 3 - A Read of the RSWRST register must follow the write. This action triggers the software reset, which should occur on the next clock cycle.

Bear in mind plib is obsolete and will soon be removed from MPLAB XC32. Worth considering Harmony for new designs: http://www.microchip.com/mplabharmony

romain145
  • 13
  • 8
0

Nothing immediately stands out to me when looking at the datasheets for both of the microcontrollers. However, I do have a couple of suggestions.

First, in your function you are doing the following:

WDTCON=0x8000;
EnableWDT();

If you look at plib.h you will see that it refers to wdt.h. In wdt.h you can see that EnableWDT() is simply a macro that expands to the following:

WDTCONSET = _WDTCON_WDTCLR_MASK

Where the mask is 0x00008000. Basically, you are performing the same operation twice. Just let the macro take care of enabling it.

Also, since you are using the watchdog to reset your device, there is no need to clear the watchdog. ClearWDT() just resets the watchdog and makes your while(1) loop run longer. So, I would write your function like this:

void reset_cpu(void)
{
    EnableWDT();
    while(1){};
}

Finally, I would recommend taking a look to ensure that you have the correct processor selected in your IDE. I am not certain that this would cause your problem, but if you had the PIC32MX360F512L selected and tried running it on the PIC32MX695F512L, you could end up with the wrong register definitions (assuming that you are using #include "xc.h").

I would also check on how you are setting your device configuration bits. It is possible to set a very long timeout on the watchdog.

embedded_guy
  • 1,939
  • 3
  • 24
  • 39