Shop OBEX P1 Docs P2 Docs Learn Events
Math with the BS2 — Parallax Forums

Math with the BS2

ArchiverArchiver Posts: 46,084
edited 2003-03-13 06:30 in General Discussion
I am new to the Basic Stamp.
I am trying to take a pressure reading through the LTC1298 ADC
I get the input fine.
The problem is when I try to do the math to convert the pressure to mb.
I am using the formula:

pressure=AD*p01/p02+p03

where p01=137
p02 = 591
and p03 = 512

AD ranges in value from about 1100 to 2400

with AD = to about 2130 My output should read 1005
Instead, I am getting a reading of 567

I have tried using numbers instead of variables as well as the
following lines.

pressure=AD*p01
pressure=pressure/p02
pressure=pressure+p03

All result in the same incorrect answer.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-03-13 05:35
    I don't fully understand the formula you are using however, I have have two
    suggestions. If p01, p02, and p03 are constants - that is they do not
    change, why not figure out what p01/p02+p03 equals and multiply AD by that.
    That would eliminate alot of math from your BS2. Also, not sure of specifics
    with BS2 but most computers handle division before addition. I believe the
    precedence goes mult, div, add, subtract. This would greatly affect the
    outcome of your equation. If indeed you do want p01/p02 done first this
    yields 0.2318... again I'm not sure how the bs2 handles number this small
    perhaps rounds to nearest integer (0 or 1).

    Hope this helps

    Original Message
    From: "dillocam" <cedwards@c...>
    To: <basicstamps@yahoogroups.com>
    Sent: Wednesday, March 12, 2003 9:11 PM
    Subject: [noparse][[/noparse]basicstamps] Math with the BS2


    > I am new to the Basic Stamp.
    > I am trying to take a pressure reading through the LTC1298 ADC
    > I get the input fine.
    > The problem is when I try to do the math to convert the pressure to mb.
    > I am using the formula:
    >
    > pressure=AD*p01/p02+p03
    >
    > where p01=137
    > p02 = 591
    > and p03 = 512
    >
    > AD ranges in value from about 1100 to 2400
    >
    > with AD = to about 2130 My output should read 1005
    > Instead, I am getting a reading of 567
    >
    > I have tried using numbers instead of variables as well as the
    > following lines.
    >
    > pressure=AD*p01
    > pressure=pressure/p02
    > pressure=pressure+p03
    >
    > All result in the same incorrect answer.
    >
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-03-13 06:30
    Try this:

    pressure = AD ** 15192 + 512

    The Stamp approximates your fraction, 137/591, with this one:
    15192/65536. The division by 65536 is implied in the ** operator.

    In straight multiplication, 2130*137 would be 291810, but the Stamp
    gets it wrong, 29666, because of its 16-bit word size. The **
    operator avoids the problem.

    -- Tracy


    >I am new to the Basic Stamp.
    >I am trying to take a pressure reading through the LTC1298 ADC
    >I get the input fine.
    >The problem is when I try to do the math to convert the pressure to mb.
    >I am using the formula:
    >
    >pressure=AD*p01/p02+p03
    >
    >where p01=137
    >p02 = 591
    >and p03 = 512
    >
    >AD ranges in value from about 1100 to 2400
    >
    >with AD = to about 2130 My output should read 1005
    >Instead, I am getting a reading of 567
    >
    >I have tried using numbers instead of variables as well as the
    >following lines.
    >
    >pressure=AD*p01
    >pressure=pressure/p02
    >pressure=pressure+p03
    >
    >All result in the same incorrect answer.
Sign In or Register to comment.