Finding the change and direction of a signed word value (sensor output) ?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2008
    Posts
    96

    Default Finding the change and direction of a signed word value (sensor output) ?

    I'm being bogged down by the math involved in using a I2C pressure sensor to calculate true pressure, so I'm looking for a simpler course to just detect a positive or negative changes in it's output rather calculate than it's absolute value.

    At this point I only need to know if pressure is rising, falling, or steady. The sensor outputs a signed 16bit value.

    Has anybody seen or used some PBP code to compare a new Word value against a previous Word value to see if the difference is positive or negative, and by how much ?

    I'm short on bright ideas right now, so anything may help me get going the right way.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe something like this?

    If reading1 > reading2 then
    diff = reading1 - reading2
    else
    diff = reading2 - reading1
    endif

    Then maybe set a flag to know which calc was used?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb Supposing you build a barometer or altimeter ... using MS5534 or Hope HP03 ...

    Hi, Martin

    Assuming pressure will be read as i.e 1013.3 mb ( displayed number < 65536) ...

    the difference between two measures will be < 32768 ... ( or you will feel really really really bad !!! )

    sooo ...

    the MSB of the difference will be 0 for positive difference and 1 for neg difference... add to that PBP offers the direct print of the value and sign : " SDEC Difference "

    Alain
    Last edited by Acetronics2; - 17th May 2010 at 13:29.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    Assuming pressure will be read as i.e 1013.3 mb ( displayed number < 65536) ...

    the difference between two measures will be < 32768 ... ( or you will feel really really really bad !!! )

    sooo ...

    the MSB of the difference will be 0 for positive difference and 1 for neg difference... add to that PBP offers the direct print of the value and sign : " SDEC Difference "

    Alain
    The sensor is a Bosch BMP085. The actual raw un-compensated pressure value at about 260m (where I live) is -24200 in SDEC. I'm not sure what the range of values is going to be yet, I need to work that out yet (from sea level to say 1000m).

    I'll try out the SDEC Difference to see what it does too.

  5. #5
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Maybe something like this?

    If reading1 > reading2 then
    diff = reading1 - reading2
    else
    diff = reading2 - reading1
    endif

    Then maybe set a flag to know which calc was used?
    Thanks, that looks simple enough for a start tonight.

    I'd like to take the difference value and average it too, before deciding if the change is big enough to use and not just sensor noise. To average the raw output of the sensor needs 32bit math I think, so this has got to be easier for me.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The difference should be smaller than a WORD so if you do the average of a couple you should not need 32 bit math. If it does over flow the WORD then I think that would be telling you that the difference is larger enough to... make a difference
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    The difference should be smaller than a WORD so if you do the average of a couple you should not need 32 bit math. If it does over flow the WORD then I think that would be telling you that the difference is larger enough to... make a difference
    OK, yes I see that.
    Is there any drawback to averaging the difference between the numbers rather than the total of the numbers ?

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mr.sneezy View Post
    OK, yes I see that.
    Is there any drawback to averaging the difference between the numbers rather than the total of the numbers ?
    It sounds like you are after a relative measurement and not concerned withnthe actual so averaging the difference should be fine.

    Are you thinking the Difference values will be small enough to use more samples in the average? Should be on target then.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts