I enabled the watchdog timer, and set the Postscaler to 1:256
If I don't reset the timer "WDTCLR_bit = 1;", then the microcontroller resets every 256 milliseconds, which is expected...
If I use "WDTCLR_bit = 1;", when it's reaching that line of code, instead of clearing the watchdog timer, it resets the microcontroller. I have delays in my code, in total of 110 milliseconds, and then I set the WDTCLR_bit = 1; and that's exactly when the microcontroller resets.
Here is the code I am using (I removed some of the code that is not relevant to my problem), but I zipped the full project and attached it:
Code: Select all
#define DEBUG1 LATB.F15
#define DEBUG5 LATG.F6
void Config(){
AD1PCFG = 0b1111111111111011;
// 5432109876543210
DDPCON.JTAGEN = 0;
LATB = 0;
TRISB = 0b0000000000000100;
// 5432109876543210
DEBUG1 = 1;
LATD = 0;
TRISD = 0b0000111100000000;
// 5432109876543210
LATE = 0;
TRISE = 0b11111111;
// 76543210
LATF = 0;
TRISF = 0;
LATG = 0;
TRISG = 0b10000000;
INTCON.B12 = 1; //Set for multivector
INT1IE_bit = 0; //Clear interupt state
INT1IF_bit = 0; //Set interupt for falling edge i.e button release
INT1EP_bit = 1; //Set to 1 for rising edge i.e button press
INT2IE_bit = 0; //Clear interupt state
INT2IF_bit = 0; //Set interupt for falling edge i.e button release
INT2EP_bit = 1; //Set to 1 for rising edge i.e button press
TMR1 = 0; // reset timer value to zero
PR1 = 20000; // Load period register
T1IP0_bit = 0; // set interrupt
T1IP1_bit = 1; // priority
T1IP2_bit = 1; // to 6
TCKPS0_bit = 1; // Set Timer Input Clock
TCKPS1_bit = 0; // Prescale value to 1:256
EnableInterrupts();
INT1IP0_bit = 1;
INT1IP1_bit = 1;
INT1IP2_bit = 1;
INT2IP0_bit = 1;
INT2IP1_bit = 1;
INT2IP2_bit = 1;
INT1IE_bit = 1;
INT2IE_bit = 1;
T1IE_bit = 1; // Enable Timer1 Interrupt
}
void main() {
Config();
delay_ms(10);
DEBUG1 = 0;
delay_ms(100);
do {
WDTCLR_bit = 1; // ***** the microcontroller resets here !!!!!!!!!!!!
if (UART3_Data_Ready()) {
uart_rd = UART3_Read();
if(uart_rd == 'A'){
DEBUG5 = 1;
delay_ms(2);
DEBUG5 = 0;
}
}
} while(1);
}