|
|
View previous topic :: View next topic |
Author |
Message |
pbrew1 Guest
|
64 bit math routines |
Posted: Sat Jun 26, 2004 12:52 am |
|
|
Does anyone know where I can get 64 bit math routines?
Especialy interested in 64 bit integer divide or multiply.
Thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1938 Location: Norman, OK
|
Just wondering why.... |
Posted: Sat Jun 26, 2004 8:51 am |
|
|
64bit math on an 14 bit processor!
Wow, I keep wondering how far folks will try to push a $5 PIC processor.... It sounds like it will be used to calculate the location of all the planets in 2050 along with the probability of a meteor collision with earth in the next 100 years...
And I just thought it was good for use as a hardware controller. What happened to the old IBM 360/30 which is better suited to what he wants to do?
Pardon my musing....but I couldn't help myself! |
|
|
Guest
|
|
Posted: Sat Jun 26, 2004 1:00 pm |
|
|
I am using the 18F series processor. I need it for calculating:steps to move = inches to move/inches per step. Its for a cnc machine. Without the precision it wont allways be acurate doun to the step. I need a 16 bit fixed or floating divide or multiply function. Will anyone sell me one?
thanks,
Paul |
|
|
Guest
|
|
Posted: Sat Jun 26, 2004 1:09 pm |
|
|
I meant to say 64 bit not 16 bit on last message |
|
|
Ttelmah Guest
|
|
Posted: Sat Jun 26, 2004 2:52 pm |
|
|
Anonymous wrote: | I am using the 18F series processor. I need it for calculating:steps to move = inches to move/inches per step. Its for a cnc machine. Without the precision it wont allways be acurate doun to the step. I need a 16 bit fixed or floating divide or multiply function. Will anyone sell me one?
thanks,
Paul |
Seriously, I have a couple of CNC systems here, and neither uses better than 32bit aritmetic. One offers a potential 'step size' (though the machine cannot achieve this), of 1/10000th mm, yet still has an acceptable range of over 200m. You should not need 64bit arithmetic for any real CNC system (except perhaps some of the CNC systems for milling objects like Airbus spars...). Use scaled 32bit integers, they are plenty accurate enough.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jun 26, 2004 3:40 pm |
|
|
I was intruiged by the question and have done some research.
Division in soft- and hardware is often implemented with an function called the "Booth's algorithm" which is a clever combination of "shift and subtraction". This algorithm contains a loop which has to be run for every bit, so 64 times in your example.
Just as a mental exercise I tried to estimate the number of instruction cycles such a function would take on a PIC processor. I took an 32-bit by 16-bit division code example of Booth's algorithm for an 8051 compatible processor, written in assembly it takes about 1307 instruction cycles. Extrapolated for a 64 bits division it takes a massive 3375 instruction cycles!!!
On the web I couldn't find any 64-bit division routines for an 8-bit microprocessor. This is a good indication that in the real world there are better solutions for your problem. As Ttelmah already mentioned, with a signed 32bit integer and a CNC with 0,1um per step you have a positive and negative range of 200m!
Have a closer look at your arithmetic, it's very likely that by shuffling a few instructions around you can do all your calculations with 32-bit arithmetic. |
|
|
Guest
|
|
Posted: Sat Jun 26, 2004 6:59 pm |
|
|
I am not good with math but this is how I figured I need more than 32 bit
divide function.
steps to move= inches to move / inches per step
inches to move 144
inches per step .00023459
steps to move=144/.00023459=613,836 (actual)
For the Pic:
multiply top and bottom by 10,000,000
(144*10,000,000)/(.00023459*10,000,000)=
1,440,000,000/2345.9
drop the .9
1,440,000,000/2345=614,072
difference between actual and calculated is 236 steps
or .055 inches |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
|
Posted: Sun Jun 27, 2004 1:35 am |
|
|
Anonymous wrote: | I am not good with math but this is how I figured I need more than 32 bit
divide function.
steps to move= inches to move / inches per step
inches to move 144
inches per step .00023459
steps to move=144/.00023459=613,836 (actual)
For the Pic:
multiply top and bottom by 10,000,000
(144*10,000,000)/(.00023459*10,000,000)=
1,440,000,000/2345.9
drop the .9
1,440,000,000/2345=614,072
difference between actual and calculated is 236 steps
or .055 inches |
Have you tried the CCS float ? |
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 27, 2004 2:48 pm |
|
|
Anonymous wrote: | I am not good with math but this is how I figured I need more than 32 bit
divide function.
steps to move= inches to move / inches per step
inches to move 144
inches per step .00023459
steps to move=144/.00023459=613,836 (actual)
For the Pic:
multiply top and bottom by 10,000,000
(144*10,000,000)/(.00023459*10,000,000)=
1,440,000,000/2345.9
drop the .9
1,440,000,000/2345=614,072
difference between actual and calculated is 236 steps
or .055 inches |
Approach it from the other direction. Store steps/1024 inches (or some similar large constant), as a 32bit integer. Also look carefully at your 'step' value (generally systems have either imperial or metric lead screws, and it is better to work in the same unit that the lead screw uses - the value you give, doesn't quite work as either a metric or imperial screw, with any likely step ratio).
So from the value you give, steps/1024 inches is:
4365062
Then calculate using multiplication, not division, and divide by the 'factor' at the end. So:
steps required = (144*4365062)>>10
gives 613836 steps
This is also much faster to solve than any floating point solution.
Best Wishes |
|
|
pbrew1 Guest
|
|
Posted: Thu Jul 01, 2004 4:40 pm |
|
|
Ttelmah,
The 140 whould actually have to be 140.999
and 140999 * 4365062 is greater than a 32 bit int. Is there a way to split the #s up to solve the problem?
Thanks for the info I used your method to solve other problems.
Paul |
|
|
cyril Guest
|
|
Posted: Fri Jul 02, 2004 3:39 pm |
|
|
(144*10,000,000)/(.00023459*10,000,000)=
1,440,000,000/2345.9
drop the .9
1,440,000,000/2345=614,072
If you use 2346 instead of 2345 (rounding the .9 up instead of dropping it)
the result (on my calculator) is 613,810.74 much closer (to actual) than the 614,072. If you drop the .74 the difference is 26 X .00023459 = .006" over 144 inches of travel.
Also this is what I get on a PIC using floats:
enter first float 144
enter second float .00023459
result = 613835.284113 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Jul 02, 2004 4:13 pm |
|
|
If you have been using .00023459 that is only 6 significant digits. Try.00023459034 for a more accurate value. The CCS float format uses 6.5 significant digits. |
|
|
Guest
|
|
Posted: Sun Jul 04, 2004 1:15 pm |
|
|
cyril wrote: | (144*10,000,000)/(.00023459*10,000,000)=
1,440,000,000/2345.9
drop the .9
1,440,000,000/2345=614,072
If you use 2346 instead of 2345 (rounding the .9 up instead of dropping it)
the result (on my calculator) is 613,810.74 much closer (to actual) than the 614,072. If you drop the .74 the difference is 26 X .00023459 = .006" over 144 inches of travel.
|
With a little trick you can get still better precision based on following approximation: a/(1-d) ~ a*(1+d) when d<<1.
1440,000,000/(2345.9) = 1440,000,000/(2346-0.1)
= 1440,000,000 / ( 2346 ( 1-0.1/2346))
~ 1440,000,000 * (1+0.1/2346) / 2346
= (1440,000,000 + 144,000,000/2346)/2346 which gives 613836
Erkki Malkam�ki |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|