[comp.sys.handhelds] a "fuel guage" for the 28s

peraino@gmu90x.gmu.edu (peraino) (12/31/89)

>From glenk@llama.UUCP Thu Dec 28 07:40:32 1989
>Subject: Want HP-28S fuel gauge, program name query

>  What about a "fuel gauge" for the 28?  I'd like a function that
>would return a real number between 0 & 1 indicating battery voltage,
>where 1 = new batteries, & 0 means the low-battery indicator was
>just triggered.  If it could report hours of continuous computation
>left, it would be a googol times GREATER (but that's too much to
>hope for!)!

   What you are looking for is not necessarily impossible to achieve. I'll give
you what you need, and the rest is, how they say, "a cake walk".

     One of the SYSEVALS recently discovered (sorry, I don't remember the 
exact number, and am too lazy to look it up) supposedly checks for low battery
indication, by returning 0 for normal batteries and 1 for low batteries. I
promptly put this SYSEVAL into a global function called BAT and figured my 
problems were solved. Lo, this was not the case. The first time my batteries
ran out, the BAT function was still returning a 0! Being perplexed, I contacted
the source for this SYSEVAL and the source was just as perplexed as I.
Apparently, the code at this address simply loops and checks the value at
address fff08 several times, to determine if the batteries are borderline.
This address apparently contains a zero for no, and a 1 for yes. The routine
samples the address several times, because of the "graininess" of the value;
as the batteries drop, a "1" will be present, statistically, more often than
a zero. So I decided to write my own battery function based on this
information. Simply, sample the value of this address five times. If a 1 was
returned all 5 times, then return a low battery indication. It works like
a charm! Here is the code:

  << 0 1 5 START
     #FFF08h PEEK
     #Fh AND + NEXT
     #5h SAME
  >>

     The basis of this code is like quantum mechanics; I can't really exactly
say WHY this address acts this way, but it does, and through observation,
we can say certain things about it. For instance, as the power level drops 
off, a value of "1" becomes more prevalent than "0". This means that as the
percentage of the presence of a "1" appearing at fff08 goes up over time,
the power of the batteries are going down. It is an academic matter of 
statistical observation to come up with a metric which maps this percentage
to battery life. For example, in the above code, instead of returning
a boolean, take the count, divide by 5, subtract from 1, and multiply by
100, and you would have a rough (almost jagged) percentage of battery life
remaining. Now, I would have tested this all a long time ago, except that
you need several sets of batteries in several states of decay, to really
PROVE how accurate this whole thing is. But if you want to play around,
you can try what I have suggested, with a set of old batteries. Of course
in the above example, the statistical value of this number may be in question
due to the low number of observations. But you have to consider that this is
a function which should return its answer fairly quickly. Therefore, I do not
recommend a value for the loop index higher than 10. As for using the above 
fucntion as-is, I have tested it with old and new batteries, and can say
with more than reasonable assuredness, that when it returns a 1, your
batteries are almost pooped!
   Good luck, god speed, and all that rot. And in gratitude, you can
post your results for the world to see.

>						Glen Kilpatrick
>                                               (916)756-9321home


-----------------------------------------------------------------------------
       Bob Peraino                   UUCP    : uunet!pyrdc!gmu90x!peraino
 George Mason University             INTERNET: peraino@gmuvax.gmu.edu
UCIS, Thompson Hall, rm 2 <-         BITNET  : peraino@gmuvax
  4400 University Drive     \        PHONE   : (703)-323-2549
   Fairfax, VA  22030        \- Yeah, they put us in the basement, too.
-----------------------------------------------------------------------------

oscar@zelator.UUCP (Carsten Tschach) (01/10/90)

Hello,
in one of the articles about "fuel guage" you uses a function called "PEEK"
I don't have this function on my 28S.
Is it posible to send me the source of it ?
Has someone information about Machinecode-programming.
Feel free to send me a E-Mail or back in this board.

.....!uunet!unido!tmpmbx!einoed!zelator!oscar