>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.
-----------------------------------------------------------------------------



     This is an update to the "fuel gauge" posting I sent out a few weeks
back. The original program I posted for low battery indication is wrong!
My thanx go to Rob Prior for noticing that the program wasn't quit right,
and that's putting it mildly! I'm surprised more people haven't wondered
about that program by now. Let's look at the original 
program;

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

     The nybble at FFF08 is the power indication. You need to read it more than
once because it is very sporadic. The problem is, when I finished the loop
for some strange reason (I claim temporary insanity) I treat the nybble as a
bit, and see if it turned up true all 5 times. This is WRONG, since it is a
nybble, and could conceivably add up to 4B, meaning, the thing would rarely
return a true result. Now concerning turning this into a fuel gauge, fixing
this program was simple, and you have your fuel gauge. Here is the CORRECT
program (I hope):

BAT [19CE]

<< 100 0 1 5
   START
    #FFF08h PEEK #Fh AND +
   NEXT
   B->R 75 / 100 * IP -
>>

     This program finds the AVERAGE of the nybble readings, and will be
accurate. It then converts the reading into a percentage of available
power. So with good batteries, it returns 100, and with lousy batteries,
it returns less than 100, down to 0. So this program is the fuel gauge, but
can also be used as the low battery indication, by including it into
a program like this:    ....... IF BAT NOT THEN ...
Of course this would only return true when the batteries are drained down
to the lowest levels. If you don't like waiting that long, then compare
the value to a threshold.
     One thing to keep in mind, though; The battery indication is NOT a
linear scale. BAT will read 100 percent for quite a while, and then start
to drop off at a fairly steady rate. It will definitely give you plenty
of advance warning, though, and so is quite effective as a "fuel gauge".
     I'm sorry for posting such shoddy "workmanship" previously. I don't
know what was going through my head at the time.



-----------------------------------------------------------------------------
       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.
-----------------------------------------------------------------------------

