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

don't want the WATCHDOG to reset, but it does!
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

don't want the WATCHDOG to reset, but it does!
PostPosted: Mon Jun 27, 2005 7:46 am     Reply with quote

Code:
#fuses XT, NOPUT,WDT, NOPROTECT, NOLVP, NOCPD, NOWRT, NOBROWNOUT


Code:


//*********************************** Main ***********************************//
void main()
{
   int8 i,temp;
   int16 key;
   int1 Pressed, Alles_los, signaal_gegeven = FALSE;
   char buffer[9];
   Zoemer_aan = TRUE;

   setup_wdt(WDT_2304MS);
   
   setup_adc_ports(NO_ANALOGS);   // ADC UIT
   setup_adc(ADC_OFF);
   
   SETUP_TIMER_1(T1_DISABLED);      // T1 uit

   SETUP_TIMER_2(T2_DISABLED,0,1);   // T2 uit

   setup_psp(PSP_DISABLED);      // PSP UIT

   setup_comparator(NC_NC_NC_NC);// COMPARATOR UIT
   setup_vref(FALSE);

   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   output_High(BR_SLEEP);
   output_high(E3_uit);          // E3-Lijn op hoog plaatsen
   output_low(BUZZ);             // Buzz laag

//Batterijspanning controleren; indien te laag: niet opstarten.
   do
   {
      Meet_Vbat(&Vbat);
      restart_wdt();
     
      if (Vbat < 3.5 && !signaal_gegeven)
      {
         //LOW_BAT_WARNING();
         restart_wdt();
         BUZZER();
         signaal_gegeven = TRUE;
         
      }
   }
   while (Vbat < 3.5 );


In main, I'm first checking the battery voltage; if it's too low, the pic just doesn't fire up. if it's good, the program begins to run.

Now I have touse the watchdog to get me out of sleep_mode. Because when the device is in sleep, the battery voltage also has to be monitored.

Now is on this code, the pic continuously reseting! I don't want that, I want it to buzz 1 time and stay looping until Vbat is good..

suggestions?

** Is there another way to wake up from sleep to check the battery voltage instead of the watchdog?

** The watchdog wakes the PIC up every 2300MS. How can I prolongue this time? If I want to check the battery voltage every minute for instance.

Many thanks
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 8:18 am     Reply with quote

Have a look for my post in this thread:

http://www.ccsinfo.com/forum/viewtopic.php?t=22952&highlight=sleep

It should help you out.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 8:26 am     Reply with quote

I checked that; doesn't help me ... sorry, I don't understand why the PIC is reseting!?
Guest








PostPosted: Mon Jun 27, 2005 9:37 am     Reply with quote

setup_wdt(WDT_OFF);
Guest








PostPosted: Mon Jun 27, 2005 9:41 am     Reply with quote

you must wake up evey 2sek and reset wdt
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Jun 27, 2005 10:43 am     Reply with quote

If you don't know why the PIC is reseting then use the restart_cause()
function at the START of main to print why. Use info from the header file for the chip to decrypt the number returned.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 11:57 am     Reply with quote

Make a small test program to experiment with the Watchdog Timer
in Sleep mode, until you understand it completely.

If you still can't make it work, then post a small but complete
test program, including the #fuses, #include, and #use delay()
statements.
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 2:00 pm     Reply with quote

Just some thoughts:
1) You are restarting the watchdog after Meet_Vbat() and directly again before BUZZER(), so the second iteration has a total time of these two functions before restarting the watchdog again. How much time do the functions Meet_Vbat and BUZZER take together?

2) The CCS define WDT_2304MS gives the impression of being very accurate, but on most PIC devices the watchdog is specified with approximately a 50% margin. You didn't mention your processor type, but for example on the PIC16F688 the watchdog is typical 17ms, with a minimum of 10ms and a maximum of 30ms. Suppose your chip has the minimal value, then the watchdog doesn't trigger after 2304ms, but after 1280ms. Have you accounted for this?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 3:47 pm     Reply with quote

Christophe wrote:
I checked that; doesn't help me ... sorry, I don't understand why the PIC is reseting!?


