PDA

View Full Version : Program time-out



Travin77
- 10th June 2006, 00:39
Hello all. I am wondering if anyone can provide some programming advice. I am looking for a way to provide a time-out for a program. I would like for the program to wait for a user to push a button. If the user fails to push a button within say 1 min, the program starts over. I haven't a clue how to do something like this short of some kind of loop that I would probally screw up. Thanks in advance.

Travin

SteveB
- 10th June 2006, 04:04
This might be a solution that will work for you:

- Set up a Timer with a prescale and starting value so it overflows at the desired interval ("say 1 min"). Depending on what clock rate your using, you may be limited to a timer with a large prescale. A quick look at the "Complete Mid-Range/High-Range Reference Manuals" shows TIMER0 with a prescale as large as 1:256. Certainly enough for any clock rate you could use.

- Either setup an interrupt handler or just poll the timers interrupt flag periodicly (depending on the timing precision you need) to know when the time period has expired.

- IF the time expires THEN GOTO where ever you want to restart the program.

- When the button is pressed, stop the timer, reset the prescale and starting value, then restart the timer.

Is this what you are looking to accomplish?
Steve

trying
- 10th June 2006, 04:31
I use this

A VAR WORD
For A = 0 TO 60000 '1 min loop looking for pb
Pause 1
IF pb = 0 Then
LED = 1
Pause 3000
LED = 0
EndIF

Next A
goto were ever

Travin77
- 10th June 2006, 16:58
That thought had crossed my mind. The problem is I know absolutely nothing about interupts or the pre-scalar settings. I tried to learn about them early on wheh I was building the timer example that is here on the forum. It is set up for a 4 mhz crystal and I was using a 20 mhz crystal. I couldn't figure out how the prescalar worked. If you would be willing to teach me then I would be willing to learn. I just don't want to monopolize your time as I am sure it is valuable. Here is some background on my project:

16F876a running at 20 mhz. It is decoding dtmf signals from a dtmf chip. I want the program to wait for the pin to go high that says a tone has been decoded. If that pin doesn't go high within 1 minute, I want the program to start over at the beginning. thanks for the help in advance.

Travin

Thanks trying. I tried your idea as it is simpler to implement, the problem was it was missing the pin going high. I couldn't seem to get the timing right.

Travin77
- 10th June 2006, 17:01
That thought had crossed my mind. The problem is I know absolutely nothing about interupts or the pre-scalar settings. I tried to learn about them early on wheh I was building the timer example that is here on the forum. It is set up for a 4 mhz crystal and I was using a 20 mhz crystal. I couldn't figure out how the prescalar worked. If you would be willing to teach me then I would be willing to learn. I just don't want to monopolize your time as I am sure it is valuable. Here is some background on my project:

16F876a running at 20 mhz. It is decoding dtmf signals from a dtmf chip. I want the program to wait for the pin to go high that says a tone has been decoded. If that pin doesn't go high within 1 minute, I want the program to start over at the beginning. thanks for the help in advance.

Travin

Thanks trying. I tried your idea as it is simpler to implement, the problem was it was missing the pin going high. I couldn't seem to get the timing right.

Archilochus
- 10th June 2006, 18:54
Thanks trying. I tried your idea as it is simpler to implement, the problem was it was missing the pin going high. I couldn't seem to get the timing right.

Hi Travin77 - trying's sample waits for the pin to go low. If your button pulls an input high, just replace the "IF pb=0" with "IF pb=1"

Or do you need to do something different than just wait for a button press?

Arch

Travin77
- 11th June 2006, 03:49
I realized that the pause in trying's loop paused for 3 seconds. I changed the loop structure a little though I haven't had a chance to check it yet. Here it is:

repeat
repeat
t=t+1 'added this
pauseus 500 'added this
until dtmf_ready=1 or t > 60000 'added this
if t > 60000 then start 'added this
gosub getdtmf
password[c]=dtmf
c = c + 1:pause 500
until c > 7

this should give me a 30 timeout feature if I calc'ed it correctly. I am running 20 mhz. The dtmf_ready is a pin on the pic that waits for the dtmf decoder chip to go high which indicates that a tone has been decoded and is ready for the pic to "read". This pin stays high for as long as the individual holds the button down. hopefully this doesn't slow down the program any. Thanks

Travin

trying
- 11th June 2006, 04:33
travin 77 I guess i should have gone into more detail it was just a ideal as I was walking out the door
yes it's looking for a LOW pb and the pause time will add to total time of the loop. hope I didn't get you side tracked