Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
 Michael Karas11/22/17 03:34Read: 399 timesBeaverton OrUSA #190816 - Fractional ArithmeticResponding to: Razman Ramedan's previous message PID algorithms typically need to compute at a relatively fast rate. Trying to do floating point math on an 8051 that does not have a floating point hardware unit is most likely going to be too slow. So you want to look for an integer math library for the 8051 that supports 32-bit integers. Then implement all your math equations with integers. For anything that is fractional convert the elements in the equation by multiplying by the appropriate power of 10 before performing the operation. Lets say for example you need to divide a quantity by a divisor that has three digits to the right of the decimal point. Multiply everything by 1000 and perform the math in integer form and then know that your integer result has an assumed three places of fractional digits. Since signed 32-bit integer math is good for 9 decimal digits of integer math you could, for example, design your algorithms to use an assumed four digits of fractional and still maintain 5 digits of logical integer magnitude. There are assembler language libraries for the 8051 to be found on the web so search for them. Lastly let me comment that there is a language called C that would be a whole lot easier to use in managing the PID calculations. You would still want to use the above scaled integer math as I described in the C coding because even though the C language implementation may support floating point it is still going to be slow. To deal directly with your questions. 1. Use scaled integer calculations as described. 2. Your integer math library should have routines for signed and unsigned integer math. 3. The 8051 can compute numbers to almost any maximum size limited only by available memory to store them and performance impact to compute the arithmetic operations. 32-bit integer math on an 8051 is reasonably practical using four bytes to store each integer. 4. With the right software code in place the 8051 can manipulate integers of 8, 16, 24, 32, 48 or even 64 bit resolution. 5. Google is your friend to find an 8051 math library.

List of 16 messages in thread
 Topic Author Date Arithmetic operation with signed number & fractional number Razman Ramedan 11/21/17 23:32 Fractional Arithmetic Michael Karas 11/22/17 03:34 agree Erik Malund 11/22/17 08:29 Why Assembler? Andy Neil 12/05/17 01:49 Hard to do better. Michael Karas 01/25/18 21:36 Assembly vs. Keil James Hinnant 02/14/18 17:43 assembly vs C Erik Malund 02/15/18 08:18 Re: assembly vs C James Hinnant 02/15/18 15:15 In the good old days... Kai Klaas 02/16/18 05:56 in the new days Erik Malund 02/17/18 08:52 Hi Razman, here are some links James Hinnant 02/15/18 15:41 Code samples James Hinnant 02/15/18 15:55 Oops - 8052.com code library is broken James Hinnant 02/17/18 15:43 A bit late Andy Neil 02/19/18 16:13 threads autolocking at approx. 2 months James Hinnant 02/20/18 16:49 threads autolocking Andy Neil 02/21/18 03:15

Back to Subject List