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

Using watchdog timer for timeout function
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
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

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

PostPosted: Thu Oct 25, 2012 5:10 pm     Reply with quote

Quote:
Why not use one of the hardware timers?

I'm willing to try anything. So far, though, I haven't gotten anything to work. Do you know where I could find some sample code for this?
_________________
Always remember, things are never so bad that they can't get worse.
Ttelmah



Joined: 11 Mar 2010
Posts: 20161

View user's profile Send private message

PostPosted: Fri Oct 26, 2012 1:25 am     Reply with quote

OK. A sort of partial example.
Will need tweaking to suit your clock chip etc..:
Code:

//Data definitions
#define TICK_REQUIRED (350) //7 seconds at 50*/second adjust to suit
//your timer
int16 tick=TICK_REQUIRED;
int1 send_message=FALSE;

//Use the code from EX_SISR to receive your serial, except modify the
//INT_RDA routine like:

#INT_RDA
void serial_isr(void) {
   int t;
   buffer[next_in]=getc();
   t=next_in++;
   if (next_in==BUFFER_SIZE)
       next_in=0;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
   tick=TICK_REQUIRED; //reload the ticker because a character has come
}

#INT_TIMER2
void ticker(void) {
  static int1 sent=FALSE;
  //Tick at some defined rate - say 50*/Sec
  if (tick) {
     --tick; //decrement if not zero
     sent=FALSE; //flag that a message has not been sent
  }
  else {
      //Here 'tick' has reached zero
      if (sent==FALSE) {
         send_message=TRUE;
         sent=TRUE;
      }
   }
}

//Then setup timer2 to tick at 50Hz in the main, and if no data is seen by
//INT_RDA for 7 seconds, the flag 'send_message' will be set. In your main
//if this is set, send your message.


Now, This will set the flag 'send_message', _once_ when there is a 7 second gap in the incoming data. If no more data comes the flag will be left unchanged, but as soon as another character comes, the counter will restart.

You can obviously change the count used, to suit the interrupt rate that is simplest for you.

Best Wishes
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

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

PostPosted: Fri Oct 26, 2012 6:19 pm     Reply with quote

Problem solved!!! Very Happy

I actually ended up taking a different approach, but the information I got here got me unstuck. I'm running TIMER1 in the 16F685 chip and having it cancel the event, and then it tells the 18F4520 that it did it.

It's working like a charm.

Thanks for all the help, guys! Wink
_________________
Always remember, things are never so bad that they can't get worse.
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