WDTCLR_bit = 1; resets the microcontroller

General discussion on mikroC PRO for PIC32.
Author
Message
CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

WDTCLR_bit = 1; resets the microcontroller

#1 Post by CVMichael » 06 Oct 2012 03:07

I am using PIC32MX795F512H @80MHz

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);
}
Attachments
Robot_Drive.zip
(137.14 KiB) Downloaded 418 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: WDTCLR_bit = 1; resets the microcontroller

#2 Post by janko.kaljevic » 08 Oct 2012 17:11

Hello,

I was not able to reproduce this behavior.
I tested it on L version of the chip (100 pin), and if WDT was cleared in while loop, there were no resets at all.
Everything worked just fine as expected.

Is there anything else that I could use for test?

Best regards.

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#3 Post by CVMichael » 09 Oct 2012 04:19

I am not sure what else to give you... maybe you can give me the test code you used (if different than mine)?

Did I miss something in the setup/config?

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: WDTCLR_bit = 1; resets the microcontroller

#4 Post by janko.kaljevic » 09 Oct 2012 07:57

Hello,

I used your project and only changed the microcontroller to PIC32M795F512L.
But is should behave the same.

Please try to check again your config bits. I used our default with WDT enabled.

Best regards.

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#5 Post by CVMichael » 10 Oct 2012 02:35

I've been trying to get it to work for hours, and still nothing...

It looks like I am not the only one with the same problem, see the last post: http://www.mikroe.com/forum/viewtopic.php?f=168&t=38695

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: WDTCLR_bit = 1; resets the microcontroller

#6 Post by janko.kaljevic » 10 Oct 2012 12:53

Hello,

In the attachment is simple code as demonstration.
I have tested it on PIC32MX795F512L.

When I do not clear WDT, controller will always reset.
But if I do WDTCLR_bit = 1; in while loop controller will not reset, which can be clearly seen on PORTD.

My test configuration mirkoC PRO for PIC32 v2.40, EasyPIC Fusion, and PIC32MX795F512L revision 3.

Best regards.
Attachments
WDT.rar
(151.33 KiB) Downloaded 609 times

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#7 Post by CVMichael » 11 Oct 2012 01:46

I tried your code, but I still have the same problem.

When "WDTCLR_bit = 1;" is used, the PIC resets every 100ms, PORTD is off for only 50us (while the PIC resets)

When "WDTCLR_bit = 1;" is removed, PORTD is ON for 100ms, then off until it resets at the timeout of 255ms (this is normal).

I looked at the "Silicon Errata and Data Sheet Clarification": http://ww1.microchip.com/downloads/en/D ... 80480L.pdf , at #22 it says "Use WDT periods equal to or longer than 128 ms.", but I've been using 256ms timeout, and I still have this problem.

Anyways... I'm giving up on this.
Attachments
No "WDTCLR_bit = 1;"
No "WDTCLR_bit = 1;"
WDT_2.png (115.19 KiB) Viewed 18465 times
With "WDTCLR_bit = 1;", it resets
With "WDTCLR_bit = 1;", it resets
WDT_1.png (135.37 KiB) Viewed 18465 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: WDTCLR_bit = 1; resets the microcontroller

#8 Post by janko.kaljevic » 11 Oct 2012 10:35

Hello,

You should not be affected with this silicon bug.
But have you tried to use different WDT postscaler?

Also which silicon revision of the chip do you use, and have you tried another controller?

Best regards.

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#9 Post by CVMichael » 11 Oct 2012 14:22

janko.kaljevic wrote:Also which silicon revision of the chip do you use, and have you tried another controller?
How can I find out what revision it is? is this the number that shows when I connect the MPLAB ICD 3 to the PIC in the MPLAB IDE?

What do you mean another controller? I think you are referring to the PCB board?
I made my own PCB. I posted on this forum pictures & schematic of my board:
Pictures: http://forum.allaboutcircuits.com/showp ... stcount=43
and schematics: http://forum.allaboutcircuits.com/showp ... stcount=45

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

Re: WDTCLR_bit = 1; resets the microcontroller

#10 Post by Mince-n-Tatties » 11 Oct 2012 19:52

CVMichael wrote:I connect the MPLAB ICD 3 to the PIC in the MPLAB IDE?
this could be the main difference, you are using MPLAB with ICD3 and janko will be using mikroE kit. i would make sure the config settings are correct in MPLAB and run in release mode just in case debug mode is introducing a delay.
Best Regards

Mince

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#11 Post by CVMichael » 11 Oct 2012 20:00

Mince-n-Tatties wrote:I would make sure the config settings are correct in MPLAB
I don't even know how to set config settings in MPLAB?

Do the config settings in MPLAB override the seetings in the mikroC compiler?

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

Re: WDTCLR_bit = 1; resets the microcontroller

#12 Post by CVMichael » 11 Oct 2012 23:29

janko.kaljevic wrote:Also which silicon revision of the chip do you use, and have you tried another controller?
When I connect the ICD 3 to the microcontroller, this is what the MPLAB IDE shows:

Target Detected
Device ID Revision = 34300053

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: WDTCLR_bit = 1; resets the microcontroller

#13 Post by janko.kaljevic » 12 Oct 2012 09:06

Hello,

Config bits set up are implemented in hex file and they should be set in MPLAB as soon as you import the hex.

You can check explanation how to see silicon revision of the controller in following document:
http://ww1.microchip.com/downloads/en/D ... 80480L.pdf

Best regards.

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

Re: WDTCLR_bit = 1; resets the microcontroller

#14 Post by Mince-n-Tatties » 12 Oct 2012 11:27

is this what you expect the config bit to be set as?
config.png
config.png (25.96 KiB) Viewed 18426 times
Best Regards

Mince

Wildza
Posts: 1
Joined: 19 Oct 2012 05:46

Re: WDTCLR_bit = 1; resets the microcontroller

#15 Post by Wildza » 19 Oct 2012 06:10

I came up with exactly the same issue using the PIC32MX320F128H. The moment my code hit WDTCLR_bit = 1, the processor reset. I eventually traced the issue. The PIC32's (most if not all, I think) have a feature called 'Windowed Watchdog', which is a fancy feature that will only allow you to kick the dog while you are in a specified 'Allowed' reset window (which is near the expiry of the WDT timer), if you kick the dog outside this window, the processor resets immediately. Now here is where it get interesting, the Microchip Family reference documentation goes to great lengths to describe this feature and make mention that the 'windowed' feature can be turned off by a setting in the device configuration bits, but when looking at the device configuration bits in the actual part data sheet, they make no mention of how to do this. I eventually tracked down the bit, its located at 0x1FC0_2FF8 bit 22. If this bit is set the 'windowed' feature is disabled and the WDT can be kicked at any time, if the bit is cleared, the WDT can only be kicked in the so called 'Allowed Window', any kick outside this window and the processor resets. MikroC Pro V2.4 does not give you the option in the 'Edit Project' to set or clear this bit for Windowed or Standard type watchdog, so after a compile, this bit is cleared and the processor is running in Windowed mode. If however you look closely at mikroProg Suite for PIC when you program the part, you will see there is an option in the configuration settings 'Windowed Watchdog Timer' where you can now enable and disable this feature. This is however very painful as you have to explicitly turn off the windowed watchdog every time you compile to debug. Interestingly enough, the latest Mplab V8.87 and MPLABX do not even show this bit as an option when going to configuration settings box, which leads me to believe that this bit is undocumented and should be left set and never cleared as the MikroC compilers does by default.

Post Reply

Return to “mikroC PRO for PIC32 General”