Shop OBEX P1 Docs P2 Docs Learn Events
Program problem with a delauy — Parallax Forums

Program problem with a delauy

NewzedNewzed Posts: 2,503
edited 2007-02-14 20:24 in Propeller 1
This post will read better if you expand the screen.

I have a menu-driven program that, among other things, returns the temperture from 3 locations if I press "N".· I wanted to introduce a delay so that if no menu option was selected within 5 minutes, the program would automatically execute the "N" routine.· I wrote the following:
PRI getChoice : selectedOption
· repeat
··· rxtime(2)
···· if rxtime(25000) == 0
······ senddata("Q")··· '"N" routine
······ waitcnt(clkfreq/10 + cnt)····
······ senddata("Q")
······ recdata
······ start
··· repeat until selectedOption := key.key··
··· if (selectedOption => "a") and (selectedOption =< "z"")························
····· selectedOption -= 32··· '32 = ("a" - "A")·
···· ' Convert letters to··uppercase·····························
· until (lookdown (selectedOption : "TGNRS"))

PUB rxtime(ms) : rxbyte | t
'' Wait ms milliseconds for a byte to be received
'' returns·0 if no byte received, $00..$FF if byte
· t := cnt
· repeat until (rxbyte := key.key) or (cnt - t) / (clkfreq / 1000) > ms

With the above, the program waits for about 25 seconds.· If there is no key press within that time, then it executes the "N" routine.· The program will not execute an rxtime of greater than 25000 because a 32 bit compare is only good for about 50/2 seconds.

Can anyone·modify the above so that I can get a wait period of up to 5 minutes?· If I want to select another menu option during the 25 seconds wait, I can do·so, ·but I have to press the selected key twice.· I can live with that if there is no alternative.

Sid
·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?

Newzed@aol.com
·

Comments

  • T ChapT Chap Posts: 4,198
    edited 2007-02-10 20:12
    Just a thought, why not create a new cog, run a 1 sec loop that increments a variable by 1 each pass. 300 will be 5 minutes, and you could have code in your main program checking to see if the variable was at 300, then do the required work plus reset the counter variable.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-02-10 21:21
    Pub rxtime(ms) : rxbyte
    repeat ms
    rxbyte := key.key
    if rxbyte
    quit
    waitcnt(clkfreq/1000 + cnt)

    This assumes that a 1 millisecond sampling rate of the keyboard is fast enough. You can wait 2^32 milliseconds, a long time.
  • NewzedNewzed Posts: 2,503
    edited 2007-02-10 21:43
    Jabshier, doesn't that require some indenting?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-02-10 23:11
    Pub rxtime(ms) : rxbyte
       repeat ms
          rxbyte := key.key
          if rxbyte 
             quit
          waitcnt(clkfreq/1000 + cnt)
    
    This assumes that a 1 millisecond sampling rate of the keyboard is fast enough. You can wait 2^32 milliseconds, a long time.
    

    That's what I get for being in a hurry and using the quick reply.
  • NewzedNewzed Posts: 2,503
    edited 2007-02-11 00:12
    John, I figured out the indentation while I waiting for a reply.· After playing around a bit, I set rxtime at 54700 and got readings every 10 minutes, except that the time increment increases an average of 7 seconds every cycle.· This is because one of the remote locations on transmits its temp every 15 seconds.· If I decrease rxtime by 7000ms, then I can be 7 secs under or 7secs over.· That's close enough for me.· Thank you very much for solving this little problem.· It still takes two key presses to execute another menu option but that is OK.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • NewzedNewzed Posts: 2,503
    edited 2007-02-14 20:24
    John, I fine-tuned Rxtime to 544000.· The pause in Rxtime takes 5440ms, and with the computer overhead, each reading is 4 seconds behind the last one.· I don't think I can get much closer than that.· Thanks again.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver

    Yesterday is history, tomorrow is a mystery, and today is a gift.
    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
Sign In or Register to comment.