Shop OBEX P1 Docs P2 Docs Learn Events
BS2p Math — Parallax Forums

BS2p Math

ArchiverArchiver Posts: 46,084
edited 2002-08-14 17:54 in General Discussion
I am reading a 12 bit A/D that is connected to a pressure sensor that
is trimmed up to 2.5V so that I can measure vacuum.

The pressure sensor outputs 150 mV/PSI and I want to then convert
this to inches of Hg which 1 PSI = 2.036021 inHg.

Right now I can zero out the reading by:

Zero = 2500 - CH_0

Which is a no brainer but ,

PSI = Zero/150

just gives me a whole number thats rounded off???

Once I have this PSI converson done I think I can convert to inHg
with this:

inHg = (PSI * 2) + (PSI ** 2361)

Need help with division.

Jason

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-08-14 03:40
    You have to excuse my previous brain fart.

    If I take (Zero * 10)/15 then I get an acceptable amount of
    resolution.

    Unless any of you out there have a better way to do it.

    Jason


    --- In basicstamps@y..., "jbirnsch" <jbirnsch@v...> wrote:
    > I am reading a 12 bit A/D that is connected to a pressure sensor
    that
    > is trimmed up to 2.5V so that I can measure vacuum.
    >
    > The pressure sensor outputs 150 mV/PSI and I want to then convert
    > this to inches of Hg which 1 PSI = 2.036021 inHg.
    >
    > Right now I can zero out the reading by:
    >
    > Zero = 2500 - CH_0
    >
    > Which is a no brainer but ,
    >
    > PSI = Zero/150
    >
    > just gives me a whole number thats rounded off???
    >
    > Once I have this PSI converson done I think I can convert to inHg
    > with this:
    >
    > inHg = (PSI * 2) + (PSI ** 2361)
    >
    > Need help with division.
    >
    > Jason
  • ArchiverArchiver Posts: 46,084
    edited 2002-08-14 17:54
    Hi Jason,

    I see you answered your own question. Here is another way to do it,
    by working with the remainder from the first division:

    PSI = ch_0/150*100 + (ch_0//150*100/150) - 1666
    ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ ^^^^
    1st division remainder division offset

    example, when ch_0=1234 then PSI= -844 to represent -8.44.

    Note that division on the Stamp does not work right on negative
    numbers, so if negative numbers might turn up, I always subtract the
    offset _after_ doing the division. Your result ch_0 I think is
    positive from the 12 bit A/D. 1666=2500/150*100 precalculated.

    You trick for division is fine, using 15 instead of 150. The only
    advantage of the "remainder" method above would come if your scale
    factor happened to be, say, 153 instead of 150.

    I hope that helps!

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com


    >You have to excuse my previous brain fart.
    >
    >If I take (Zero * 10)/15 then I get an acceptable amount of
    >resolution.
    >
    >Unless any of you out there have a better way to do it.
    >
    >Jason
    >
    >
    >--- In basicstamps@y..., "jbirnsch" <jbirnsch@v...> wrote:
    > > I am reading a 12 bit A/D that is connected to a pressure sensor
    >that
    > > is trimmed up to 2.5V so that I can measure vacuum.
    > > The pressure sensor outputs 150 mV/PSI and I want to then convert
    > > this to inches of Hg which 1 PSI = 2.036021 inHg.
    > > Right now I can zero out the reading by:
    > > Zero = 2500 - CH_0
    > > Which is a no brainer but ,
    > > PSI = Zero/150
    > > just gives me a whole number thats rounded off???
    > > Once I have this PSI converson done I think I can convert to inHg
    > > with this:
    > > inHg = (PSI * 2) + (PSI ** 2361)
    > > Need help with division.
    > > Jason
Sign In or Register to comment.