Cecil W. Soileau wrote: How do I raise a variable, X to a Power of 1.197 in my Stamp2 Basic language
cmooneyg
Posts: 4
in BASIC Stamp
I am trying to use a Sharp GP2Y0A21YK0F distance measuring ir emitter/irtransistor module with an ADC0831 converter, which reads the voltage coming out of the Sharp DME. the problem is that the voltage is not leaner function of the distance, but is instead an inverse function of the distance to the object being sensed. My problem then is how do I take the value read and raise it to a power of 1.197. The equation I need to solve is: Y = 27.639/X^1.197. So X the voltage read from the ADC0831 must be converted to a distance in millimeters, via a solution to this equation.
Comments
-Phil
y = 27.639/(x^1.197)
mm = 3072.34 / count ^ 1.197 ' where millimeters is a function of count from 0 to 256.
No need to convert to millivolts.
Next, make your table for only the range that you need, cut off the values that are too far distant. Those are the low values of count. For example, cut off the values below count 16, greater than 100mm distant.
I'd also consider making the table as a function of 1/x instead of proportional to x directly. The graph of 1/x will be almost linear. Commensurately, the Stamp would have to compute 1/x in real time by computing 10000/x or 65535/x. At that point the table lookup is better, and even a quadratic approximation with r^2>0.99 is possible.