Darrel pointed out that I could further reduce the equation, and I had the following error:
The range for A/D conversion is only from 0 to 1023, not 1024 like I had stated. Alain caught that too, but I missed that.
So to further simplify the equation (notice how complicated it is to simplify things?)
We start with the same thing we ended with in the last post.
P = (((result * 6775) / VS) - 271) / 25
Put in the known high range value for VS
P = (((result * 6775) / 1023) - 271) / 25
Don't be afraid of the decimals here ....
Dividing by 25 we get:
P = (((result * 271) / 1023) - 10.84)
271/1023 = .2649
P = (result * .2649) - 10.84
We can get there by .... (Thanks again Darrel!)
Code:
ADCIN 0, result
Pressure = result * 2649
Pressure = DIV32 1000
Pressure = Pressure - 108
LCDOUT DEC Pressure/10,".",DEC Pressure//10
The above code converts the .2649 to 2.649 by multiplying result * 2649, then dividing by 1000. It subtracts 10 x the 10.84 which averages out to 108. so the division by 10, and the remainder from the division by 10 can give accurate results.
And we can do all this without using slow, bloated, floating point code, available here:
<A Href="http://www.melabs.com/resources/fp.htm">Using Microchip's <b>Floating</b> Point routines with PicBasic Pro Compiler</a>
Bookmarks