View previous topic :: View next topic |
Author |
Message |
JC
Joined: 03 Nov 2005 Posts: 7
|
WDT Problem |
Posted: Wed Apr 05, 2006 1:28 am |
|
|
Hi,
I've got a problem with WDT concerning the Fuse. I can't regulate when the reset will happen. I tried to change the fuses but it resets exactly after the same amount of time.
here is my example:
Code: |
#include <18F4580.h>
//#use delay(clock=20000000,restart_wdt)
#use delay(clock=20000000)
//#FUSES NOWDT
#FUSES WDT32768
//#FUSES WDT16
#FUSES RC //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#include "Display.c"
#include "KeypadBis.c"
void main()
{
long count_outside;
char key;
lcd_init();
kbd_init();
count_outside=0;
switch ( restart_cause() )
{
case WDT_FROM_SLEEP:lcd_gotoxy(1,1);lcd_putc("sleep");break;
case WDT_TIMEOUT:lcd_gotoxy(1,1);lcd_putc("timeout");break;
case MCLR_FROM_SLEEP:lcd_gotoxy(1,1);lcd_putc("MCLR sleep");break;
case NORMAL_POWER_UP:lcd_gotoxy(1,1);lcd_putc("Normal power up");break;
}
setup_wdt(WDT_ON);
lcd_gotoxy(1,2);
printf(lcd_putc,"Hit any key.");
lcd_gotoxy(1,3);
while(TRUE)
{
key=kbd_getc();
if (key!='\0')
{
restart_wdt();
printf(lcd_putc,"%c",key);
}
}
}
|
1) Does someone see any error or have an explanation?
2)When is the best time to reset the WDT? at the end of the While(TRUE) loop?
Thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 05, 2006 3:00 am |
|
|
Quote: |
I've got a problem with WDT concerning the Fuse. I can't regulate when
the reset will happen. I tried to change the fuses but it resets exactly
after the same amount of time.
|
What is the amount of time ? How do you measure it ?
Quote: |
#use delay(clock=20000000)
#FUSES RC //Resistor/Capacitor Osc with CLKOUT
#FUSES LVP |
According to the 18F4580 data sheet, RC mode will only run at
a maximum of 4 MHz. But you have your #use delay() statement
set for 20 MHz.
Are you really using an external Resistor and Capacitor for an RC
oscillator ?
Also, are you really using a Low Voltage programmer ? 99% of all
people use a High Voltage programmer, and use the NOLVP fuse. |
|
|
JC
Joined: 03 Nov 2005 Posts: 7
|
|
Posted: Wed Apr 05, 2006 4:18 am |
|
|
Thanks for your answer.
You were right for both of your remarks. Now my fuses look like this:
Code: |
#include <18F4580.h>
//#use delay(clock=20000000,restart_wdt)
#use delay(clock=20000000)
//#FUSES NOWDT
//#FUSES WDT32768
#fuses HS,NOPROTECT,NOLVP
#FUSES WDT16
|
I use an external 20MHz Oscillator. That's why the "#use delay(clock=20000000)"
I tried with these changes but I still can't notice any change between:
#FUSES WDT16
or
#FUSES WDT32768
I would like to let run the controller for some seconds without making any reset with the Watchdog. What is the maximal time available?
Thank you. |
|
|
JC
Joined: 03 Nov 2005 Posts: 7
|
|
Posted: Thu Apr 06, 2006 9:20 am |
|
|
Please, does someone have any idea? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 06, 2006 9:30 am |
|
|
Quote: |
I tried with these changes but I still can't notice any change between:
#FUSES WDT16
or
#FUSES WDT32768
I tried to change the fuses but it resets exactly
after the same amount of time.
|
From my previous post:
What is the amount of time ? How do you measure it ? |
|
|
JC
Joined: 03 Nov 2005 Posts: 7
|
|
Posted: Mon Apr 24, 2006 8:58 am |
|
|
Sorry for the long silence.
The program restarts after something like half a second, whatever I specified as watch dog fuse (WDT16 or WDT32768)
The specification of the microcontroller talks about 2.18 Minutes for the WDT32768 variant and I definitely don't reach that.
Thank you for your help. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Apr 24, 2006 9:06 am |
|
|
What is the version number of your compiler? |
|
|
JC
Joined: 03 Nov 2005 Posts: 7
|
|
Posted: Mon Apr 24, 2006 9:09 am |
|
|
3.241 |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Apr 24, 2006 2:48 pm |
|
|
I checked the code for the fuses generated by v3.241 and to me this looks ok.
Please note that the function setup_wdt(WDT_ON) for the PIC18 only works when you have the hardware fuses set to NOWDT, otherwise the software will not be allowed to overrule the fuse settings (PIC18F4580 datasheet chapter 24.2.1).
Setting the watchdog delay to 32768 should give you a nominal 2.18 minutes before the watchdog kicks in. If this happens quicker, maybe something else in your code is messing up? Just for testing make your program as small as possible, you have way to much code in your program to make debugging easy. |
|
|
JC
Joined: 03 Nov 2005 Posts: 7
|
|
Posted: Tue Apr 25, 2006 7:57 am |
|
|
Thank you for your help,
I don't understand what you mean. In the sample code of CCS, we got:
Code: |
#fuses WDT1 // PIC18 example, See
// restart_wdt for a PIC18 example
main() { // WDT1 means 18ms*1
setup_wdt(WDT_ON);
while (TRUE) {
restart_wdt();
perform_activity();
}
}
|
CCS sets the fuses and then makes a setup_wdt(WDT_ON).
Changing the WDT fuse doesn't change the delay, even with 32768 that is suppose to last 2,18 minutes... |
|
|
|