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

Watch Dog on PIC 18F
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







PostPosted: Tue Jun 07, 2005 6:43 am     Reply with quote

The watchdog does not care about what the processor is actually 'doing'. The only thing it cares about is the reset_wdt instruction. If you have this inside the loop, then the watchdog will never occur, but if (for instance), you have a layout like:
Code:

while (true) {
   reset_wdt();
   some_sort_of_loop;
}


Then if the 'some sort of loop' gets hung, the code will never return to the reset_wdt instruction, and will reset itself when the watchdog timer expires.
What sort of interval to choose, is entirely down to you. If your system is in a slow loop that may take many tens of mSec to execute, and you are happy to accept many mSec of delay before a fault is 'seen', then you can set the watchog out to a couple of seconds. However if you expect data every few uSec, and want a fast response if the sysem hangs, then going down to the minimum becomes the correct solution...

Best Wishes
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Fri Aug 26, 2005 6:09 am     Reply with quote

Hello,

thanks a lot for all your help.

I worked it out but i still have one problem: i would like to to reset the PIC after 30 seconds if one condition is not satisfied.

I see that i can't have more than few seconds ,with the watchdog.

How could i manage this for 30 seconds ?

Is there a big difference between setup_wdt(WDT_ON), that restarts the PIC, and the reset_cpu() function that i think is doing the same thing ?

So i can reset the pic when i decide it right ?

Is it the same reset for the PIC or not ?

Many thanks.
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 12:45 am     Reply with quote

Question Idea
asmallri



Joined: 12 Aug 2004
Posts: 1679
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Aug 29, 2005 10:41 pm     Reply with quote

Quote:

I worked it out but i still have one problem: i would like to to reset the PIC after 30 seconds if one condition is not satisfied.


A WDT is typically used to to recover from unexpected program behaviour such as a program crash. In you case you do NOT need the WDT.

Code:

Initial a timer for a 30 second count();
do
   {
    do something();
    if (my event occured)
        disable timer;
    if (timer expired)
        reset_cpu);
    }


Quote:

Is there a big difference between setup_wdt(WDT_ON), that restarts the PIC, and the reset_cpu() function that i think is doing the same thing ?


These funcition are not even related. reset_cpu() means perform an immediate rest of the CPU.

setup_wdt(WDT_ON) means enable the software enabled WDT logic. Once you enable the WDT logic, if you do not periodically restart_wdt() then eventually the WDT timer will expire and the processor will reset.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
asmallri



Joined: 12 Aug 2004
Posts: 1679
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Aug 29, 2005 10:44 pm     Reply with quote

Quote:

I worked it out but i still have one problem: i would like to to reset the PIC after 30 seconds if one condition is not satisfied.


A WDT is typically used to to recover from unexpected program behaviour such as a program crash. In you case you do NOT need the WDT.

Code:

Initial a timer for a 30 second count();
do
   {
    do something();
    if (my event occured)
        disable timer;
    if (timer expired)
        reset_cpu);
    }


Quote:

Is there a big difference between setup_wdt(WDT_ON), that restarts the PIC, and the reset_cpu() function that i think is doing the same thing ?


These funcition are not even related. reset_cpu() means perform an immediate rest of the CPU.

setup_wdt(WDT_ON) means enable the software enabled WDT logic. Once you enable the WDT logic, if you do not periodically restart_wdt() then eventually the WDT timer will expire and the processor will reset.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 3:01 am     Reply with quote

Many thanks for you answer !

Do you have an exemple that shows how you do that ?

I want to count 30 seconds with a timer but i don't know how to use it this way and to disable the timer.

Do you have a concrete example for me to use a timer on a pic 18F458 at 4 MHz that count 30 seconds or more but not disturbing what the main is doing?


Many thanks.
asmallri



Joined: 12 Aug 2004
Posts: 1679
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Sep 02, 2005 10:20 am     Reply with quote

There's no free lunch. Here is a sample, based on a method I commonly use.

Code:

// System Timer 1ms clock
#define C_TMR0_1ms   256 - (XTAL_FREQ/(64*4*1000))

int8   TMR_100ms;         // 100ms timer counter
int16   TMR_30sec;         // 30sec timer counter
short   some_condition;      // some flag or other....

void ServiceSystemTimer()
///////////////////////////////////////////////////////////////////////////
//
// Subroutine ServiceSystemTimer
//
//   Tests the interrupt flag for the system timer (Timer 0)
//
// On Exit:
//   TF_100ms   set (TRUE) when TMR_100 decrements to 0
//   TF_30sec   set (TRUE) when TMR_30sec decrements to 0
//
// Calls:
//
///////////////////////////////////////////////////////////////////////////
   {
   // timer 0 interrupt source?
   if (bit_test(INTCON, TMR0IF))
      {
      // here on timer 0 rollover
      // reset the count for Timer 0
      TMR0L += C_TMR0_1ms;
      clear_interrupt(INT_Timer0);

      // service the 100ms timer
      if(!--TMR_100ms)
         {
         TF_100ms = TRUE;
         TMR_100ms = 100;
   
         // service the 30sec timer if active
         if(some_condition && (!--TMR_30sec))
            {
            TF_30sec = TRUE;
            TMR_30sec = 300;
            }
         }
      }
   }


void do_something()
   {
   ..
   // some condition has occured where I want to start the 30 second timer
   some_condition = true;
   TMR_30sec = 300;
   TF_30sec = false;
   }


main
   {
   ..
   ..
   // initialise 100ms supervisor timer
   TMR_100ms = 100;
   TF_100ms = false;

   // initialise 30sec timer
   TMR_30sec = 300;
   TF_30sec = false;

   some_condition = false;

   // setup the timers
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64 | RTCC_8_BIT);

   ..

   while (1)
       {
      do_someting();
      ..
      ..
      ServiceSystemTimer();
      if (some_condition && TF_30sec)
         reset_cpu();
      ..
      ..
      }
   }


_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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