This shows you the differences between two versions of the page.
20b:software-battery_level [2008/07/25 20:18] newell created |
20b:software-battery_level [2008/07/28 19:49] (current) newell Updated source to fix startup switch to Thumb mode. |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Proof of concept: battery level measurement ===== | ||
+ | |||
+ | ==== Description ==== | ||
+ | |||
+ | Demo program showing that it is possible to measure the battery voltage with the onboard brownout detector. | ||
+ | |||
+ | ==== Usage ==== | ||
+ | |||
+ | Boot calc into test mode (to allow stock firmware to configure and init the chip), | ||
+ | connect a debugger, halt the chip, download the image, and let 'er rip. | ||
+ | It'll probably corrupt anything you had in ram before. | ||
+ | |||
+ | ==== Download link ==== | ||
+ | |||
+ | | ||
+ | |||
+ | ==== Readme.txt ==== | ||
+ | |||
+ | Another sample program for the HP20B. | ||
+ | illustrate that the brownout detector can be used to probe for the | ||
+ | battery voltage. | ||
+ | |||
+ | The idea is that by ramping down the brownout threshold, we can find the | ||
+ | point at which the unit goes out of brownout mode. When the threshold | ||
+ | is above battery voltage, the brownout bit will be high. As the | ||
+ | threshold drops, eventually it will be less than the battery. | ||
+ | theshold at which the brownout bit was set can give us an approximate | ||
+ | measure of the battery voltage. | ||
+ | exactly linear. | ||
+ | |||
+ | The first few hex digits on the display are the last value of the power | ||
+ | supply controller status register. | ||
+ | brownout (threshold under battery), and 0x1d40 when in brownout (threshold | ||
+ | above battery). | ||
+ | (refer to the book for conversion to volts), and the rightmost digit is | ||
+ | the edge of brownout to no brownout. | ||
+ | |||
+ | Finally, the measured battery voltage is converted to decimal, scaled by | ||
+ | 10, and placed in the exponent area of the display. | ||
+ | |||
+ | The probe loop is intentionally slow, so that you can see the probe | ||
+ | process and brownout detector in action. | ||
+ | variable power supply and see the voltages change. | ||
+ | display is only updated at the end of the probe loop, so it'll be | ||
+ | several seconds before you see it change. | ||
+ | |||
+ | The keys are not scanned. | ||
+ | |||
+ | Runs from ram, Thumb mode, trashes memory, and requires some sort of JTAG | ||
+ | debugger to load and start the program. | ||
+ | address of 0x002FF000, in case your debugger can't figure it out. | ||
+ | |||
+ | Under OpenOCD, I do a “soft_reset_halt”, | ||
+ | battery_level.hex”, | ||
+ | wants to run in ARM mode, so be sure the core is set accordingly. | ||
+ | it jumps to main, it should switch cleanly into Thumb mode. (Or at | ||
+ | least it seems to for me, single-stepping through it.) | ||
+ | |||
+ | Disclaimer: Yes, the code is ugly. Fix it at your own risk. Consider it | ||
+ | nothing more than a toy to demonstrate that we know a little about the hardware. | ||
+ | |||
+ | Happy HP Hacking! | ||