I found this topic on record dark frames, control with mechanical shutter from lua script. I don't know how to adopt for my camera.
This should work in any build with "native calls" enabled. The function required to register the Mecha event procs may vary on some cameras. If the return value of call_event_proc is -1, then the function probably isn't registered. If this happens, someone here can probably find the correct function for you.
Depending on camera and settings, you may need to open the shutter after taking the dark frame.
In CHDK 1.2, you don't need a special build to use native, you just have to turn the "Enable Lua native calls" option on in the misc menu.
If i understand properly, this script switch a shooted double image to one normal and one dark frame pictures separate.
You can just close the shutter and take one shot to make a dark frame.
The CCD sensor temperature is important, different normal and dark frame CCD temperature not good. This is one thing why it's not good to use very old dark frames.
You could take a series of dark frames and log the CCD temperature. Then log the CCD temp when you shoot, and match them up.
The script attached here may be useful
http://chdk.setepontos.com/index.php?topic=9229.0very interesting topic, a540 camera record a normal and dark frame separate
http://chdk.setepontos.com/index.php?topic=1998.msg18450#msg18450
That code saved the raw before and after the canon dark frame. That doesn't give you the actual dark frame (most likely Digic does the subtraction when it reads out the dark frame, and so it's never stored in ARM accessible memory), but the difference between the two would show you what has been subtracted out. However, this method requires new hooks in the ASM code for every camera. Using the mecha eventprocs to close the shutter is a much more efficient way to get dark frames.