Shop OBEX P1 Docs P2 Docs Learn Events
Inclinometer Resolution - ?Decimal? Math — Parallax Forums

Inclinometer Resolution - ?Decimal? Math

geometrixgeometrix Posts: 27
edited 2007-06-02 14:53 in BASIC Stamp
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

Comments

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-24 15:48
    value=((value MIN 1875 MAX 3125)-1875*20**47186-9000) '+/- 90.0 degrees, units of 0.01

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-24 15:50
    geometrix said...(trimmed)
    Sorry.· I am reposting because I accidentally left out the Subject.
    In the future please edit your original message to add the subject instead of reposting.· I have removed the duplicate post.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • geometrixgeometrix Posts: 27
    edited 2007-05-24 16:16
    Tracy,

    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-24 18:44
    There is info about how ** and */ work on my web site, here.

    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, nono.gif. 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. yeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/24/2007 6:49:02 PM GMT
  • marlord0marlord0 Posts: 8
    edited 2007-06-02 02:46
    I have a similar problem, I need to round off my the numbers that I get from my Accelerometer. I have it connected to servos and currently they are going crazy because how sensitive the Accelerometer is. So what would be a good short program that will take make the last digit 0.
  • geometrixgeometrix Posts: 27
    edited 2007-06-02 14:53
    Marlord0,

    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
Sign In or Register to comment.