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
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.
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.
Comments
so Mainloop is not a label, it's an implied "GOTO" Mainloop...... which executes the PUB Mainloop
-Phil
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?
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.
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