View previous topic :: View next topic |
Author |
Message |
koray_duran
Joined: 04 Feb 2010 Posts: 37
|
WDT doesn't work |
Posted: Tue Aug 17, 2010 4:23 am |
|
|
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: 19515
|
|
Posted: Tue Aug 17, 2010 4:45 am |
|
|
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
|
|
Posted: Tue Aug 17, 2010 5:17 am |
|
|
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
|
|
Posted: Tue Aug 17, 2010 7:08 am |
|
|
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
|
|
Posted: Tue Aug 17, 2010 5:11 pm |
|
|
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
|
|
Posted: Wed Aug 18, 2010 2:07 am |
|
|
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: 19515
|
|
Posted: Wed Aug 18, 2010 9:23 am |
|
|
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
|
|
Posted: Wed Aug 18, 2010 2:21 pm |
|
|
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
|
|
Posted: Wed Aug 18, 2010 4:07 pm |
|
|
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
|
|
Posted: Thu Aug 19, 2010 1:21 am |
|
|
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: 19515
|
|
Posted: Thu Aug 19, 2010 1:55 am |
|
|
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
|
|
Posted: Fri Aug 20, 2010 2:14 am |
|
|
Thanks Ttelmah. I will search and write the results here. |
|
|
|