Day/night auto exposure intervalometer - Script Writing - CHDK Forum

Day/night auto exposure intervalometer

  • 2 Replies
  • 4763 Views
Day/night auto exposure intervalometer
« on: 08 / September / 2010, 13:46:53 »
Advertisements
Hi, everybody.

I recently bought myself an A480 and completely fell in love with CHDK, which is completely awesome.   :)
I started to experiment with script writing and decided I'd like to write a script that would take accurate exposures at almost any light level - I'd really like to capture a sunrise, starting at twilight.

Here's what I got so far - I don't know how well it should work on other cameras.

Hopefully all of the parameters make sense - Starting stops is just the initial TV96 value divided by 96, and the camera goes from there by taking pictures and analyzing the RAW histogram.

Code: [Select]
@title Day/night intervalometer
@param a Save RAW
@default a 1
@param b Starting stops @ ISO80
@default b 0
@param c Pause between shots (s)
@default c 10
@param e Max shot length (15 s)
@default e 1
@param d EV offset (2/3rds)?
@default d -2

rem These can be parameters, but I don't think
rem there's enough room for them
rem @param i 100% level
rem @default i 64
i = 64
rem @param f Coverage %
rem @default f 99
f = 99

i = i * 8
j = i / 4

rem *** NON-PARAMETER VARIABLES ***
rem uvwxyz/UVWXYZ are reserved for counters
rem yz/YZ are reserved for counters in subroutines

rem N - shot counter (only tuned shots, not guide shots)
rem I - guide shot ISO - 0 for 100, 1 for 1600
rem G - guide shot shutter speed, TV96 value
rem g - tuned shot shutter speed, TV96 value
rem C - tuned shot correction amount, based on histo
rem F - flag - used for multi-line if/then statements
rem h - histogram range
rem H - ""
rem J - previous adjustment direction
rem     to prevent flip-flopping for a while
rem      1 - longer exposure time
rem     -1 - shorter exposure time
rem      0 - first change this shot
rem L - shutter speed limit imposed on shot
rem K - iso level of the final image

L = -768
if e = 1 then L = -375
if e = 2 then L = -471
if e = 3 then L = -527
if e = 4 then L = -567
if e = 5 then L = -597
if e = 6 then L = -623
if e = 7 then L = -644
if e = 8 then L = -663
if e = 9 then L = -679
if e = 10 then L = -693
if e = 11 then L = -707
if e = 12 then L = -719
if e = 13 then L = -730
if e = 14 then L = -740
if e = 15 then L = -750
if e = 16 then L = -759

N = 0
if a < 0 then a = 0
if a > 1 then a = 1

shot_histo_enable 1

I = 1
G = (b * 96) + 414

:anothershot

set_raw 0

if I = 0 then set_iso 2
if I = 1 then set_iso 6

J = 0

do

if G <= 0 and I = 0 then F = 1 else F = 0
if F = 1 then I = 1
if F = 1 then set_iso 6
if F = 1 then G = G + 384
F = 0

if G >= 768 and I = 1 then F = 1 else F = 0
if F = 1 then I = 0
if F = 1 then set_iso 2
if F = 1 then G = G - 384
F = 0

set_tv96_direct (G + 1)
shoot

F = 1
h = get_histo_range 0 j
H = get_histo_range 0 i
if (h >= f) and (G > -480) and (J > -1) then G = G - 96
if (h >= f) and (G > -480) and (J > -1) then J = 1
if (h >= f) and (G > -480) and (J > -1) then F = 0
if (H <= f) and (G < 1053) and (J < 1) then G = G + 96
if (H <= f) and (G > 1053) and (J < 1) then J = -1
if (H <= f) and (G < 1053) and (J < 1) then F = 0

until F = 1

N = N + 1
print "TAKING SHOT", N

rem Y = 0
rem do
rem Y = Y + 8
rem H = get_histo_range 0 Y
rem until (Y >= 1024) or (H >= f)
rem hopefully faster (and more accurate) routine for finding histogram level
Y = 0
do
Y = Y + 64
H = get_histo_range 0 Y
until (Y >= 1024) or (H >= f)
Y = Y - 64
do
Y = Y + 16
H = get_histo_range 0 Y
until (Y >= 1024) or (H >= f)
Y = Y - 16
do
Y = Y + 4
H = get_histo_range 0 Y
until (Y >= 1024) or (H >= f)

Y = (Y * 1059) / 1000
C = 0
do
C = C - 8
Y = (Y * 1059) / 1000
until (Y >= i)

set_raw a
g = G
if I = 1 then g = g - 384
g = g - 30
g = g - (d * 32)
g = g + C + 1
K = 1
if g > 1053 then g = 1053
if (g < L) then K = 2
if (g < L) then g = g + 30
if (g < L) then K = 3
if (g < L) then g = g + 96
if (g < L) then K = 4
if (g < L) then g = g + 96
if (g < L) then K = 5
if (g < L) then g = g + 96
if (g < L) then K = 6
if (g < L) then g = g + 96
if (g < L) then G = L
set_iso K


set_tv96_direct g
shoot

print "WAIT..."
sleep c*1000
goto "anothershot"

:endprogram

shot_histo_enable 0

end

I dunno if anybody would find this to be useful, or have any suggestions, but there you go.
I haven't had a chance to test it very much with night shots, but it seems to do auto exposure pretty well during the day, and will go from 1/2000 all the way up to a couple of minutes.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Day/night auto exposure intervalometer
« Reply #1 on: 08 / September / 2010, 14:05:23 »
I'm wondering how much is this different in functionality and performance compared to the sunset scripts (that really do work as generic timelapse scripts regardless of the name), at least you're using the same shot histogram feature developed for the purpose of those scripts:
http://chdk.setepontos.com/index.php/topic,2156.0.html
http://chdk.setepontos.com/index.php/topic,3079.0.html

Re: Day/night auto exposure intervalometer
« Reply #2 on: 08 / September / 2010, 16:20:17 »
Looking at those scripts, I think I really need to learn Lua.  Just being able to use multi-letter variables would be wonderful.  :P  And yeah, it does look like they're fairly similar - I wanted to write mine mostly as a learning exercise, but it looks like it's got a way to go before being as useful as either of those scripts.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal