CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

INT_EXT1 causing a watchdog restart

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

INT_EXT1 causing a watchdog restart
PostPosted: Fri Apr 27, 2018 10:21 am     Reply with quote

Hi fellow Programmers:
I am new to using the dsPic33FJ128GP708A. I have an External RTC hooked to the EXT1 input with a 10k pullup to 3.3 volts. It outputs a 1Hz square wave. If the interrupts are enabled or the External clock is turned on the program does a watchdog reset. When I try to print a float value.
Fuses are as follows:
Code:

#include <33FJ128GP708A.h>
#device ICSP=1
#device ADC=12


#FUSES HS                       //HIGH SPEED CRYSTAL
#FUSES WDT                      //Watch Dog Timer
#fuses NOWRTB           //Boot block not write protected
#fuses NOBSS          //No boot segment
#fuses NORBS          //No Boot RAM defined
#FUSES NOSSS                    //NO SECURE SEGMENT
#fuses NORSS          //No secure segment RAM
#fuses NOWRT          //Program memory not write protected
#fuses NOPROTECT      //Code not protected from reading
#fuses IESO           //Internal External Switch Over mode enabled
#fuses PUT16          //Power On Reset Timer value 16ms
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled
#FUSES NODEBUG                    //NODEBUG WITH ICD
#FUSES NORBS                    //NO BOOT RAM DEFINED
#fuses PR             //Primary Oscillator
#FUSES SOSC                      //SECONDARY OSC
#fuses ICSP1          //ICD uses PGC1/PGD1 pins
#fuses LPRC           //Internal low power RC Oscillator

#use delay(xtal=14.745M,restart_wdt)

#define DELAY 100

I have
Code:

setup_wdt(WDT_1S|WDT_ON);
ext_int_edge(1,H_TO_L);

in my initialization

I removed all the code used when the interrupt fires.
Code:
#INT_EXT1 //external RTC Clock
void clock_functions()
    {
  restart_wdt();
}


The other interrupts TIMER1 and TIMER4 work correctly.
Any Ideas?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 10:43 am     Reply with quote

My guess...

Most PICs have several values that can be assigned to the WDT to timeout but I don't see one in your FUSEs listing.
It could be the default is very short (fast) and the print command (especially for a float) is tripping the WDT.

I don't use that PIC, so I don't know what the CCS defaults are...
BTW I like to 'group' FUSEs based on purpose. It this case the WDT 'time value' would be next after the WDT fuse.

Jay
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 11:17 am     Reply with quote

What do you have your stack size set to?
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 27, 2018 11:17 am     Reply with quote

Added these and still the same problem. Thanks for the idea.
Code:

#FUSES WPRES32                  //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS11                 //Watch Dog Timer PostScalar 1:1024
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 1:21 pm     Reply with quote

You have no margin at all.

1 second timeout selected, and a 1 second pulse interval. If the watchdog is even 0.0001% fast, it'll trigger. You need some safety margin. Set the watchdog to timeout after 2 seconds.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 2:18 pm     Reply with quote

As a general comment, a WDT is normally never ever used (enabled) until 100% of the code is working, THEN you can determine the 'worst case' time and decide how long to set the WDT for. As MR. T says , it should be a minimum of 2X the time you decide.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 2:34 pm     Reply with quote

It's also worth understanding that a watchdog as you are currently doing it is useless....
The PIC can be doing things it is not meant to be doing, but because the interrupt triggers the watchdog will be reset.

A watchdog reset needs to be testing that every aspect of the code execution is correctly happening, and only reset the watchdog if this is the case. So every piece of code flow in the main routine, should set a flag whenever it happens. The timer can do the same, and only if all these flags are all set, then reset the watchdog. Designing a proper useful watchdog needs thought.
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 27, 2018 2:37 pm     Reply with quote

I changed the setup_wdt(WDT_1S|WDT_ON); to
setup_wdt(WDT_8ok lS|WDT_ON);

sadly, it did not help.. just delays longer between resetting.
asmallri



Joined: 12 Aug 2004
Posts: 1630
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Apr 27, 2018 2:54 pm     Reply with quote

