[comp.sys.handhelds] Fuel gauge program for the hp-28s.

peraino@gmu90x.gmu.edu (peraino) (02/02/90)

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