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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
 ???11/22/17 10:34Read: times #190816 - Fractional ArithmeticResponding to: ???'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 01/01/70 00:00 Fractional Arithmetic 01/01/70 00:00 agree 01/01/70 00:00 Why Assembler? 01/01/70 00:00 Hard to do better. 01/01/70 00:00 Assembly vs. Keil 01/01/70 00:00 assembly vs C 01/01/70 00:00 Re: assembly vs C 01/01/70 00:00 In the good old days... 01/01/70 00:00 in the new days 01/01/70 00:00 Hi Razman, here are some links 01/01/70 00:00 Code samples 01/01/70 00:00 Oops - 8052.com code library is broken 01/01/70 00:00 A bit late 01/01/70 00:00 threads autolocking at approx. 2 months 01/01/70 00:00 threads autolocking 01/01/70 00:00

Back to Subject List