'*/' operator


Closed Thread
Results 1 to 3 of 3

Thread: '*/' operator

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    */ is the MidWord multiplier.

    When you multiply 2 16-bit values together, you'll get up to a 32-bit result (4 bytes). The Midword, is the 2 bytes in the middle.

    For instance, let's say you have an A/D value of 600, and you multiply it times 5000, that gives you 3,000,000. And if you express that in Hexadecimal, it looks like ...
    002D:C6C0

    The MidWord is 2DC6, or 11,718.

    That's the same as (600 * 5000) / 256. The /256 is implied, and happens without the extra time required to do a division. So, it can be allot faster than using DIV32.

    The rest of the formula is, >> 2, or shiftright 2 places. Which is the same as /4. Since the result has already been divided by 256, /4 makes the total divisor equal to 1024 (256*4). And, the result will be 2,929, which represents 2.929 Volts input to the ADC.

    So, the whole formula is really just (600 * 5000) / 1024. But in a way that PBP can handle it with 16-bit numbers.<hr>
    OK, so how to go the other direction...
    I would like to take 0.01 to 0.250V
    You'll need the integer numbers (10 to 250) I'll call it Offset. Then just do the reverse formula.

    AD_Cal = (Offset * 1024) / 5000

    This one doesn't fit in with the */ operator, so you'll need to use DIV32.
    Code:
    Offset = 250          ; 0.250V - Must be a WORD Var
    AD_Cal = Offset * 1024
    AD_Cal = DIV32 5000
    This gives a result of 51, which can then be added or subtracted from the AD result as necessary.

    HTH,
    DT

  2. #2
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default supplement

    To supplement Darrel's example/description, I'd suggest looking HERE for some good examples.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. ISD17240 on PIC16F88
    By drewcog in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th December 2008, 21:07
  2. what is objective of this operator "*/" ?
    By iugmoh in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th April 2008, 03:43
  3. Exponential Operator
    By andrewroz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st October 2007, 09:00
  4. Help to Get The highest value in Array
    By jetpr in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th August 2005, 12:09
  5. math operator LOG
    By Eyal in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd July 2004, 00:45

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