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


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    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.

  2. #2
    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.

  3. #3
    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 ?

  4. #4
    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 : 0

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