Shop OBEX P1 Docs P2 Docs Learn Events
Math operations on 24 bits values — Parallax Forums

Math operations on 24 bits values

ArchiverArchiver Posts: 46,084
edited 2001-02-01 20:13 in General Discussion
Hello,
AD7730 is 24/16 bits A/D contains 24 bits calibration registers and I may
need to read back the calibration coefficient and multiply it by a
fractionary number.
So, can I perform math operations on 24 bits values with BS2?

Thank You
Mohamed Refky



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-01-23 21:26
    >Hello,
    >AD7730 is 24/16 bits A/D contains 24 bits calibration registers and I may
    >need to read back the calibration coefficient and multiply it by a
    >fractionary number.
    >So, can I perform math operations on 24 bits values with BS2?
    >
    >Thank You
    >Mohamed Refky

    Hi Mohamed,

    Yes. :-)

    The method will depend on whether you know the "fractionary number"
    in advance at compile time, or if it will come from data collected at
    run time.

    There is some general information on double precision math at
    http://www.emesys.com/BS2math6.htm
    but please ask if you have a specific numerical example.

    -- Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-23 23:08
    As Tracy pointed out, there are specific tricks you can use depending on
    your situation. Another possibility is to use a PAK-I or PAK-II math
    coprocessor. These use 32-bit floating point numbers and have a facility for
    loading/storing 24-bit integers (there is 24-bits of mantissa and 8 bits of
    exponent). Read more at http://www.al-williams.com/awce/pak1.htm

    Regards,

    Al Williams
    AWC
    * Connect a PS/2 keyboard to your Stamp!
    http://www.al-williams.com/awce/pak6.htm


    >
    Original Message
    > From: Mohamed REFKY [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=t_-oEN0inJzko3_8yTs5ICCaAHqmaO9t9vRidjYTbPSZp9K1D-0pC7svNzJt7Pdkc8hzsXf09LaG]refky@h...[/url
    > Sent: Monday, January 22, 2001 3:44 PM
    > To: basicstamps@egroups.com
    > Subject: [noparse][[/noparse]basicstamps] Math operations on 24 bits values
    >
    >
    > Hello,
    > AD7730 is 24/16 bits A/D contains 24 bits calibration registers and I may
    > need to read back the calibration coefficient and multiply it by a
    > fractionary number.
    > So, can I perform math operations on 24 bits values with BS2?
    >
    > Thank You
    > Mohamed Refky
    >
    >
    >
    > _________________________________________________________________________
    > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-24 19:02
    Typical calibration coefficient is 5877479 multiplied by 2.5 which I know
    in advance.

    >From: Tracy Allen <tracy@e...>
    >Reply-To: basicstamps@egroups.com
    >To: basicstamps@egroups.com
    >Subject: Re: [noparse][[/noparse]basicstamps] Math operations on 24 bits values
    >Date: Tue, 23 Jan 2001 13:26:46 -0800
    >
    > >Hello,
    > >AD7730 is 24/16 bits A/D contains 24 bits calibration registers and I may
    > >need to read back the calibration coefficient and multiply it by a
    > >fractionary number.
    > >So, can I perform math operations on 24 bits values with BS2?
    > >
    > >Thank You
    > >Mohamed Refky
    >
    >Hi Mohamed,
    >
    >Yes. :-)
    >
    >The method will depend on whether you know the "fractionary number"
    >in advance at compile time, or if it will come from data collected at
    >run time.
    >
    >There is some general information on double precision math at
    > http://www.emesys.com/BS2math6.htm
    >but please ask if you have a specific numerical example.
    >
    > -- Tracy Allen
    > electronically monitored ecosystems
    > http://www.emesystems.com
    >
    >
    >
    >

    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
  • ArchiverArchiver Posts: 46,084
    edited 2001-02-01 20:13
    >Dear Sir,
    >A typical calibration coefficient is 5877479 multiplied by 2.5 which
    >I know in advance.How to perform multiplication?
    >
    >Thank You
    >Mohamed Refky
    >
    >>From: Tracy Allen <tracy@e...>
    >>Reply-To: basicstamps@egroups.com
    >>To: basicstamps@egroups.com
    >>Subject: Re: [noparse][[/noparse]basicstamps] Math operations on 24 bits values
    >>Date: Tue, 23 Jan 2001 13:26:46 -0800
    >>
    >>>Hello,
    >>>AD7730 is 24/16 bits A/D contains 24 bits calibration registers and I may
    >>>need to read back the calibration coefficient and multiply it by a
    >>>fractionary number.
    >>>So, can I perform math operations on 24 bits values with BS2?
    >>>
    >>>Thank You
    >>>Mohamed Refky
    >>
    >>Hi Mohamed,
    >>
    >>Yes. :-)
    >>
    >>The method will depend on whether you know the "fractionary number"
    >>in advance at compile time, or if it will come from data collected at
    >>run time.
    >>
    >>There is some general information on double precision math at
    >> http://www.emesys.com/BS2math6.htm
    >>but please ask if you have a specific numerical example.
    >>
    >> -- Tracy Allen
    >> electronically monitored ecosystems
    >> http://www.emesystems.com

    The multiplier 2.5 is particularly easy, because it is made up of
    powers of two. A fast ad-hoc routine using shifts can do it:

    x0 var word ' x1:x0 initial value
    x1 var word
    y0 var word ' y1:y0 result=2.5 * initial value
    y1 var word
    yf var word ' helper variable
    ' 5877479 example as 24 bit binary number is $59aee7 in HEX
    ' held in x1:x0 as x1=$59, x0=$aee7
    ' the result should be y1:y0=$e03541
    x1=$59
    x0=$aee7
    yf=x0>>1 | x1.bit0 ' 32 bit shift 1 right to low word (low word of /2)
    y1=(x1<<1 | x0.bit15) + (x1>>1) ' high word of result,
    ' first term is times 2
    ' second term is /2
    y0 = x0<<1 + yf ' low word, times 2, plus the fractional part
    y1 = y1 + (yo max yf - yf max 1) ' add possible carry to high word
    debug ihex4 x1,hex4 x0," *2.5= ",ihex4 y1,hex4 y0,cr
    end

    The carry term in the above is calculated. [noparse][[/noparse]y1 = y1 + (yo max yf - yf
    max 1)] is equivalent to:
    if y0>=yf then nocarry
    y1=y1+1 ' add carry
    nocarry:


    If the multiplier is something more complicated than 2., then a more
    general approach will be called for. Let me know if you need that.

    -- Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
Sign In or Register to comment.