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

PIC 10F with WTD

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








PIC 10F with WTD
PostPosted: Fri Nov 11, 2005 6:21 am     Reply with quote

Hello all
I have code (just part):

#include <10F206.h>

#fuses NOMCLR,NOPROTECT,WDT
#ROM 0x2007 = {0x0FFB}//----------------------------------------------------------------------Configuration bit

#use delay(clock=4000000)//-------------------------oscilator 4MHZ
#use fast_io(B)
int8 num;

void main() {

num++;

if (num>7){
num=0;
do smth
}

#asm
// Prescaler to WDT, max division 2304mS
movlw 0x8F
OPTION
#endasm

sleep();


}


I want to measure something one per 20 sec. I use var num to save number of cycles between measuring. Than start WTD and go to sleep. After 2.3 sec mC will be reseted by wtd.
This code doesnt work. Parametern num will be 0 after reset not 1, 2, 3...
What s the right way to do?
Thanks
foothill
Guest







WDT operations
PostPosted: Fri Nov 11, 2005 8:26 am     Reply with quote

There are several problems. Here's a general approach to Sleep/WDT:
Code:


#include "your chip.h"
#fuses WDT, etc
#use delay (clock=your clock in Hz)
<declare variables>
<define isr's>

void main()     /*begin main*/
{
   setup_wdt(WDT_2304MS);
   <set starting values of variables, if needed; ie, num = 0>

   while (TRUE)    /*start an infinite loop inside main()*/
   {
      if (num <= 6)
     {
        reset_wdt()
        num++     /* next if tests num; if still <7, goes back to sleep*/
     }

      if (num >=7)   /* if num >=7, do stuff*/
     {
        while (there's stuff to do)
        {
           reset_wdt();   /*you _must_ reset WDT every so often while                             
                                   awake*/
           num = 0;
           do stuff;
        }   /*note: when no more stuff to do, "while stuff" loop exits with
                num = 0 and WDT = 0; flow will then exit "if num>=7"
                loop and go to sleep*/
     }
     sleep

  }   /*end while (TRUE)*/
}   /*end main()*/
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