Converting TV96 value to shutter time - LUA Scripting - CHDK Forum
supplierdeeply

Converting TV96 value to shutter time

  • 4 Replies
  • 5772 Views
*

Offline lapser

  • *****
  • 1093
Converting TV96 value to shutter time
« on: 28 / September / 2012, 23:23:03 »
Advertisements
Code: (lua) [Select]
function seconds(tv) -- for chdk 32 bit integer numbers
  if(tlog==nil)then
    tlog="000007015022029037044052059067075083091098106114122131139147155164172181189198207215224233242251260269278288297306316325335345354364374384394404414424435445456466477488498509520531542553565576587599610622634646658670682694706719731744756769782795808821834847861874888901915929943957971986"
  end
  pre="1/"
  if(tv<=0)then
    tv=-tv
    pre=""
  end
  ti=(tv%96)*3+1 -- index into tlog
  tv=(2^(tv/96))*(string.sub(tlog,ti,ti+2)+1000) -- time value in msec
  ti=tv/1000 -- integer part
  ts=string.format("%s%u.%03u",pre,ti,tv%1000) -- xx.xxx or 1/xx.xxx
  if(ti>1)then -- truncate digits to reflect decimal precision
    if(ti>149)then ti=-5
    elseif(ti>14)then ti=-3
    else ti=-2 end
    ts=string.sub(ts,1,ti)
  end
  return ts
end
I wrote this function to convert Canon TV96 values into shutter times. It returns a string with the shutter time in seconds. I use it like this:

tv96=get_tv96()
print(tv96, "=", seconds(tv96),"seconds")
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: Converting TV96 value to shutter time
« Reply #1 on: 29 / September / 2012, 06:22:49 »
Ooo, that's nice;) I'll use this in my intervalometer with auto Tv, where the displaying value is incorrect now:

http://chdk.setepontos.com/index.php?topic=7757.0
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Converting TV96 value to shutter time
« Reply #2 on: 29 / September / 2012, 07:07:49 »
A very nice function. Thanks for that.

Another way is using a table:
Code: (lua) [Select]
function print_tv(val)
    local i = val + 19+15
    local tv_str = {"2048","1625","1290","1024","812","645","512","406","322",
                    "256","203","161","128","101","80","64","50","40","32","25",
                    "20","15","13","10","8","6","5","4","3.2","2.5","2","1.6",
                    "1.3","1.0","0.8","0.6","0.5","0.4","0.3","1/4","1/5","1/6",
                    "1/8","1/10","1/13","1/15","1/20","1/25","1/30","1/40","1/50",
                    "1/60","1/80","1/100","1/125","1/160","1/200","1/250","1/320",
                    "1/400","1/500","1/640","1/800","1/1000","1/1250","1/1600",
                    "1/2000","1/2500","1/3200","1/4000","1/5000","1/6400","1/8000","1/10000"}
    if (i > #tv_str) or (i < 1) then
        return "n/a"
    else
        return tv_str[i]
    end
end

print(print_tv(get_tv96()/32))

msl
CHDK-DE:  CHDK-DE links

*

Offline lapser

  • *****
  • 1093
Re: Converting TV96 value to shutter time
« Reply #3 on: 29 / September / 2012, 10:33:39 »
Ooo, that's nice;) I'll use this in my intervalometer with auto Tv, where the displaying value is incorrect now:
Thanks. I'm still perfecting a time lapse script, and wrote this function for it. I liked the exposure adjustment at low brightness in your script.
Another way is using a table:
I started with a log table, but realized that using a string would be much more efficient in memory and speed. I also wanted a more exact value rather than an approximation. When TV96 changes by one, at least 1 digit of the output time changes so you can tell something happened.

I used Lua for Windows to create the log table (string) and debug the time converter. Then I changed it to a function for CHDK by removing the "math.floor" calls, since CHDK uses integer variables. This code runs under Lua for Windows (not CHDK):

http://code.google.com/p/luaforwindows/
Code: (lua) [Select]
f=io.open("testing.txt","wb")
f:write("tlog=\"")
for i=0,95 do
   nlog=math.floor(1000*(2^(i/96))+0.5)-1000
  f:write(string.format("%3u",nlog))
end
f:write("\"\n")
f:close()
--produces this line:
tlog="000007015022029037044052059067075083091098106114122131139147155164172181189198207215224233242251260269278288297306316325335345354364374384394404414424435445456466477488498509520531542553565576587599610622634646658670682694706719731744756769782795808821834847861874888901915929943957971986"

repeat
  io.write("Enter Tv96 value:")
  tv=tonumber(io.read())
  if(tv==nil)then break end
  pre="1/"
  if(tv<=0)then
    tv=-tv
    pre=""
  end

  ti=(tv%96)*3+1 -- index into tlog
  tv=(2^math.floor(tv/96))*(string.sub(tlog,ti,ti+2)+1000) -- time value xxxxxx
  ti=math.floor(tv/1000) -- integer part
  ts=string.format("%s%u.%03u",pre,ti,tv%1000) -- xx.xxx or 1/xx.xxx

  if(ti>1)then -- truncate digits to reflect decimal precision
    if(ti>149)then ti=-5
    elseif(ti>14)then ti=-3
    else ti=-2 end
    ts=string.sub(ts,1,ti)
  end

  io.write("time=",ts,"\n")
until(false)
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos


Re: Converting TV96 value to shutter time
« Reply #4 on: 29 / September / 2012, 11:50:55 »
Ooo, that's nice;) I'll use this in my intervalometer with auto Tv, where the displaying value is incorrect now:
Thanks. I'm still perfecting a time lapse script, and wrote this function for it. I liked the exposure adjustment at low brightness in your script.

I would like to see your improved script posted on forum;)
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal