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

Re: WDTCLR_bit = 1; resets the microcontroller

#16 Post by CVMichael » 22 Oct 2012 02:11

Thanks for the info Wildza

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

Re: WDTCLR_bit = 1; resets the microcontroller

#17 Post by janko.kaljevic » 22 Oct 2012 16:15

Hello,

Thanks for the valuable input Wildza.
I have tested this more further and i was able to reproduce this issue.
But if you check more carefully config bits definitions in device datasheet:
http://ww1.microchip.com/downloads/en/D ... 61143H.pdf
you will see that FWDTWINEN is not defined. Also if you check config bit set up from the MPLAB for your controller, you can see that there is no such config bit.
(Take a look at Mince's previous post).

But after all I can confirm that when you disable Windowed Watch Dog in mirkoProg Suite you will get expected result. (procedure that Wildza described)
Also I was not able to disable Windowed Watch Dog from software, and in device datasheet there is no description of WDTWINEN bit in WDTCON register.
So at the moment the only way to disable it is as Wildza recommended.

This matter requires more investigation and we will work on it.

Best regards.

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

Re: WDTCLR_bit = 1; resets the microcontroller

#18 Post by Mince-n-Tatties » 24 Oct 2012 22:47

janko.kaljevic wrote: Thanks for the valuable input Wildza.
awesome detective work, Wildza.
janko.kaljevic wrote: Also I was not able to disable Windowed Watch Dog from software, and in device data
So at the moment the only way to disable it is as Wildza recommended.
easy solved if mikroE would just implement "in code" config setup as a user option.

i.e. __config 1FC0_2FF8: 00 C8 C6 A3

or perhaps the ability to be able to edit the device configuration table in Edit Project. use the drop downs to get the majority of the config done, then have a radio button to switch to user edit mode and make the bit change directly on the hex value. This would at least be a start point.
Best Regards

Mince

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

Re: WDTCLR_bit = 1; resets the microcontroller

#19 Post by janko.kaljevic » 25 Oct 2012 10:05

Hello,

Yes, this was discussed here on forum, and we are definitely considering it, and it is on our wish list.

When Windowed Watchdog is enabled, user should be able to turn it on/off from code.
But I was not able to do it, and lack of information in datasheet was not helpful.

So the only way to disable it is setting appropriate config bit.

Best regards.

bartt
Posts: 156
Joined: 20 Jul 2012 18:52
Location: Left coast

Re: WDTCLR_bit = 1; resets the microcontroller

#20 Post by bartt » 15 Jan 2013 00:17

Wow that is a nice find for a potentially nasty problem. I did a bit of research on it and have a solution for us..

You can also fix this problem by adding a couple of lines to the p32mx795f512L.c file. In the section under WDTCON add this:

Code: Select all

    const register unsigned short int WDTWINEN = 1;
    sbit  WDTWINEN_bit at WDTCON.B1;               // added to control windowed WDT
I put it just above WDTCLR_bit so it looks like this..

Code: Select all

    const register unsigned short int SWDTPS0 = 2;
    sbit  SWDTPS0_bit at WDTCON.B2;
    const register unsigned short int WDTWINEN = 1;
    sbit  WDTWINEN_bit at WDTCON.B1;               // added to control windowed WDT
    const register unsigned short int WDTCLR = 0;
    sbit  WDTCLR_bit at WDTCON.B0;
save that file..
Now in your code you can to this at the top of your main():

Code: Select all

   AD1PCFG = 0xFFFF; // Configure AN pins as digital I/O
   MVEC_bit = 1;     // turn on multivectored interrupts.
   WDTWINEN_bit = 0; // turn off windowing of Watchdog timer to reset it at any time
   CLEAR_WATCHDOG;    // clear the watchdog timer..
   WATCHDOG_OFF;       // turn off the watchdog until we are ready to start it..


Another note - I have some macros that help in a header file:

Code: Select all

#define CLEAR_WATCHDOG  WDTCLR_bit = 1   // clear the watchdog timer..
#define WATCHDOG_OFF    ON_bit = 0
#define WATCHDOG_ON     ON_bit = 1
This all compiles clean for me, so if there is anything wrong with it, someone please let me know..
Hope it helps.

zorgcorp
Posts: 110
Joined: 28 Mar 2011 10:17

Re: WDTCLR_bit = 1; resets the microcontroller

#21 Post by zorgcorp » 29 Aug 2013 15:34

Dear Bartt,
I still have trouble to make the watchdog clear as my code is constantly rebooting.

I have done exactly what you mentioned in your post regarding adding in the P32MX695F512H.c this:

const register unsigned short int SWDTPS0 = 2;
sbit SWDTPS0_bit at WDTCON.B2;
const register unsigned short int WDTWINEN = 1;
sbit WDTWINEN_bit at WDTCON.B1; // added to control windowed WDT
const register unsigned short int WDTCLR = 0;
sbit WDTCLR_bit at WDTCON.B0;

then I created a simple project which turn two leds on F0 and F1 on and off two times, then I clear the watchdog inside a while loop.

I tried everything using
WDTWINEN_bit = 0;
or
WDTWINEN_bit = 1;

along with

WDTCLR_bit = 1;
or
WDTCLR_bit = 0;

Please try the attached project and help me find out what is wrong with the windowed watchdog.
If the wdt and its clearing was working the leds should blink two time and stay on for ever....

PS: I do not, because I can not, use the mikroProg Suite (where you can turn off windowed wdt) because my electronic is not implemented with it, I use MPLAB and PIC-Kit3 instead.

Thansk for your help, best regards
Alex
Attachments
WDT problem.zip
(39.79 KiB) Downloaded 276 times

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: WDTCLR_bit = 1; resets the microcontroller

#22 Post by dejan.odabasic » 12 Dec 2013 14:44

Hello,

Please refer to MCU datasheet for details regarding WDT.
As far as I could see in PIC32MX5XX/6XX/7XX documentation, there is no details regarding windowed WDT.

Best regards.

sunjun
Posts: 5
Joined: 15 Nov 2010 11:23

Re: WDTCLR_bit = 1; resets the microcontroller

#23 Post by sunjun » 16 May 2014 10:28

dejan.odabasic wrote:Hello,

Please refer to MCU datasheet for details regarding WDT.
As far as I could see in PIC32MX5XX/6XX/7XX documentation, there is no details regarding windowed WDT.

Best regards.
We are using PIC32MX460F512L and we have exactly the same problem.

No mentioning of windowed WDT mode in datasheet.

"WDTCLR_bit = 1;" just resets the processor - it is not restarting the timeout counter of the watchdog!


Does anyone have updates on this?

User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: WDTCLR_bit = 1; resets the microcontroller

#24 Post by petar.timotijevic » 20 May 2014 07:37

Hi,

@sunjun

Which compiler version you have?


Best regards,
Peter

sunjun
Posts: 5
Joined: 15 Nov 2010 11:23

Re: WDTCLR_bit = 1; resets the microcontroller

#25 Post by sunjun » 28 May 2014 07:51

petar.timotijevic wrote:Hi,
@sunjun
Which compiler version you have?
Sorry, @petar.timotijevic, I have totally missed the reply!

The compiler is the latest MikroC for PIC32 v.3.3.3.

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: WDTCLR_bit = 1; resets the microcontroller

#26 Post by phil31 » 30 Jan 2016 22:06

sunjun wrote:
dejan.odabasic wrote:Hello,

Please refer to MCU datasheet for details regarding WDT.
As far as I could see in PIC32MX5XX/6XX/7XX documentation, there is no details regarding windowed WDT.

Best regards.
We are using PIC32MX460F512L and we have exactly the same problem.

No mentioning of windowed WDT mode in datasheet.

"WDTCLR_bit = 1;" just resets the processor - it is not restarting the timeout counter of the watchdog!


Does anyone have updates on this?

Dear all,
2 years later and the WDTWINEN bit of WDTCON is even not implemented for PIC32MX675F512H at least (don't check for others parts) (MBPRO PIC32 v3.6.0)
and if you check this thread, ME team know this from 3 years now :
https://www.mikroe.com/forum/viewtopic. ... 64&t=55199


anyway, i try to clear it directly by WDTCON.1 = 0 and unfortunately was not able to correctly work with the watchdog in non windowed mode ..
so as soon of my main try to clear watchdog timer, then a reset occurs

please anybody can show me how to switch off this windowed watchdog feature ?

thanks, regards

serge87
Posts: 45
Joined: 12 Sep 2012 17:55

Re: WDTCLR_bit = 1; resets the microcontroller

#27 Post by serge87 » 03 Feb 2016 10:31

I've got the same problem with watchdog.
After scouring the forum and the net I've tried the "Mikroprog Suite" (I do not have an ME programmer).
I've started the "mE programmer" from tools, I've loaded the hex file in it and then re-save it to the disk, after that I programmed it with PICKIT3 to the uC and the problem was gone.
I have noticed a difference in the config codes form the hex files.
The compiler treat the config variables as cleared when they are loaded with zeroes and adjust them afterwards, but the Mikroprog treat them as cleared when they are loaded with $FFFFFFFF (ones) and do the same modification.
From the device datasheet in the configuration words section we see that the "reserved" bits should be set as "1" not as "0"
Extract from the datasheet, notice the red lines:
bit 31-19 Reserved: Write ‘1’
bit 18-16 FPLLODIV<2:0>: PLL Output Divider bits
111 = PLL output divided by 256
110 = PLL output divided by 64
101 = PLL output divided by 32
100 = PLL output divided by 16
011 = PLL output divided by 8
010 = PLL output divided by 4
001 = PLL output divided by 2
000 = PLL output divided by 1
bit 15 UPLLEN: USB PLL Enable bit
1 = Disable and bypass USB PLL
0 = Enable USB PLL
bit 14-11 Reserved: Write ‘1’
bit 10-8 UPLLIDIV<2:0>: USB PLL Input Divider bits
111 = 12x divider
110 = 10x divider
101 = 6x divider
100 = 5x divider
011 = 4x divider
010 = 3x divider
010 = 3x divider
001 = 2x divider
000 = 1x divider
bit 7 Reserved: Write ‘1’
bit 6-4 FPLLMUL<2:0>: PLL Multiplier bits
111 = 24x multiplier
110 = 21x multiplier
101 = 20x multiplier
100 = 19x multiplier
011 = 18x multiplier
010 = 17x multiplier
001 = 16x multiplier
000 = 15x multiplier
bit 3 Reserved: Write ‘1’
So from this it seems that the Mikroprog does the correct thing with the config words, not the compiler.
I encourage ME team to look in to this, as it is some nasty bug witch can cause the users to spend a lot of time trying to circumvent it.
Thank you.

P.S. I have Mikrobasic and PIC32MX795F512H and programmer is PICKIT3 & mplab IPE.
Just tell me....

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: WDTCLR_bit = 1; resets the microcontroller

#28 Post by phil31 » 03 Feb 2016 14:27

Hello Serge

well, my CPU target is 32MX675F512H.
when i compile the application and upload it with my mikroprog, it is NOT working at all .. no start up !
but when i program the same HEX file with my ICD3 programmer, the wall application work as expected (of course, with watchdog disable)

i already open a ticket about this programmer problem with mikroprog .. open since maybe 1 year .. no news from ME about that issue .......

i will have a look about the CONFIG reg when i load it in ICD3 or in mikroprog, to see if there is any differences ..

the datasheet for the 6xx is not really clear about the WDTCON register .. sometime they mention about the bit1, sometime, the case is grey (which indicate unused bit ) ...

thanks for you reply, regards

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: WDTCLR_bit = 1; resets the microcontroller

#29 Post by phil31 » 04 Feb 2016 22:28

Hello

well you right about the mikroprog CONFIG reg modification !

when i load the HEX file to mikroprog and save it back, the CONFIG regs are modified as you describe.
if i program with mikroprog this "new saved" hex file, then again, nothing start
but if i program this new saved file with ICD3, then all work as expected, included watchdog feature !

I thought that the watchdog problem coming from a bad configuration of my application.. or a problem with the windowed watchdog feature..
but it seem that the 32MX675F512H don't have this feature ... not totally clear from the datasheet about the 6XX family !

definitely another issue with compiler and/or programmer ...

thanks for your tips ! :D
will open again a ticket ..

regards

serge87
Posts: 45
Joined: 12 Sep 2012 17:55

Re: WDTCLR_bit = 1; resets the microcontroller

#30 Post by serge87 » 06 Feb 2016 17:53

Hello,
I'm glad that your program worked.
In my opinion the fault is split between Micrchip and MikroE.
The Microchip fault is that their datasheets and/or errata are not clear enough.
On the other hand the MikroE fault is that they don't use the same principles throughout their program (witch in this case is a workaround for the problems).
phil31 wrote:I thought that the watchdog problem coming from a bad configuration of my application.. or a problem with the windowed watchdog feature..
but it seem that the 32MX675F512H don't have this feature ... not totally clear from the datasheet about the 6XX family !
My uC doesn't have this feature either, but it seems that, in my opinion, Microchip at some point had it in this chips but decided to remove it just on paper, not on the actual chips, or is just an oversight from the chip development.

Regards.
Just tell me....

Post Reply

Return to “mikroC PRO for PIC32 General”