Dennis Welbourn’s 8052 web page
Dennis Welbourn’s 8052 web page
I work with 8052-based monitoring systems, and as a result
do a lot of data converting, scaling and such.
All of my code
is integer arithmetic, no floating point.
So how do I handle converting say gallons to liters? Easy. The conversion factor is 3.7853, which just
happens to be pretty close to 53/14. So
I can multiply my value of gallons by 53 then divide by 14. If I multiply by 530 instead, I’ll have a
result in tenths of a liter.
OK, but maybe the result isn’t accurate enough? Well then use 617/63. Or maybe 670/177. Or maybe even 1957/517.
Now where did I come up with these values? I suppose I could try numbers and see how
close I could get, but instead I used the fractional equivalence equation
implemented in a spreadsheet. Enter the
floating point value then select the fraction that provides the accuracy that I
need. All I need to remember is to size
my variables to avoid overflow, mostly using unsigned variables and often using
unsigned int or unsigned long for intermediate
results, casting the final value back to the needed size.
See spreadsheet here.
Ever wondered what high voltage does to an integrated
circuit? Once upon a long time ago while
hooking up a teletype to a microprocessor development board, I found out the
hard way that someone had included 110VAC on one of the RS232 cable pins… zzzzzPOP! And the board stopped working. (Imagine that!) The AC line voltage went to the output pin of
a 7417 hex driver, which I opened and photographed. See the shiny crater and debris field around
it, along with the other damage caused before the bonding wire finally fused: picture