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

Back to Subject List

Michael Karas
11/22/17 03:34
Read: 103 times
Beaverton Or

#190816 - Fractional Arithmetic
Responding 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 4 messages in thread
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      

Back to Subject List