You have not given enough code to help you identify the problem.

If your code is executing inside an interrupt handler (not the EXTN1 handler), then the EXTN1 interrupt will not be processed and therefore the WDT will not be reset.

Similarly, if one of other of your handlers calls a function that is also called by the mainline then the compiler will disable interrupts in the function. In this case, the EXTN1 interrupt will also not be processed.

As others have indicated, adding a WDT reset within the interrupt handler does not give a lot of value. I have had a few cases where the main code ran off into the never never but the interrupt handler continues to run normally. If this happens in your code the EXTN1 would happily reset the WDT but the application is still off with the fairies.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

Re: INT_EXT1 causing a watchdog restart
PostPosted: Fri Apr 27, 2018 7:24 pm     Reply with quote

David Pouzar wrote:
...If the interrupts are enabled or the External clock is turned on the program does a watchdog reset. When I try to print a float value...


You're using a dsPIC which requires the PCD compiler. The PCD compiler, by default, allocates a stack that is notoriously found to be too small, especially when using printf and/or floats.

So, once again, I humbly ask what you have set your stack to? If you have not specified a stack size, insert this after your #fuses:

Code:
#BUILD (stack=1024)


If that doesn't fix the issue, try 2048.
jeremiah



Joined: 20 Jul 2010
Posts: 1314

View user's profile Send private message

PostPosted: Sun Apr 29, 2018 4:48 pm     Reply with quote

do you have the fuse WINDIS enabled? Some chips require this fuse or if you call restart_wdt() when the window isn't active it will reset the chip

You want #fuses WINDIS if it is available for that chip. One of my coworkers mistakenly used NOWINDIS thinking the NO meant it was disabled but failed to read the double negative.
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 30, 2018 6:04 am     Reply with quote

Thank you all, I added a
#fuses WINDIS
#BUILD (stack=1024)
Then problem seems to be gone.. Thank you so much.

Now to search the forum for ways to figure out the length of my execution time, I guess I could setup of a timer and start it and then read its value within parts of the code. Unless there is a better way..? Here is a copy of my new improved main.h

Code:

#include <33FJ128GP708A.h>
#device ICSP=1
#device ADC=12


//#FUSES FRC                      //FAST RC OSCILLATOR
#FUSES HS                       //HIGH SPEED CRYSTAL
//#FUSES WDT                      //Watch Dog Timer
//#FUSES WPRES32                  //Watch Dog Timer PreScalar 1:32
//#FUSES WPOSTS11                 //Watch Dog Timer PostScalar 1:1024
#fuses NOWRTB           //Boot block not write protected
#fuses NOBSS          //No boot segment
#fuses NORBS          //No Boot RAM defined
#FUSES NOSSS                    //NO SECURE SEGMENT
#fuses NORSS          //No secure segment RAM
#fuses NOWRT          //Program memory not write protected
#fuses NOPROTECT      //Code not protected from reading
#fuses IESO           //Internal External Switch Over mode enabled
#fuses PUT16          //Power On Reset Timer value 16ms
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled
#FUSES NODEBUG                    //NODEBUG WITH ICD
#FUSES NORBS                    //NO BOOT RAM DEFINED
#fuses PR             //Primary Oscillator
#FUSES SOSC                      //SECONDARY OSC
#fuses ICSP1          //ICD uses PGC1/PGD1 pins
#fuses LPRC           //Internal low power RC Oscillator
#fuses WINDIS           //Watchdog Window Select
#BUILD (stack=1024)


#use delay(xtal=14.745M,restart_wdt)
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 30, 2018 7:04 am     Reply with quote

Yes, when Jeremiah posted this I went and checked, and the chip will be 'disabling' this by default (so selecting windowed mode). In this mode restart_wdt is _only_ accepted when it falls inside the selected time window. Otherwise it will be ignored and cause a reset....
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 30, 2018 8:13 am     Reply with quote

Ttelmah,
I just glad that there are people out there that can help me and are willing. It is so exciting to see stuff work. I thank you for your help also.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group