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

How to know why WDT is barking?

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



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

How to know why WDT is barking?
PostPosted: Sat Dec 16, 2017 6:58 pm     Reply with quote

There's any way to know what part of the code is making WDT to bark?

I know that the WDT is barking time to time but the code is too long.
There's any register that saves the last PC (Program Counter) before the WDT barks or something similar?
_________________
Electric Blue
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 16, 2017 11:36 pm     Reply with quote

You could put marker bytes in the code with putc() statements, using the
hardware UART. If possible, use a high baud rate such as 115200.

Start with your main loop as shown below. This will show the progression
of your program in the terminal window. See if it always restarts in the
same function.

If it does, then put marker bytes within that function. Or, just closely
look at the function.
Code:

void main(void)
{
print("\n\r\n\rStart: ");

while(TRUE)
  {
    putc('A');
    function1();

    putc('B');
    function2();
 
    putc('C');
    function3();

    putc('D');
    function4();
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Dec 17, 2017 1:07 am     Reply with quote

The other way is to use a marker.

Code:

int16 marker;
#define mark(x) bit_set(marker,x)

//Then at the start of your main
   if (restart_cause()==NORMAL_POWER_UP)
       marker=0;

   //At this point, 'marker' has the bits set you have marked
   //before the restart.

   mark(1);
   function1();

   mark(2);
   function2();
 
   mark(3);
   function3();
   
   mark(4);
   function4();



Critical thing to be careful of is the minima. On some (a lot) of the older PIC's the watchdog timeout is very inaccurate. If you have the watchdog set to (say) 1 second, and then have a half second delay, you instinctively think "can't trigger", but checking the data sheet the minimum time for the same setting may well be only perhaps 400mSec...
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

PostPosted: Sun Dec 17, 2017 1:58 pm     Reply with quote

Thanks for the ideas. Smile
_________________
Electric Blue
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

PostPosted: Mon Dec 18, 2017 11:48 am     Reply with quote

I just want to tell you that I found the bug.
It was a 8 bit variable that must be declared as 16bit variable so it can be compared against another 16bit variable.

Code:

char count=0;
long bytelimit=0x4000;

do
{

 count++;
}while(count<bytelimit) //<--count is 8bit and never going to be bigger than bytelimit.


The curse of copy&paste. Crying or Very sad
_________________
Electric Blue
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 18, 2017 4:32 pm     Reply with quote

Did the techniques that we gave you, help you to find the bug ?
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

PostPosted: Tue Dec 19, 2017 1:57 pm     Reply with quote

PCM programmer wrote:
Did the techniques that we gave you, help you to find the bug ?


The program uses both USARTs so I was thinking in to use USB instead but first I tried by just debugging and, since the WDT barks after 8 seconds, I just halt the debug when I see that the program get halt and check where the program get looping forever; and it works.

The marker at RAM level I'm not sure if works or not because after the WDT I have not clear if the GPRs are reset to 0 or keep the last value.
Also CCS compiler have some init code before the code reach the main and I have no 100% clear how it works.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Dec 19, 2017 2:12 pm     Reply with quote

Quote:

The marker at RAM level I'm not sure if works or not because after the WDT I have not clear if the GPRs are reset to 0 or keep the last value.
Also CCS compiler have some init code before the code reach the main and I have no 100% clear how it works.


Global variables, that are not 'static', are only initialised if the code says to do so (or you have zero RAM selected).
Static variables are zeroed.

So a global variable as I show will not be initialised.

In order to start it at zero, the routine I post will clear it if the chip has done a normal reset.

This is a very important behaviour, since it allows you to have variables that are initialised, but retain their value after a watchdog reset.
Very Happy

This potentially allows a chip to be programmed to 'carry on' with values set up as they were after a watchdog reset.
guy



Joined: 21 Oct 2005
Posts: 291

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

PostPosted: Sun Dec 24, 2017 3:26 am     Reply with quote

E_Blue wrote:
The program uses both USARTs

Just the other day I suggested to use PPS with an available pin, if you need an unplanned debug UART, assuming you have PPS on your chip.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Dec 24, 2017 3:44 am     Reply with quote

Remember also that for a debug transmit, a software UART is normally perfectly usable. Especially if you use a nice high rate, so that interrupts can be disabled for a moment while the character transmits. Smile
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