Program time-out


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    89

    Default Program time-out

    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

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    trying's Avatar
    trying Guest


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by trying; - 10th June 2006 at 04:40.

  4. #4
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Yes Steve

    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.

  5. #5
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Yes steve

    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.

  6. #6
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Travin77
    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
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

  7. #7
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Yup

    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 + 1ause 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

  8. #8
    trying's Avatar
    trying Guest


    Did you find this post helpful? Yes | No

    Smile

    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

Similar Threads

  1. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  2. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 02:55
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. Alarm Time
    By Santana in forum Code Examples
    Replies: 1
    Last Post: - 8th December 2006, 13:58
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts