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

Watchdog and timer0

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



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

Watchdog and timer0
PostPosted: Sun Jun 25, 2006 3:55 pm     Reply with quote

in my running code where i use timer0 if i want to add watchdog I got a problem, timer0 stops running
and watchdog doesn't run. If i cancel timer zero code and watchdog begin running correctly. I tryed to use timer 1 or timer 2 but ive a big delay in code with them configured as timer0. Immediately after powerup if i press a key to send some bytes in rs232 i can see bitstream starting after some seconds. instead with timer0 it starts immediately.

what could be the problem??
asmallri



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

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

PostPosted: Sun Jun 25, 2006 7:36 pm     Reply with quote

Post the smallest code segment that demonstrates the problem.

Which PIC?
Is the WDT fuse enables or software enabled?
What is your #use delay directive?
_________________
Regards, Andrew

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



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

PostPosted: Mon Jun 26, 2006 5:55 pm     Reply with quote

This is beginning of my working code only without watchdog:

Code:
#include <16f628A.h>


#fuses INTRC, NOPROTECT, NOPUT, NOWDT, MCLR, NOLVP , BROWNOUT
#use delay(clock = 4000000)




int count_time=0;
int acceso;   //
int pulsante=0; // variabile anti debounce on-off
int premuto=0;
int sforzo=0;
int porta=0;
int prima=0;
int comparatore=0;
int attivo=0;
int errore=0;
int allarme=0;
int timeout=0;

#define INTS_PER_200MS 20     // (20000000/(4*256*256))

BYTE seconds;      // A running seconds counter
BYTE int_count;    // Number of interrupts left before a second has elapsed


#int_rtcc                          // This function is called every time
void clock_isr() {                 // the RTCC (timer0) overflows (255->0).
                                   // For this program this is apx 60 times
    if(--int_count==0)             // per second.
    {

      if((premuto==1) || (premuto==3))
         errore++;
      else
         errore=0;


      int_count=INTS_PER_200MS;
    }

}









main()
{

SET_TRIS_A(0b11111111);
SET_TRIS_B(0b11110011);


 output_low(PIN_B2);
 output_low(PIN_B3);



setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);

setup_oscillator(OSC_4MHZ);

//setup_wdt(WDT_576MS);




   int_count=INTS_PER_200MS;
   set_timer0(0);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_32);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);




   while(TRUE)
   {



  //  restart_wdt();





       
        if(!input(PIN_B0))
        delay_ms(15);
        if(!input(PIN_B0) && (comparatore==255) && (attivo==0) )
         {
            ++premuto;
            comparatore=0;
            attivo=255;
            porta=1;
            errore=0;
            allarme=0;

           };
Ttelmah
Guest







PostPosted: Tue Jun 27, 2006 4:14 am     Reply with quote

Very simple answer.
There is only _one_ prescaler available, for _either_the watchdog (where it is used as a postscaler), or Timer0. As soon as you call 'setup_wdt(WDT_576MS);', you set the prescaler to be fed from the watchdog timer, and not from timer0.
Read the data sheet. Section 6.3.
With the prescaler used for timer0, you can only enable/disable the watchdog (not set it's rate), and it'll default to approximately 18mSec interval.
Use either Timer1, or Timer2 (the former is 16bit, and the latter has it's own independant prescaler), if you want to use a prescaler with the watchdog.

Best Wishes
fuzzy



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

PostPosted: Tue Jun 27, 2006 6:36 am     Reply with quote

ok thanks for your help.

I tryed with TIMER 1 or 2 but i had different problems. code started with some seconds of delay after power up. i can't understand why. this doesn't happen with timer 0.
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