classic Classic list List threaded Threaded
1 message Options
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view


So, one of the things I've been doing recently is tracking timing data for adcscope.lua when running it.  I've found certain things that increase or decrease the amount of time spent getting samples, but I hadn't actually checked what the bare minimum time would be for a dry loop like the following:


while 1 do
  t1 = tmr.start(0)
  t2 = tmr.read(0)
  dtime = tmr.diff(0,t2,t1)
  term.putstr(string.format("Time (us): %06d",dtime))

For LM3S6965, I get 79 us.  Is this correct?

I get generally the same results if I start the timer outside the loop and do two subsequent reads.
Making t1 and t2 locals shaves off a little but not much.  If I make tmr.start and tmr.read locals, things get down to 13 us.  Does this jibe with everyone else's findings?

If I do a local function between the two timers like math.sqrt, I get a stable 48 us/cycle:


local t1, t2, s2
local tstart = tmr.start
local tread = tmr.read
local speedfun = math.sqrt

while 1 do
  s2 = 23
  t1 = tstart(0)
  s2 = speedfun(s2)
  t2 = tread(0)
  dtime = tmr.diff(0,t2,t1)
  term.putstr(string.format("Delay (us): %06d",dtime))

Making all the timing and sampling functions and variables local, here are the timings I'm looking at for adcscope.lua when getting samples from 4 channels.

Pass table to getsamples, modify specified index ( adc.getsamples(v,1,adcvals,i ): 293 us (stable)
Convert returned table to integer, insert into table (adcvals[i] = adc.getsamples(v,1)[1]): ~470 us (fluctuates)
Replace nested table of values within adcvalues table (adcvals[i] = adc.getsamples(v,1)): ~450 (fluctuates, sometimes maybe up to 1000-2000 us)