 |
 |
| View previous topic :: View next topic |
| Author |
Message |
jlucas
Joined: 08 May 2011 Posts: 41 Location: Carthage, MO
|
|
Posted: Thu Oct 25, 2012 5:10 pm |
|
|
| 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
|
|
Posted: Fri Oct 26, 2012 1:25 am |
|
|
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
|
|
Posted: Fri Oct 26, 2012 6:19 pm |
|
|
Problem solved!!!
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!  _________________ Always remember, things are never so bad that they can't get worse. |
|
 |
|
|
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
|