Shop OBEX P1 Docs P2 Docs Learn Events
Propeller timing - Page 2 — Parallax Forums

Propeller timing

2»

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-10-13 21:55
    Graham, when the timeout loop is complete, assuming no key presses, then it jumps back to the repeat at Line 170.· This is where the screen actually refreshes.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-13 22:12
    I thought the idea was to have a regular refresh and then also have a time out so if no key was pressed you could send a warning message or something?
  • NewzedNewzed Posts: 2,503
    edited 2007-10-13 22:17
    Graham, my goal was to have the screen refresh at what ever interval I select.· I also wanted to be able to interrupt the refresh timeout with a keypress.· That is what I am doing now.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-13 22:44
    It seems most of our time in your threads is wasted by not understanding what you are actually trying to do. With the simple description you just posted we could have given an answer instantly. So my advice might be to state what you are trying to acheive, then how you are trying to acheive it and then what the problem is.

    Graham
  • NewzedNewzed Posts: 2,503
    edited 2007-10-13 23:33
    Graham, you are correct.· I re-read all my posts in this thread, and to my chagrin, I found that I had never clearly stated what I wanted to do.· For this, my apologies.

    Now......I wanted to change the refresh delay to 30 seconds so I wrote:

    ··· timeout := clkfreq + cnto
    ··· repeat 30
    ····· repeat while ( timeout - cnt ) > 0
    ······· if key.gotkey
    ········· cmds
    ········· quit
    ····· timeout := clkfreq + cnt

    I discovered that the QUIT exits the "repeat while" loop but it does not exit the "repeat 30" loop.· The result is that with a keypress, I have to wait until "repeat 30" completes before the screen refreshes.· What I would like to do is to be able to refresh the screen without waiting for "repeat 30" to complete.· I have a waitcnt at the end of each menu option to set the time the data remains on the screen.· How can I modify the above routine so when the program runs into the QUIT it will refresh the screen in a second or two?· I wrote:

    ··· timeout := clkfreq + cnto
    ··· repeat 30
    ····· repeat while ( timeout - cnt ) > 0
    ······· if key.gotkey
    ········· cmds
    ········· quit
    ····· timeout := clkfreq + cnt
    ····· if key.gotkey
    ······ QUIT

    but that didn't help.

    Sid


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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


    Post Edited (Newzed) : 10/13/2007 11:42:45 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-14 00:01
    The compares with CNT both of you are trying will not work! The algorithm I gave you is THE ONLY ONE to compensate for plus/minus overflow of CNT
  • hippyhippy Posts: 1,981
    edited 2007-10-14 02:06
    Newzed said...
    I discovered that the QUIT exits the "repeat while" loop but it does not exit the "repeat 30" loop. The result is that with a keypress, I have to wait until "repeat 30" completes before the screen refreshes. What I would like to do is to be able to refresh the screen without waiting for "repeat 30" to complete.

    Just put a call to refresh the display after you call your 'cmds' routine. You don't need to quit out of any loops that way.

    There are two potential problems with that; you may get a key, process it, refresh the screen and immediately after that the screen may be refreshed again. Plus, if the screen refresh takes long enough an impending timeout may be delayed and that delay will be rippled onwards ( although subsequent refreshes will be at the right rate ).

    This is another 'spec change', a requirement which wasn't originally stated, and the solutions haven't taken that into account. Simply hacking a solution isn't the best way to get to a solution for what is now a different problem. At some point you have to step back, take what you've learned, then design a system which does what you want. Think about what you need to do to achieve what you want, what steps and actions are needed before trying to work out how to actually implement it.

    Think of it this way - You need a loop. You need a timer. For simplicity that timer will timeout every second. You start the timer running and enter your loop. Whenever the timer timesout you increment a seconds counter, restart the one second timer. When the seconds counter reaches 10 seconds ( or whatever ) you refresh the display, restart the 10 second timer. If a key is detected you handle it, refresh the display and reset the 10 second timeout.

    RefreshDisplay
    start oneSecondTimer
    secondsCount :=0
    repeat
      if oneSecondTimer timedout
        restart oneSecondTimer
        secondsCount++
        if secondsCount => 10
          RefreshDisplay
          secondsCount := 0
      if key detected
        HandleKey
        RefreshDisplay
        secondsCount :=0
    

    That shouldn't be too hard to turn into actual Spin Code.
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 12:37
    deSilva, you said this is the only one that will work:

    z·:=·CNT
    REPEAT·WHILE·CNT-z·<·CLKFREQ
    ··IF·gotKey
    ······doSomething·or·QUIT
    ······z:=CNT

    I changed z to cnto and wrote:

    cnto :=·CNT
    REPEAT·WHILE·CNT-cnto·<·CLKFREQ
    ··IF·key.gotKey
    · cmds
    · cnto := cnt

    and ran the program.· If I press a·key, the program executes the selected option, completes the waitcnt at the end of the option, then refreshes the screen.· However, if I do not press a key, the screen never refreshes.

    Sid



    ······cnto:=CNT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-14 12:42
    Your indention is somewhat unclear.. Maybe the cnto := CNT is not in the IF-THEN part, than this is indeed an endless loop...
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-14 13:13
    Sid you should enclose code with [noparse][[/noparse]code ] and [noparse][[/noparse]/code ] to maintain the indentation. Also attaching the full program may help as it removes the possibility that the problem is else where.

    DeSilva, you are quite right, this is something I had not realized having always used waitcnts looking for a specific value where the overflow is not a problem (at least for shorter times).

    Graham
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 13:16
    deS, here is the routine I wrote.· The indentation is somewhat exagerated:

    cnto :=·CNT
    REPEAT·WHILE·CNT-cnto·<·CLKFREQ
    ···· IF·key.gotKey
    ···· cmds
    ···· cnto := cnt

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-14 13:41
    but nothing is indented from the if statement!

    Please see my comment above

    Graham
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 14:05
    Graham, you are so right!· I think I have been at this too long.

    Indented the "if" loop and moved cnto:= cnt to the beginning of my main repeat loop and now everything appears to be working fine.· Will have to let it run for awhile to see if the screen ever varies from the 5-second delay.· Up to 55 reads and still holding.· Thank you, Graham.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-14 14:09
    Sid, I think you have to remind yourself that none of this is hocus pocus and if something doesn't work there is a reason for it, then you can sit down and step through the program in your head or on paper, don't just try things randomly.

    I can also second the opinions of Hippy, you really need to spend a bit more time thinking exactly what it is you want to achieve and then sketch out the program on paper, perhaps as a flowchart it can really help especially for confusing little programs where it is hard to keep it all in you head at once.

    Glad to see progress getting made and I'm looking forwards to the results of all this hard work.

    Graham
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 14:57
    Up to 300 refreshes and still holding precisely 5 seconds.· Looks like it will go on forever if there is no keypress.

    So........I tried a keypress.· Worked just like I wanted!· That makes the program·practically perfect.· I don't think I can ever get a delay greater than 53 seconds because clkfreq*54 exceeds 32 bits.· However, if I store an 8-byte packet in EEPROM every 30 seconds, that will give me 15 hours of data logging, which is probably all I will ever need.· And I can read the EEPROM and display the data in Hyperterminal·where I can·capture it to an Excel file.· Then I clear the EEPROM and start all over.

    Thanks to all for helping me solve a complex problem.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-14 15:02
    You can exceed 53 seconds by having a further loop and counting the timeouts, much like Hippy suggested.

    The problem wasn't actually complex, well described it would have been 5mins work.

    Graham
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 16:02
    Graham, here is my little timing loop:

    ··· repeat while cnt-cnto < clkfreq*5
    ····· if key.gotKey
    ······· cmds

    Can you show me how to count the timeouts and exit the loop if there are 2 timeouts?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-14 16:48
    Sid, I can give you four different solutions for a clock, two of them needing another COG, one both timers of your main COG and the fourth one needs a garanteed refresh within 40 seconds.

    None of them can easily be adapted to your loop. The main issue being not knowing how long you will stay inside CMDS. Orcan you GUARANTEE that it will ALWAYS be shorter than 40 seconds?
  • NewzedNewzed Posts: 2,503
    edited 2007-10-14 20:15
    I just figured out a way to get a 60-second delay.· I wrote:

    ··· repeat while cnt-cnto < clkfreq*10
    ····· if key.gotKey
    ······· cmds
    ··· cnto := cnt···························· · 'reset cnto
    ··· repeat while cnt-cnto < clkfreq*10·
    ····· if key.gotKey
    ······· cmds
    ··· cnto := cnt··
    ··· repeat while cnt-cnto < clkfreq*10·
    ····· if key.gotKey
    ······· cmds
    ··· cnto := cnt··
    ··· repeat while cnt-cnto < clkfreq*10·
    ····· if key.gotKey
    ······· cmds
    ··· cnto := cnt··
    ··· repeat while cnt-cnto < clkfreq*10·
    ····· if key.gotKey
    ······· cmds
    ··· cnto := cnt··
    ··· repeat while cnt-cnto < clkfreq*10·
    ····· if key.gotKey
    ······· cmds

    And the screen refreshes precisely every minute.· If I want less than 60 seconds, I just comment out the repeat loops I don't need.

    Clumsy?· Probably.· Inefficient?· No doubt.· But it will work until I can figure out a better way.· You ask - why didn't I write:

    ··· repeat while cnt-cnto < clkfreq*30
    ····· if key.gotKey
    ······· cmds

    and use 2 repeats?· Because -·if I write just one loop of clkfreq*30 the screen refreshes every second.· I have no idea why.

    Sid



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-15 06:45
    Because 30 > 2^31 / CLKFREQ
    So this toggles the sign bit and the clever check becomes obsolete.....

    Or in other words: How do know whether the clock is late or still early?
    You can only judge according to the full range of available numbers: Half of them tell you are late and the other half tell you are early: 30 crosses this border..

    Post Edited (deSilva) : 10/15/2007 7:00:33 AM GMT
  • NewzedNewzed Posts: 2,503
    edited 2007-10-15 13:17
    deSilva, that makes sense.· Have you figured out what the upper limit for clkfreq*N is?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • hippyhippy Posts: 1,981
    edited 2007-10-15 17:06
    @ Sid : If "CLKFREQ*N must be less than MaxValue" then it follows that "N must be less than MaxValue/CLKFREQ".
  • NewzedNewzed Posts: 2,503
    edited 2007-10-15 23:25
    deSilva, your timing loop is excellent.· I have had the program running for about 7 hours, with no keypresses, and it is still displaying the precise time I selected.· No plus or minus 1 second.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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.