PDA

View Full Version : microns to decimal conversion



Rleonard
- 26th February 2007, 15:42
Micron to Decimal Conversion


I am using an 18F4431(and a 18F4550) with encoder inputs.
The development board is a LAB-XUSB.
The scale being used is in microns.
1 count = .0003937 inches.
I do not need the resolution the
encoder and scale provide but I need to
use this encoder and scale.

I will need to convert microns to
decimal for data logging.
I will need to perform a calculation
To see if the value falls outside of a
plus(+) or minus(-) point.
Example
.000 is the datum.
The deviation allowed is
+ or - .010. Therefore, if
the reading is .013 then the
unit has failed and I would
report this to the user.

I have tried using integers with no
success. I have not attempted
floating-point math. I do not
know how to incorporate the
routine into Pic Basis Pro at present.
I do not know which routines
of the samples provided to incorporate.
I am still studying a method to implement.

I need to be pointed in the right direction.

Any help will be appreciated.

Thank You.

Richard

Archangel
- 27th February 2007, 04:56
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

Rleonard
- 27th February 2007, 18:03
Thank You
Charles at microEngineering gave me a solution

mister_e
- 27th February 2007, 23:00
and thank you very much for sharing that with us !

Rleonard
- 28th February 2007, 14:37
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