Soy nuevo en el desarrollo de uC y he estado jugando con la serie PIC durante aproximadamente 6 meses. Recientemente comencé a trabajar con el compilador PIC32 y XC32 C++ de Microchip. No sé si tengo un malentendido fundamental de cómo funciona el WDT en la serie PIC, o si hay alguna advertencia que desconozco, sin embargo, tengo un código que creo que debería encender un LED en RA0, luego encender se apaga y después de 512 ms, el WDT debe restablecer el uC y el proceso debe comenzar de nuevo. Lo que realmente sucede es que el LED se enciende momentáneamente, luego se apaga y nunca más se vuelve a encender. No sé si esto significa que el WDT está configurado incorrectamente o qué. Aquí está mi código:
#include <xc.h>
#define LED _LATA0
/*
*
*/
int main(int argc, char** argv) {
WDTCONbits.WDTPS = 0b1001; //512ms postscaler
WDTCONbits.WDTCLR = 1; // feed the watchdog
WDTCONbits.ON = 1; // enable the watchdog
TRISAbits.TRISA0 = 0; //output on RA0
ANSELAbits.ANSA0 = 0; // digital only
LED = 1; //led on
int i = 100000;
while(i--);
LED = 0; // led off
while(1); // hang up and let WDT reset us
return 0;
}
¿Qué parte del uso exitoso del WDT me estoy perdiendo?
Después de indagar un poco más, creo que encontré la respuesta. De acuerdo con este documento , el WDTCONbits.WDTPS
registro es solo una copia oculta de los bits del escalador posterior. Para configurar el escalador posterior, tuve que agregarlo en mi archivo principal #pragma config WDTPS = PS512
. Mi código exitoso ahora dice:
#define LED _LATA0
#pragma config WDTPS = PS512 // this is the magic line
/*
*
*/
int main(int argc, char** argv) {
//WDTCONbits.WDTPS = 0b1001; //512ms postscaler
WDTCONbits.WDTCLR = 1; // feed the watchdog
WDTCONbits.ON = 1; // enable the watchdog
TRISAbits.TRISA0 = 0; //output on RA0
ANSELAbits.ANSA0 = 0; // digital only
LED = 1; //led on
int i = 100000;
while(i--);
LED = 0; // led off
while(1); // hang up and let WDT reset us
return 0;
}