Help with calculation


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Default Help with calculation

    I need a little understanding with how the calculation of DIV32 function works. I have a part of calculation where results can vary from 8 bit to 32 bit.
    The following is causing problems and I would like to know how to avoid DIV32 when results are up to 16bit:

    Variable starting with 'w' are word sized
    wDummy=wTemp * (wWeight2-wWeight1)
    wTemp= DIV32 100 ' I do not want to use it if the result is up to 16 bit. But how to implement this check?

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: Help with calculation

    Well, probably something like this

    Code:
    wDummy=wTemp * (wWeight2-wWeight1)
    
    IF wDummy > 65536 THEN
       wDummy=wTemp * (wWeight2-wWeight1)  'This line needs to be before DIV32
       wTemp= DIV32 100
    ENDIF
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: Help with calculation

    @ first ...

    could you explain how DIV32 results can be > 16 bits ...

    Never seen that for 14 Years I use PBP !

    Ok, ...

    1) The "Dummy" variable must be < 32768 ... see Manual !

    2) IF you use DIV32 ... your program variables only can be < 16 Bits ( 65535 ), obvious, eh ! ( DIV32 doesn't work when LONGS used !!! )

    => soooo, how are you dealing with your supposed 16 -> 32 bits intermediate "results" ???

    BTW :
    Code:
    IF wDummy > 65536 THEN
    " another " compiler would have sent you the message
    Condition always TRUE
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Help with calculation

    Quote Originally Posted by Acetronics View Post
    @ first ...

    could you explain how DIV32 results can be > 16 bits ...

    Never seen that for 14 Years I use PBP !

    Ok, ...

    1) The "Dummy" variable must be < 32768 ... see Manual !

    2) IF you use DIV32 ... your program variables only can be < 16 Bits ( 65535 ), obvious, eh ! ( DIV32 doesn't work when LONGS used !!! )

    => soooo, how are you dealing with your supposed 16 -> 32 bits intermediate "results" ???

    BTW :
    Code:
    IF wDummy > 65536 THEN
    " another " compiler would have sent you the message

    DIV32 results are never over 16bits. What I meant is that my calculation in the following sentence

    wDummy=wTemp * (wWeight2-wWeight1)

    Can result in result of upto 16 bits, which is fine as wDummy can handle it. But in cases when it gets over 16bits for example if wTemp is 100 and result of the subtraction is 100 as well, DIV32 gets me what I want. i.e. 10,000 in this example.

    BUT the problem is that I am not sure if DIV32 is still doing something to my answer when the result is up to 16 bits as I would not like DIV32 to execute in this case. Hope I made myself more clear this time.

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