Skip to contentSkip to conversation

better battery sensing code for collie

FYI Pavel Machek 1 participant 1 message Jul 12, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Hi!

I played a bit with battery sensing code, and found out that default sharp thresholds only use 40% (!) of my battery capacity. Collie seems to work down to 3.35V.. I even added the code to guess current power consumption, and compute internal battery voltage, so guesses should be less depended on backlight settings.

(Internal battery resistance seems to be ~1ohm, unfortunately changes with charge).

More precise values would be welcome, as would be some temperature calibration.

Here are relevant parts of my diff... One possible message is "having values in miliVolts actually has some benefits". Perhaps we could even share voltage tables between different zauruses... I can use collie (sl-5500) battery in spitz (c-3000) just fine, for example.

Pavel

Documentation/collie-battery.txt new file +180 -0
new file mode 100755
index 0000000..6c132c0
@@ -0,0 +1,180 @@
+#!/bin/bash
+( 
+  while true; do
+	read hour min volt rem || exit
+	t=$[$hour*60 + $min - 4*60 - 7]
+	percent=$[100*$t /146]
+	percent=$[100-percent]
+#	echo $t $volt $percent '#' $rem; 
+	echo "	{ $volt, $percent }, /* at $t minutes was $rem */ "
+done ) < collie-battery.raw
+exit
+
+132mA base system
++103mA for 25% backlight
++155mA for 50% backlight
++270mA for 75% backlight
++450mA for 100% backlight
++284mA for audio + cpu (mp3 playback)
+
+(with default brightness)
+3:10 (approx): collie reports charge full. Battery is at 4.2V most of the time.
+3:57 still charging?
+4:07 started discharge
+
+4:07 killed charger: 398, 100% and 401, 100%
+4:10 396, 100%
+4:12 394, 100%
+4:14 392, 100%
+4:15 390, 90%
+4:19 388, 90%
+4:22 386, 90%
+4:24 385, 85%
+4:28 381, 85%
+4:29 380, 80%
+4:31 379, 80%
+4:33 378, 80%
+4:35 377, 80%
+4:37 376, 80%
+4:39 375, 70%
+4:40 374, 70%
+4:42 373, 70%
+4:45 372, 70%
+4:49 370, 60%
+4:53 368, 60%
+4:55 364, 50%
+4:59 362, 40%
+5:02 360, 30%
+5:05 359, 30%
+5:07 autosuspend :-(
+5:08 357, 0%
+5:10 358, 0%
+5:11 356, 0%
+5:13 356, 0%
+5:16 357, 0%
+5:18 357, 0%
+5:21 355, 0%
+5:23 355, 0%
+5:24 354, 0%, turned brightness to 0
+5:24 366, 0% (on brighness 0)
+5:25 turned brighness to 2.
+5:27 354, 0%
+5:28 353, 0%
+5:31 352, 0%
+5:32 352, 0%
+5:37 351, 0%
+5:39 350
+5:42 349
+5:44 350
+5:47 349
+5:49 348
+5:52 347
+6:00 345
+6:02 345, turned brighness to 0
+6:03 357 (on brighness 0), 359, 360, brightness = 2
+6:08 343
+6:11 341
+6:15 339
+6:16 338
+6:18 337
+6:19 335
+6:21 334
+6:23 332 I start to see artifacts on screen.
+6:24 330
+6:25 327
+6:28 326, brightness = 0
+6:28 344, 345, 345, 346, brightness = 2
+6:32 318
+6:33 315 
+
+6:34 312 display failed, start charging.
+6:35 402 55%
+6:36 406 60%
+6:37 410 60%
+6:39 413 65%
+6:41 414 65%
+6:45 414 65%
+6:46 415 65%
+6:50 416 70%
+6:54 417 70%
+6:59 418 75%
+7:00 AC unlpuged
+7:00 374 70%
+7:01 367 0%
+7:02 366 0%
+7:02 AC replugged
+7:03 414 65%
+7:06 417 70%
+7:08 418 75%
+
+U_observed = U_battery - R_battery * current
+
+R_battery = (U_observed_1 - U_observed_2) / (current_2 - current_1)
+
+16:03: R_battery = (3.45 V - 3.59 V) / (132 mA - 132 mA - 155 mA) \ ohm = 0.9032 Ohm
+sanity check:
+15:23: R_battery = (3.54 V - 3.66 V) / (132 mA - 132 mA - 155 mA) \ ohm = 0.7742 Ohm
+16:28: R_battery = (3.28 V - 3.46 V) / (132 mA - 132 mA - 155 mA) \ ohm = 1.1612 Ohm
+
+6:34-4:07: battery lasted 2:27 == 147 minutes.
+
+time voltage percent old_percent
+================================
+0 401 100 #
+3 396 98 # 100%
+5 394 97 # 100%
+7 392 96 # 100%
+8 390 95 # 90%
+12 388 92 # 90%
+15 386 90 # 90%
+17 385 89 # 85%
+21 381 86 # 85%
+22 380 85 # 80%
+24 379 84 # 80%
+26 378 83 # 80%
+28 377 81 # 80%
+30 376 80 # 80%
+32 375 79 # 70%
+33 374 78 # 70%
+35 373 77 # 70%
+38 372 74 # 70%
+42 370 72 # 60%
+46 368 69 # 60%
+48 364 68 # 50%
+52 362 65 # 40%
+55 360 63 # 30%
+58 359 61 # 30%
+61 357 59 # 0%
+63 358 57 # 0%
+64 356 57 # 0%
+66 356 55 # 0%
+69 357 53 # 0%
+71 357 52 # 0%
+74 355 50 # 0%
+76 355 48 # 0%
+77 354 48 # 0%
+80 354 46 # 0%
+81 353 45 # 0%
+84 352 43 # 0%
+85 352 42 # 0%
+90 351 39 # 0%
+92 350 37 #
+95 349 35 #
+97 350 34 #
+100 349 32 #
+102 348 31 #
+105 347 29 #
+113 345 23 #
+121 343 18 #
+124 341 16 #
+128 339 13 #
+129 338 12 #
+131 337 11 #
+132 335 10 #
+134 334 9 #
+136 332 7 #
+137 330 7 #
+138 327 6 #
+141 326 4 #
+145 318 1 #
+146 315 0 #
arch/arm/common/sharpsl_pm.c +65 -9

186 lines not on this page · raw message

arch/arm/mach-sa1100/collie_pm.c +156 -26

258 lines not on this page · raw message

drivers/video/backlight/locomolcd.c +6 -6
index caf1eca..4c2e888 100644
@@ -109,6 +109,7 @@ EXPORT_SYMBOL(locomolcd_power);
 
 
 static int current_intensity;
+int backlight_current;
 
 static int locomolcd_set_intensity(struct backlight_device *bd)
 {
@@ -123,12 +124,11 @@ static int locomolcd_set_intensity(struc
 
 	switch (intensity) {
 	/* AC and non-AC are handled differently, but produce same results in sharp code? */
-	case 0: locomo_frontlight_set(locomolcd_dev, 0, 0, 161); break;
-	case 1: locomo_frontlight_set(locomolcd_dev, 117, 0, 161); break;
-	case 2: locomo_frontlight_set(locomolcd_dev, 163, 0, 148); break;
-	case 3: locomo_frontlight_set(locomolcd_dev, 194, 0, 161); break;
-	case 4: locomo_frontlight_set(locomolcd_dev, 194, 1, 161); break;
-
+	case 0: backlight_current = 0; locomo_frontlight_set(locomolcd_dev, 0, 0, 161); break;
+	case 1: backlight_current = 103; locomo_frontlight_set(locomolcd_dev, 117, 0, 161); break;
+	case 2: backlight_current = 155; locomo_frontlight_set(locomolcd_dev, 163, 0, 148); break;
+	case 3: backlight_current = 270; locomo_frontlight_set(locomolcd_dev, 194, 0, 161); break;
+	case 4: backlight_current = 450; locomo_frontlight_set(locomolcd_dev, 194, 1, 161); break;
 	default:
 		return -ENODEV;
 	}
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html