![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jinmoon
Joined: 05 Dec 2012 Posts: 3
|
Watchdog with 18F26J50 |
Posted: Wed Dec 05, 2012 11:09 pm |
|
|
Hi, I'm trying to figure out how the watchdog works.. Below's the full code. I set NOWDT for software control. It never comes out of sleep()... What can be possibly wrong? The compiler version is 4.128. I'm looking at PIN_A1 with an oscilloscope with nothing else connected.
Code: |
#include "18F26J50.h"
#fuses NOWDT, PLL1, NOSTVREN, NOXINST, NODEBUG
#fuses NOCPUDIV, NOPROTECT
#fuses INTRC_IO, NOT1DIG, NOLPT1OSC, NOFCMEN, NOIESO
#fuses WDT64
#fuses DSWDTOSC_INT, RTCOSC_INT, NODSBOR, NODSWDT, DSWDT2
#fuses NOIOL1WAY, MSSPMSK5
#fuses NOWPFP, WPEND, NOWPCFG
#fuses WPDIS
#use delay(clock=4000000, restart_wdt)
void main() {
setup_wdt(WDT_ON);
while(TRUE) {
sleep();
setup_wdt(WDT_OFF);
output_bit(PIN_A1, 1);
delay_ms(400);
output_bit(PIN_A1, 0);
delay_ms(400);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Thu Dec 06, 2012 2:29 am |
|
|
OK.
It's doing what it should.
Key is that you are going fully asleep. This includes stopping the low power oscillator, so the watchdog will also stop. You can wake from this with an external trigger (so external interrupt etc.).
You need to look at the sleep options in the include file for the processor. Note that the default is 'SLEEP_FULL'.
Now look at the data sheet, section 4.4 'Idle Modes'.
So, you have choices. User the idle mode, and keep the standard watchdog running. Use deep sleep, and use the optional deep sleep watchdog.
Easiest is just to use:
sleep(SLEEP_IDLE);
this will leave the peripheral clock running.
You can also use 'WAKE_FROM_RTCC', which will also leave the watchdog running, if the timer1 oscillator is not enabled (your's isn't).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
jinmoon
Joined: 05 Dec 2012 Posts: 3
|
|
Posted: Thu Dec 06, 2012 8:44 am |
|
|
Thanks Ttelmah,
I tried sleep(SLEEP_IDLE), and it's not still working. When using '#fuse INTRC', I could see on the scope that the main clock is still running even after sleep(), but still stuck at sleep (not executing the next codes). No go for 'WAKE_FROM_RTCC' either.
I also checked the LST file that NODEBUG is correctly applied.
And when I checked the manual, I found this. The watchdog is supposed to be running on INTRC, the 31kHz oscillator. Isn't it?
Quote: |
The main output (INTOSC) is an 8 MHz clock source
which can be used to directly drive the device clock. It
also drives the INTOSC postscaler which can provide a
range of clock frequencies from 31 kHz to 8 MHz.
Additionally, the INTOSC may be used in conjunction
with the PLL to generate clock frequencies up to
48 MHz.
The other clock source is the internal RC oscillator
(INTRC) which provides a nominal 31 kHz output.
INTRC is enabled if it is selected as the device clock
source. It is also enabled automatically when any of the
following are enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed Start-up
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Thu Dec 06, 2012 9:34 am |
|
|
Yes.
Seen people having problems with this before. It seems that sometimes the INTRC does not run, though the data sheet says it should. Selecting something else that should keep it running normally solves the problem....
I have tried in the past switching the CPU to run off this clock, and it then worked....
What compiler version are you on?. Will check that it is enabling the watchdog.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
jinmoon
Joined: 05 Dec 2012 Posts: 3
|
|
Posted: Thu Dec 06, 2012 9:59 am |
|
|
I have two code versions, both of which should be functioning identical.
The first one is using 'WDT', and the second one is using 'NOWDT' and controlling the WDT with software. The first one works, and the second one does not.
I think it's CCS' fault? maybe assigning weird values to the WDTCON register?
Code: |
#include "18F26J50.h"
#fuses WDT, WDT128, NODEBUG, INTRC_IO
#use delay(clock=4000000, restart_wdt)
void main() {
while(TRUE) {
output_bit(PIN_A1, 1);
sleep();
output_bit(PIN_A1, 0);
sleep();
}
}
|
The above code works with 4ms*128 = 512ms high/low duration.
Code: |
#include "18F26J50.h"
#fuses NOWDT, WDT128, NODEBUG, INTRC_IO
#use delay(clock=4000000, restart_wdt)
void main() {
while(TRUE) {
output_bit(PIN_A1, 1);
setup_wdt(WDT_ON);
restart_wdt();
sleep();
setup_wdt(WDT_OFF);
output_bit(PIN_A1, 0);
setup_wdt(WDT_ON);
restart_wdt();
sleep();
setup_wdt(WDT_OFF);
}
}
|
The above code does not work. It doesn't get out of the first sleep().
The compiler version is 4.128. I'm looking at PIN_A1 with an oscilloscope with nothing else connected. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|