Using chdk to measure the internal resistance of the batteries in the camera - Completed and Working Scripts - CHDK Forum

# Using chdk to measure the internal resistance of the batteries in the camera

• 6 Replies
• 12232 Views

#### Bagger288

• 8
##### Using chdk to measure the internal resistance of the batteries in the camera
« on: 15 / November / 2008, 19:59:04 »
Good batteries should have a low internal resistance, but measuring the internal resistance commonly requires special equipment. However, thanks to chdk, it can also be measured with just your camera. This script switches the LCD successively on and off, it measures the battery voltage in both cases, and then calculates the internal resistance of the batteries. The formula is  R = (V2-V1) / (P1/V1 - P2/V2),  where R = collective resistance of batteries in series, P = consumed electrical power, V = measured battery voltage, (1) = LCD-on, (2) = LCD-off.

Code: [Select]
`@title BatteryCheckgosub "Init"for i = 1 to n  for j = 1 to k    gosub "ClickAndMeasure"    next j  d = v - u  e = (p * 1000 / u) - (q * 1000 / v)  r = 1000 * d / e  print d, "mV dif; R", r, "mOhm"  next iend  :Init  @param k Click cycle length  @default k 3  @param n Sample size  @default n 2  @param p LCD-on power (mW)  @default p 1300  @param q LCD-off power (mW)  @default q 350  @param t Delay (sec)  @default t 10  return  :ClickAndMeasure  click "display"  z = get_display_mode  rem z=2 means LCD off  if z = 1 or z = 2 then    gosub "Measure"  else    sleep 1000  endif  return  :Measure  gosub "Delay"  if z = 1 then let u = get_vbatt  if z = 2 then let v = get_vbatt  return  :Delay  gosub "BlueBlink"  for m = 1 to t    gosub "OrangeBlink"  next m  return:BlueBlink  set_led 8 1 60  sleep 100  set_led 8 0  return:OrangeBlink  set_led 7 1 60  sleep 100  set_led 7 0  sleep 900  return`
- The script can be used to compare batteries of different brands, of different age, fully loaded vs. nearly empty, or NiMH vs. alkaline.
- Note: the formula is based on my observation that the camera (A720) draws a current which is reciprocal to the battery voltage. As a result it consumes a constant power if the battery voltage varies (unlike an ordinary resistance).
- The parameters P1 and P2 should be known; I measured it once for my camera using a current meter:  1300 mW with LCD on, and 350 mW with LCD off  (camera model A720).  These values probably depend somewhat on the camera model.
« Last Edit: 16 / November / 2008, 08:05:13 by Bagger288 »

#### fudgey

• 1705
• a570is
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #1 on: 16 / November / 2008, 04:32:05 »
Not a bad idea at all... You may want to take a look at http://chdk.setepontos.com/index.php/topic,2375.0.html if you haven't already done so. It might be fun to use more than one point (such as LCD switching you are measurening now, coupled with measurement in autofocus idle and half shoot) or just maximize the high current (half shoot in auto focus when LCD on) for greater accuracy. Btw, did you take into account the current those LEDs you are blinking may require when measuring the input power?

I didn't study the script in depth, but it looks like your measurement delays (how long to keep the camera in one mode letting the voltage settle before taking the voltage reading) aren't parametrized. With increased load, the battery voltage takes quite some time to settle to a lower value...do you know you have set an optimum i.e. do you deliberately measure fast enough to avoid settling to a value too low?

Finally, you should probably test for REC mode using get_mode, at least on my camera the disp button doesn't switch the LCD mode in PLAY mode, and the input currents are of course completely different as well.

#### fe50

• 3152
• IXUS50 & 860, SX10 Star WARs-Star RAWs
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #2 on: 16 / November / 2008, 06:13:57 »
...- The parameters P1 and P2 should be known; I measured it once for my camera using a current meter:  1300 mW with LCD on, and 350 mW with LCD off  (camera model A720IS).  These values probably depend somewhat on the camera model.

When you "switch" off the LCD on your A720, you switch off the LCD, the sensor & also the whole internal image processing, that's why there's such a big difference...the LCD itself has a much lower power consumption.
This doesn't work on all cameras, the models without an optical viewfinder (e.g. the SD870) only toggles the OSD state with the DISP key, the LCD is always on, sensor & image processing also.
On such cameras you can attach the PRINT button to "Display Off" (in the Canon menu), then with a long keypress to PRINT you can disable the LCD & the whole thing, too. This also works in a script, this way you can save battery lifetime e.g. for time lapse (SD870 / IXUS860 battery life for time lapse shots).

#### Bagger288

• 8
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #3 on: 16 / November / 2008, 07:54:39 »
It might be fun to use more than one point (such as LCD switching you are measurening now, coupled with measurement in autofocus idle and half shoot) or just maximize the high current (half shoot in auto focus when LCD on) for greater accuracy.

Fudgey,
- Thanks for the link to the discussion about power consumption in other modes, I hadn't seen it yet.
- I am not sure that using a camera mode that draws more current would improve the accuracy more than increasing the number of repeat measurements. The disadvantage of using another mode is the work of measuring a new value for P1.
- I guess that the blinking LEDs draw about 10mA for about 10% of the time, which is small compared to the current drawn by the rest of the camera. Maybe I'll add an option to disable the blinking LEDs.
- Right, a delay parameter was missing, I just added it (t). However, I am not sure that the delay needs to depend on the load, because the settling time of the measured voltage currently seems to be the fixed time interval of a running average
- Right, the script doesn't work when the camera is in PLAY-mode.
« Last Edit: 16 / November / 2008, 19:34:20 by Bagger288 »

#### Bagger288

• 8
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #4 on: 02 / December / 2008, 07:01:43 »
P1 and P2 should be known; I measured it once for my camera using a current meter:  1300 mW with LCD on, and 350 mW with LCD off  (camera model A720IS).
When you "switch" off the LCD on your A720, you switch off the LCD, the sensor & also the whole internal image processing, that's why there's such a big difference...the LCD itself has a much lower power consumption.

I finally measured the contribution of the LCD in my camera, and you are right:
Switching off only the LCD, by plugging a cable into the camera's AV-out terminal, merely reduces power consumption from 1300 to 1150 mW.
Switching off the whole bunch, either by pushing the DISP button or by running my script, reduces power consumption from 1300 to 350 mW.

#### kepler

• 11
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #5 on: 02 / July / 2011, 09:21:02 »
Hi, I'm trying to use this script but when I run it gives the error: "uBASIC: Unk stmt".

Any idea?

Thanks.

#### reyalp

• 14114
##### Re: Using chdk to measure the internal resistance of the batteries in the camera
« Reply #6 on: 02 / July / 2011, 17:49:55 »
Hi, I'm trying to use this script but when I run it gives the error: "uBASIC: Unk stmt".

Any idea?

Thanks.
You probably saved it in the wrong format. The script needs to be plain, ASCII text.
Don't forget what the H stands for.