Shop OBEX P1 Docs P2 Docs Learn Events
Beginner Prop questions - Page 2 — Parallax Forums

Beginner Prop questions

2»

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-16 18:52
    The first PUB method in your top-level object starts automatically. You can call other methods in the object just by naming them (assuming they have no arguments). By deleting the "MainLoop" line, you're deleting a call to the MainLoop method, which is why it doesn't execute.

    -Phil
    OOOOOOooooh!

    so Mainloop is not a label, it's an implied "GOTO" Mainloop...... which executes the PUB Mainloop
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-16 19:16
    Not GOTO, but GOSUB, if you want to relate it to PBASIC terminology.

    -Phil
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-23 17:54
    One more question.... I think I already know the answer, but I can't think of a way to prove it:

    nextFrameTime := cnt + clkfreq / 50
    .......
    do something that takes longer than 50ms
    .......
    waitcnt( clkfreq + nextFrameTime )


    The program will just fall through the waitcnt because the elapsed time has already passed right?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-11-23 19:12
    Spiral_72,

    I'm guessing your 50ms is really 20ms?

    And, waitcnt( clkfreq + nextFrameTime ) should be waitcnt(nextFrameTime)?

    waitcnt( clkfreq + nextFrameTime ) would wait 1.02 seconds since nextFrameTime was set.

    You do want to make sure you don't use waitcnt on a time that has already passed. If the time has passed, the program will freeze until rollover (about 54 seconds @ 80MHz).

    I'm assuming you want to know how to check if 20ms (or some other time) has passed.
      frameInterval := clkfreq / 50
      time := cnt
      repeat
        if cnt - time > frameInterval
          time += frameInterval
          ' do stuff you want done after 20ms has passed
        ' do stuff all the time
    

    The above will check to see if the 20ms interval has passed and then reset the time so you can detect the passage of the subsequent interval.


    Yes
  • ratronicratronic Posts: 1,451
    edited 2011-11-23 19:17
    Spiral_72 if you use waitcnt with a value that the current CNT just passed it will hang there for another ~53 seconds (if your running @ 80mhz) before continueing. CNT is 32bit. 4,294,967,295/80,000,000 = 53.6870911875 seconds.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-24 05:01
    ARG! Thank you both. Now that you point it out, this was a silly question! and one that I should have known the answer.
Sign In or Register to comment.