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

Math questions

ArchiverArchiver Posts: 46,084
edited 2000-08-16 13:32 in General Discussion
I am new to this stamp math. I am trying to calculate voltage through
a 0831 A/D so that I can read out to 2 decimals: (251 = 13.99volts)
I know that if I can get:
2,510,000/1794 I can get 1399
and can display it as:
serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
to get 13.99, but how does stamp math accomplish this without going
over 65535? I'm sure many people have built stamp volt meters but I
am having a ball trying to make my own. Any hardware and code for
other volt meters are appreciated. Thanks in advance. Dan

PS. Has anyone come up with PocketPC/WinCE Stamp software yet?

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-08-11 00:17
    > I am new to this stamp math. I am trying to calculate
    > voltage through a 0831 A/D so that I can read out to
    > 2 decimals: (251 = 13.99volts) I know that if I can get:
    > 2,510,000/1794 I can get 1399
    > and can display it as:
    > serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
    > to get 13.99, but how does stamp math accomplish this
    > without going over 65535? I'm sure many people have
    > built stamp volt meters but I am having a ball trying
    > to make my own. Any hardware and code for other
    > volt meters are appreciated. Thanks in advance. Dan

    Hi Dan,

    One way to compute this on the BS2 is:

    X = X */ 1427

    which gives X=1399 out for X=251 in.

    */ in effect approximates the fraction, 1399/251~=1427/256.

    regards,
    -- Tracy Allen
    Electronically Monitored Ecosystems
    http://www.emesystems.com/BS2index.htm <-- more BS2 math stuff.
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-11 00:27
    Dan:
    You have to play around with factoring and approximations:

    2510000/1794=(627500*2*2)/(897*2)
    cancel one of the 2s
    =(627500*2)/897
    =(62750*10*2)/897
    now approximate 897 almost=900
    =(62750*10*2)/900
    =(62750*10*2)/(90*10)
    cancel the 10s
    =(62750*2)/90
    =(62750*2)/(45*2)
    cancel the 2s
    =62750/45 within 0.3% of correct, will fit stamp math limit.

    So instead of (X*10000)/1794, use
    (X*250)/45

    Bruce Reynolds has a voltmeter app at his site using the 0831 with BS2 code
    to read the A/D.
    http://www.rentron.com/Volt-Meter.htm

    Good luck,
    Ray McArthur

    > I know that if I can get:
    > 2,510,000/1794 I can get 1399
    > and can display it as:
    > serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
    > to get 13.99, but how does stamp math accomplish this without going
    > over 65535? I'm sure many people have built stamp volt meters but I
    > am having a ball trying to make my own. Any hardware and code for
    > other volt meters are appreciated. Thanks in advance. Dan
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-11 00:56
    Excellent, Tracy

    I wasn't familiar with this operator... your approximation is within 0.01%!

    One more thing I learned from this list.

    Ray McArthur

    > One way to compute this on the BS2 is:
    >
    > X = X */ 1427
    >
    > which gives X=1399 out for X=251 in.
    >
    > */ in effect approximates the fraction, 1399/251~=1427/256.
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-16 13:32
    I don't really remember who sent the original question. However, I have
    devised a very simple script to accomplish both the B2D and D2B conversions
    for the BS2. The BS1 should be even simpler as I don't believe you need the
    definition statements at the top of the attached script. However, you may
    need to "mess" with the "debug" statements as the syntax is different
    between the BS1 and BS2.
Sign In or Register to comment.