microns to decimal conversion


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Integer math

    Hello Richard,
    Micron is 1 million'th of a meter.
    Millimeter is 1/1000 of a meter
    millimeter to decimal is mm * 25.4 = 1.000 inch
    so , if I did my math correctly (there is some doubt) 25,400 microns to the inch

    PICs in P basic Pro only do Integer Math.
    16 bit data bus only holds 65535 data bits.
    Seems as though a PIC should hold about 2.58 inches worth

    Do a search on DIV32, Darrel and some others have many threads and ideas.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Jan 2007
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Micron to Decimal Conversion

    Thank You
    Charles at microEngineering gave me a solution

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    and thank you very much for sharing that with us !
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jan 2007
    Posts
    8


    Did you find this post helpful? Yes | No

    Default micron to decimal conversion

    Charles first sent this email
    and the followed up with the second email


    First Email:
    If you'll give me a more specific example of the math, I may be able
    to help you with a method. The solution depends mostly on the range
    of measurement (the maximum count from the encoder).

    Can you just scale everything up to work in Word variables? If all
    you need a resolution of .001, you can use a 16 bit integer to hold a
    number up to 65.535.

    In this case, the math to convert the encoder count to the scaled
    decimal would be:

    decimal = count ** 25802 ' same as (count * 25802 / 65536)

    See the Upper 16 multiply operator (**) in section 4.17.1 of the
    manual.

    Since the count can't be allowed to exceed 65535 in this calculation,
    the resulting scaled decimal number will max at 25801 (25.801).

    This same method could (probably) be expanded to use 32-bit numbers.

    If you can help me understand what you need, I can either give you
    some math or estimate consulting time to do it for you (depending on
    the scope). Shoot some holes in my method above and I'll try to
    overcome.

    Charles Leo
    microEngineering Labs, Inc.
    http://microengineeringlabs.com


    Second Email:
    The ** operator multiplies two 16-bit numbers and then returns only
    the top half of the 32-bit result.

    You can think of this as a normal multiply that has a built-in
    division by 65536 to shrink the number into 16-bits.

    x = y ** 25802

    can also be written (outside of PBP) as:

    x = (y * 25802) / 65536

    Since you needed (x = y * .3937), I did the math to come up a number
    that would equal .3937 when divided by 65536:

    x / 65536 = .3937

    Solving for x, the result is 25801.52. Rounding to the next highest
    integer yielded 25802.

    Charles Leo
    microEngineering Labs, Inc.
    http://microengineeringlabs.com



    Thanks to all

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. Decimal to fraction conversion
    By tico in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 29th April 2007, 16:54
  3. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  4. Decimal to Binary Conversion
    By schlaray in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2006, 14:58
  5. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 20:05

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