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 CCS Technical Support

WDT doesn't work

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



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

WDT doesn't work
PostPosted: Tue Aug 17, 2010 4:23 am     Reply with quote

Hi,

Everything works fine but when I start WDT program crashes. I've placed some of my code which is related to WDT. Pls offer me a solution.


Last edited by koray_duran on Thu Dec 23, 2010 3:51 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 4:45 am     Reply with quote

The default timeout for the WDT, is approx (very approx....), 18mSec. This is what you have selected.
Your device_init code, sits in a delay for 500mSec, without restarting the WDT. What will happen....
Two choices:
1) Select a WDT timeout that is longer than your longest delay (#fuses)
2) Tell the compiler to add code to restart the WDT, when in delays (look at the clock settings in the manual).

Remember to use the _worst case_ watchdog times in each case (7mSec), if you want the code to be reliable on different chips.

Best Wishes
koray_duran



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 5:17 am     Reply with quote

Thanks for reply Ttelmah.

If you'll get a look to my code again you'll see "setup_WDT(WDT_2304MS);" in device initialization. That should be enough or I do something wrong ?
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 17, 2010 7:08 am     Reply with quote

This:

Code:

setup_timer_2(T2_DIV_BY_16, 499, 1);

Timer2 is 8 bits. I don't know what happens if you set it to 499, but it certainly doesn't help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 5:11 pm     Reply with quote

You didn't post your whole program (and I don't want you to), but there
are other ways for the compiler's built-in functions to sit in a loop until
the WDT resets the PIC. The CCS manual says this:
Quote:

RESTART_WDT

When specified in #use delay, #use I2c and #use RS232 statements like
this #use delay(clock=20000000, restart_wdt) will cause the wdt to
restart if it times out during the delay or I2C_READ or GETC.

My guess is that you have a getc() or fgetc() statement in your code
and that's where it's timing out.

You can restart the WDT in the CCS library code by adding the values
shown in bold below, and if you have a #use i2c() statement, then add it
there as well.
Quote:

#use delay(clock=20M, restart_wdt)
#use rs232(baud=2400,xmit=PIN_C6,rcv=PIN_C7,stream=RS, restart_wdt)
koray_duran



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 2:07 am     Reply with quote

Thanks PCM Promgrammer. I've changed my code as below but still have the same problem. Program doesn't start.

Last edited by koray_duran on Thu Dec 23, 2010 3:52 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 9:23 am     Reply with quote

INT_RDA, will be a problem.
You get an RDA interrupt, when _one_ character is waiting to be read. There can potentially be up to 1.99 characters, but never two. Your code is trying to read two characters in the interrupt, and _will_ hang till the second arrives. Instant WDT.

Best Wishes
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Aug 18, 2010 2:21 pm     Reply with quote

Why anyone would try to read two chars in a one char at a time interrupt is a puzzle. Anyway Ttelmah has you pointed in the right direction.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 4:07 pm     Reply with quote

Douglas Kennedy wrote:
Why anyone would try to read two chars in a one char at a time interrupt is a puzzle. Anyway Ttelmah has you pointed in the right direction.


Cause the UART has a multi-byte FIFO and they wrote the ISR to clear the FIFO at the "high water mark" that caused the interrupt?

Hahahha.. I know. NOT THIS PIC.

(I did that on a PIC24F series that had a 4byte FIFO)

:D

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
koray_duran



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 1:21 am     Reply with quote

Thanks guys for replying. This morning i find out that when deactive line
Code:

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
   enable_interrupts(INT_RTCC);


WDT starts to work fine. What can be the reason ?
There is nothing related to wdt in rtcc codes.
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 1:55 am     Reply with quote

Oh yes there is.....
Look at the timer0 section in the data sheet.
Look at figure 5-1.
Note how the prescaler is shared between timer0, and the watchdog.

Best Wishes
koray_duran



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

PostPosted: Fri Aug 20, 2010 2:14 am     Reply with quote

Thanks Ttelmah. I will search and write the results here. 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