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

WDT Problem

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



Joined: 03 Nov 2005
Posts: 7

View user's profile Send private message

WDT Problem
PostPosted: Wed Apr 05, 2006 1:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 3:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 4:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 06, 2006 9:20 am     Reply with quote

Please, does someone have any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 06, 2006 9:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 24, 2006 8:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 24, 2006 9:06 am     Reply with quote

What is the version number of your compiler?
JC



Joined: 03 Nov 2005
Posts: 7

View user's profile Send private message

PostPosted: Mon Apr 24, 2006 9:09 am     Reply with quote

3.241
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Apr 24, 2006 2:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 25, 2006 7:57 am     Reply with quote

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...
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