PDA

View Full Version : math help



houa
- 26th January 2006, 22:45
if any can help i would really appreciate it

here's the problem

A=.082
B=4.15
C=94.2
D=76.76

AA=A*B
BB=C*D
X=-75.12+AA-BB

E=101
CC=E*E
F=EE/301.6
Y=F*703

I read that pic basic pro doesn't support floating point numbers
so how can i approach this problem?

Is there an include file i can include to my problem?
Is there a procedure to follow to calculate my answers
I need to display it with 3 decimals places as well

Any help will be appreciated
thanks for looking

Jerson
- 30th January 2006, 13:36
This is a typical problem of small systems which do not have native floating point support / coprocessors.

Perhaps you should consider using 24/32 bit integers for this function. You will have to write your own functions for this or search for an app note which does this. Alternately, you may look at the microchip website for the floating point code and port it to your application though I can say it will be a lot of code and slow at that.

To do the long integer math, you can multiply each number by 1000 and then compute the result. When you get the result, divide it by 1000 to get the integer part and keep the modulus of 1000 as the fractional part to display

Jerson

Bruce
- 30th January 2006, 15:12
See this site: http://www.emesystems.com/BS2index.htm

Acetronics2
- 30th January 2006, 16:58
Hi, Houa

The first step is to use the brain ...

by multiplying a per 1000 and B per 100 ... you get integers, and so on.

AA = 34 030 * 1E-5
BB = 7 230 792 * 1E-3 ... over 16 bits, so,The second step is to define the precision of the result you want ...

X = - 7 305.5717 ok ... but what is the real meaning of the last digits ???

Here you find THE GOOD QUESTION ....

10 Bits for an ADC or DAC is .1 % ...
12 Bits ......................... is .025%

do you know lots of Pic level peripherals with a better accuracy ??? Do you know how to realise those circuits ???

so, 1 of 12 bits of your result is 1.8, say 2 ...

.5717 really do not mean anything here, in the real world !!!

Now, If you really want to do maths for maths ...

Have a look to Melabs site, you'll find two valuable solutions

1) Microchip FP files to " include" to your program
2) arithmetic co-processor ... wich is the most simple Way.

The last solution is to change compiler ( no, no ... not on the head ) or processor ... where those solutions are already cooked implemented.

Hope it helps you to better see the truth !!!

Alain