I am trying to find time elapsed (in seconds) since execution of the program. Should I use zmg.time or zmg.ticks?

Also, I made this code:


Code:

print("Chess timer starting...")
--function variables
local drawRectFill = zmg.drawRectFill
local fastCopy = zmg.fastCopy
local makeColor = zmg.makeColor
local drawPoint = zmg.drawPoint
local keyMenuFast = zmg.keyMenuFast
local clear = zmg.clear
local drawText = zmg.drawText
local keyDirectPoll = zmg.keyDirectPoll
local keyDirect = zmg.keyDirect
local floor = math.floor
local random = math.random
local time = zmg.time
local ticks = zmg.ticks

--screen vars
local LCD_SCREEN_WIDTH = 384
local LCD_SCREEN_HEIGHT = 216
local exit = 0

--game variables
local key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27}
local chesstimer = {current=0}
local color = {bg=makeColor("white"), fg=makeColor("black")}

keyDirectPoll()
--main loop
while exit~=1 do
   clear()
   --keys
   if keyDirect(key.Exit) > 0 then exit = 1 end

   chesstimer.current = ticks()
   
   
   --display
   drawText(1, 1, chesstimer.current, color.fg, color.bg)
   fastCopy()
   
   
   
   keyDirectPoll()
end


It seems that the zmg.ticks function does not start at 0 when the program is run?

I get output starting around 6 million....


EDIT:

OK, this code ticks about once per second, but its still pretty fast. Are we sure that it really ticks every 1/64 of a second?


Code:

local fastCopy = zmg.fastCopy
local makeColor = zmg.makeColor
local clear = zmg.clear
local drawText = zmg.drawText
local floor = math.floor
local ticks = zmg.ticks

startTime = ticks()
--main loop
while exit~=1 do
   chesstimer.current = ticks() - startTime
   drawText(1, 1, floor(chesstimer.current/100), color.fg, color.bg)
   fastCopy()
end
1) If you want timing finer than one second, or you want to space events, use zmg.ticks(). It does not start at zero, so you measure the starting time and then calculate zmg.ticks()-starting time.
2) If you want the absolute wall-clock time, use zmg.time(), which gives you the current number of seconds since January 1, 1970 (epoch time).
ok, gotcha. Smile

thanks.

does zmg.ticks() really increment at 1/64th sec intervals?
flyingfisch wrote:
ok, gotcha. Smile

thanks.

does zmg.ticks() really increment at 1/64th sec intervals?
I believe so. The only other options are (1) You're running overclocked (I'm not sure if that affects the RTCTicks() syscall or not) or (2) it's 1/128th sec.
The RTC's oscillator powers the CPG, not the other way around.
AHelper wrote:
The RTC's oscillator powers the CPG, not the other way around.


???

(I don't understand AHelper's post... whats a CPG?)


@Kerm: I tried dividing by 128 and now its ticking every second. Wink So that's what it must be.
AHelper wrote:
The RTC's oscillator powers the CPG, not the other way around.
OK, good to know. Flying: AHelper basically said that overclocking the CPU via the CPG won't cause the RTC to tick any faster. And good to know that it's 128 ticks; mind updating the wiki?
sure will do that, thanks for explaining Smile

EDIT:

does the clock recycle at a certain point or no?
flyingfisch wrote:
sure will do that, thanks for explaining Smile

EDIT:

does the clock recycle at a certain point or no?
It recycles at 2^32-1, or every 388.36 days.
so we can test if it about to recycle and then handle the recycle?
KermMartian wrote:
And good to know that it's 128 ticks; mind updating the wiki?
I already have that in an article. See here.
KermMartian wrote:
It recycles at 2^32-1, or every 388.36 days.
For RTC_GetTicks() or w/e? IIRC, it overflows at midnight/24 hours.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement