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
Bookmarks