Inclinometer Resolution - ?Decimal? Math
geometrix
Posts: 27
All,
Sorry.· I am reposting because I accidentally left out the Subject.
I am trying to get more resolution (less roundoff) from a Memsic 2125 Accelerometer.· I looked at the code below from Smart Sensors and Applications and changed the output range from -127 to 127 TO -90 to 90.· I am aware that the BS microcontrollers can only do integer math.· On the other hand, how can I multiply the scaling factor either by 10 or by 100 in order to capture the resolution without going over the 16-bit limits???· See code below.· Instead of trying to show 90.25 degrees, I would like to show 9025 degrees.
Thanks,
Neal
' {$STAMP BS2}
' {$PBASIC 2.5}
'TestScaleOffset.bs2
value VAR Word
DEBUG CLS, "Enter values (1875 to 3125)> ", CR
DO
· DEBUG ">"
· DEBUGIN DEC value
····· value=((value MIN 1875 MAX 3125)-1875**9437-90)*100·· '+/- 90 degrees
· DEBUG "scaled to ", SDEC value, CR
LOOP
Sorry.· I am reposting because I accidentally left out the Subject.
I am trying to get more resolution (less roundoff) from a Memsic 2125 Accelerometer.· I looked at the code below from Smart Sensors and Applications and changed the output range from -127 to 127 TO -90 to 90.· I am aware that the BS microcontrollers can only do integer math.· On the other hand, how can I multiply the scaling factor either by 10 or by 100 in order to capture the resolution without going over the 16-bit limits???· See code below.· Instead of trying to show 90.25 degrees, I would like to show 9025 degrees.
Thanks,
Neal
' {$STAMP BS2}
' {$PBASIC 2.5}
'TestScaleOffset.bs2
value VAR Word
DEBUG CLS, "Enter values (1875 to 3125)> ", CR
DO
· DEBUG ">"
· DEBUGIN DEC value
····· value=((value MIN 1875 MAX 3125)-1875**9437-90)*100·· '+/- 90 degrees
· DEBUG "scaled to ", SDEC value, CR
LOOP
Comments
value=((value MIN 1875 MAX 3125)-1875*2**47186-900) '+/- 90.0 degrees, units of 0.1
The actual resolution based on 1250 steps and the scale factor, will be around 0.15.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thank you. This solves my problem. I do not fully understand the "**" operator and how you arrived at this equation. The scaling constant is INT(65536*(900/12500)). Why not 1800 in the numerator? Why did you multiply by 20?
I played and played with the numbers prior to posting my last question and I came up with several equations for VALUE that were close but no cigar.
--Neal
In your initial equation, you multiplied by 100 at the end, which makes the result always 00 in the units and tens position. To fill in those digits, you have to do the same thing within the ** operator. The 47186 comes from a calcullator, rounding off.
65536 * 5 * 180/1250 = 47186
The logic: The full scale input is 1250, 180 output, and multiply times 5 to maximize precision . I'd multiply times 10, but that would put the multiplier over 2^16, . The multiply by the factor of 20 or factor of 2 makes the overall factor 100 or 10, just as in your original equation. It is best to do that before the **, again to maintain precision. The full scale value 1250 can be multiplied by either 2 or 20 and still be less than 65536.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 5/24/2007 6:49:02 PM GMT
My problem was that I was not getting enough resolution.· I will actually be upgrading to a Propeller Microcontroller (PropSTICK USB) to take advantage of the floating point math capabilities.
Your problem seems to be that you are getting too much resolution.· I have three suggestions:
1)· It is easier to get less resolution than more with a given set of hardware (i.e. 8-bit ADC with BS2 that can only do integer math).· If you are having problems with too much resolution, then just divide through by a factor of 10.· Then·125 degrees will become·12.5 degrees which rounds down to·12 degrees using integer math.· Then, everytime you see·12 degrees, you can interpret this as·120 degrees.
2) Use a resistor and capacitor on all accelerometer outputs to ADC and/or all ADC outputs to the Basic Stamp Microcontroller to help filter out any possible noise.
3) Swap out the accelerometer for one that has less range (i.e. plus/minus 10 degress instead of plus/minus 90 degrees)
--Neal