View previous topic :: View next topic |
Author |
Message |
honza
Joined: 23 Mar 2004 Posts: 2
|
newbeee who needs rtcc "timeout" help |
Posted: Tue Mar 23, 2004 7:32 am |
|
|
hi,
16f877
4mhz
pcm 3.174
i need a simple program that will "timeout." I using a keypad and i want it to stop reading in values from a user after a given time (10 seconds) tried looking at some examples of timer0 and interupts but couldn't see how i could make it stop a particular function. Any help is greatly appreciated
thanks jon |
|
![](templates/subSilver/images/spacer.gif) |
SteveS
Joined: 27 Oct 2003 Posts: 126
|
timeout |
Posted: Tue Mar 23, 2004 8:19 am |
|
|
If you want to use a timer and an interrupt do this:
Set up the timer and timer interrupt (per examples) for some reasonable period - in your case probably long since you want a ten second timer. I don't think you can get ten seconds directly since that's too long for the counters you have available at your crystal rate. So you will have a global variable that gets counted up (or down) in the interrupt routine. Lets see -with a 4Mhz clock, Timer0 set up with /256 prescale and run the full 256 counts, you will interrupt every 1/( 4e6/4/256/256) =~ 65msec, so 10sec/.065 =~ 152 counts. In the function that you want a timeout for, set the global counter to 0. The interrupt fires every 65 msec in which you will increment your counter. During your 'wait for user entry' code, look to see if the counter has passed 152. If so your ten seconds are up.
A simpler, non-interrupt method would be to add a delay_ms() in your wait loop - someting like
Code: |
for( waitcnt = 0; waitcnt < 100; waitcnt++)
{
if( /* insert user input test here */) break; // quit loop if user input
delay_ms(100); // wait 100msec before trying again
}
if( waitcnt >= 100 )
// no user input occured
else
// handle user input
|
but during the delay_ms() nothing else can be done.
- SteveS |
|
![](templates/subSilver/images/spacer.gif) |
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Tue Mar 23, 2004 11:31 am |
|
|
If you want to later expand the code and implement other features, consider implementing the interrupt driven suggestion by SteveS. You can use the TMR0 counter as general counter to the system i known basis, for example, 1ms and work some math to count and set flags of process timeout.
Marcus |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Mar 23, 2004 5:12 pm |
|
|
thanks guys for all the help, got it working just fine ![Razz](images/smiles/icon_razz.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|