The reason why it resets is that the PIC always, upon wakeup caused by the watchdog, starts the program anew. FROM THE BEGINNING.

That's why, in my example, I look for the cause of the restart, and act accordingly.

Look again, read it, try to understand it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 4:15 pm     Reply with quote

Quote:

The reason why it resets is that the PIC always, upon wakeup caused by
the watchdog, starts the program anew.

That's not true if the PIC is in sleep mode. From the 18F452 data
sheet, in the section on Special Features of the CPU/ Watchdog Timer:
Quote:

During normal operation, a WDT time-out generates a
device RESET (Watchdog Timer Reset). If the device is
in SLEEP mode, a WDT time-out causes the device to
wake-up and continue with normal operation
(Watch-dog
Timer Wake-up).


There are also lots of little "gotchas" in sleep mode wakeup
with regard to interrupts and the watchdog. That's why I asked
him to do a test program. From the data sheet:
Quote:
To ensure that the WDT is cleared, a CLRWDT instruction
should be executed before a SLEEP instruction.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 4:24 pm     Reply with quote

PCM programmer wrote:
Quote:

The reason why it resets is that the PIC always, upon wakeup caused by
the watchdog, starts the program anew.

That's not true if the PIC is in sleep mode. From the 18F452 data
sheet, in the section on Special Features of the CPU/ Watchdog Timer:
Quote:

During normal operation, a WDT time-out generates a
device RESET (Watchdog Timer Reset). If the device is
in SLEEP mode, a WDT time-out causes the device to
wake-up and continue with normal operation
(Watch-dog
Timer Wake-up).


There are also lots of little "gotchas" in sleep mode wakeup
with regard to interrupts and the watchdog. That's why I asked
him to do a test program. From the data sheet:
Quote:
To ensure that the WDT is cleared, a CLRWDT instruction
should be executed before a SLEEP instruction.


PCM,

Then why does my little test program always do a fresh start every time the watchdog wakes it up?

To be honest, when I did that little test program (mainly as a learning exercise for myself), I couldn't figure out why the pic kept resetting, when the data sheet said that it shouldn't.

The only way I could get it to behave as it should (or as I thought it should) was to code the program the way I did. My conclusion was that the watchdog was doing a fresh restart every time.
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 6:16 pm     Reply with quote

newguy wrote:


Then why does my little test program always do a fresh start every time the watchdog wakes it up?



Might be because you have no infinite loop at the end of your code if the battery voltage is good!

Scott
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 7:36 pm     Reply with quote

sseidman wrote:
newguy wrote:


Then why does my little test program always do a fresh start every time the watchdog wakes it up?



Might be because you have no infinite loop at the end of your code if the battery voltage is good!

Scott


Scott,

You're confusing me with someone else. My code doesn't check for battery voltage, and it does have an infinite loop at the end of main.

A link to my code: http://www.ccsinfo.com/forum/viewtopic.php?t=22952&highlight=sleep

It goes to sleep, the watchdog wakes it up, and it starts fresh with every watchdog timeout.

I'd like to know what I'm missing.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 7:57 pm     Reply with quote

Here is a demo program for wake-up from Sleep by the watchdog timer.
I tested this with PCH vs. 3.188 on a PicDem2-Plus board.
It displays the following output in the terminal window:
Quote:

Start
Sleep
Wake up
Sleep
Wake up
Sleep
Wake up
etc.

Code:
#include <18F452.H>
#fuses XT, WDT, NOPROTECT, BROWNOUT, PUT, NOLVP   
#use delay(clock = 4000000, restart_wdt)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, restart_wdt, ERRORS)

void main()
{

printf("Start\n\r");


while(1)
  {
   printf("Sleep\n\r");

   restart_wdt();
   sleep();          // Go to sleep and wait for WDT to wake-up

   printf("Wake up\n\r");

   delay_ms(500);   
  }
 
}
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 9:39 pm     Reply with quote

PCM,

Thanks, that gives me a new approach to try.

-- Mark
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 1, 2, 3  Next
Page 1 of 3

 
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