This is a multi-part message in MIME format. ------=_NextPart_000_008C_01C484FF.33A959C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > The PIC families do not have any native floating point support at all. > That means you can pick whatever representation is convenient to your > requirements for precision, range, and performance. And then you get > to write all the code to do appropriate operations on that format. > (alternately, you find someone else's floating point library that is > close enough to your requirements and use it. Perhaps simply by using > the floating point support built into a compiler...) I somehow missed the original post of this thread. I created my own 24 bit PIC floating point routines a long time ago, and use them in the relatively rare cases when floating point is really necessary. Most simple measurement and scaling can be done with fixed point. One application where I find floating point very useful is in PID controllers. There the dynamic range of values can be very high, making it impossible to find a fixed point format that is small enough in bytes. Since PIC computations generally work on real world data, 24 bit floating point with its 16 mantissa bits seems a good fit. At 3 bytes/value they generally require less storage than fixed point, especially when the range of numbers can vary widely. And 16 bit precision is several bits more than what most measurements are good for, so you can do a bunch of computations without the roundoff error becoming an issue. I have attached the comments that describe my 24 bit floating point format. Programs HFP and FPH convert between decimal floating point and the hexadecimal 24 bit PIC floating point format. These can be useful during debugging. Both these programs are included in the PIC development tools available at http://www.embedinc.com/pic/dload.htm. > Personally, if I were to find an application that required floating > point, it would be time for me to shell out the $$$ for a C or basic > compiler with known-well-behaving float code, and then just write the > code in the high level language and hope it fit. (alternately, it'd > be time to consider another processor where 'fitting' wouldn't be so > much of an issue.) Compiler floating point is notorious for code bloat. Why not just use a few hand-crafted floating point routines and call them from the assembly code? I've got one application doing two nested PID control loops and a lot of other stuff on a 16F876. It's got less than 100 words of program memory left, and I seriously doubt that it would have fit if it were compiled code. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu ------=_NextPart_000_008C_01C484FF.33A959C0 Content-Type: text/plain; name="x.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x.txt" ; 24 bit floating point format: ; ; 24 bits are used to describe a floating point value using 1 sign = bit ; 7 exponent bits, and 16 mantissa bits as follows: ; ; | byte 2 | byte 1 | byte 0 = | ; | | | | | | = | ; 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 = 1 0 ; = ------------------------------------------------------------------------ ; | | | = | ; | S| EXP | MANT = | ; | | | = | ; = ------------------------------------------------------------------------ ; ; S - Sign bit. 0 for positive or zero value, 1 for negative = value. ; ; EXP - Exponent. The overall floating point value is the = mantissa ; value times 2 ** (EXP - 64) when EXP is in the range from 1 to = 127. ; The special EXP value of 0 is only used when the overall = floating ; point value is 0.0. ; ; MANT - Mantissa. Except for the special case when the overall ; floating point value is 0, the mantissa represents a fixed point ; value such that 1 <=3D mantissa < 2. This means the integer = part of ; the mantissa is always 1. Since this integer part is always the ; same, it is not stored. The MANT field contains the 16 most ; significant fraction bits of the mantissa value. Therefore ; MANT =3D (mantissa - 1) * 65536. An overall floating point = value of ; 0.0 is indicated by EXP =3D 0. In that case MANT is reserved, = and ; should be 0. ; ; Consider the following examples: ; ; 0.0 --> 000000h ; ; S =3D 0 (positive or zero) ; EXP =3D 0 (special case for 0.0) ; MANT =3D 0 (special case for 0.0) ; ; 1.0 --> 400000h ; ; S =3D 0 (positive or zero) ; exponent =3D 0, EXP =3D 64 --> 40h ; mantissa =3D 1.0, MANT =3D 0 ; ; -3.141593 --> C19220h ; ; S =3D 1 (negative) ; exponent =3D 1, EXP =3D 65 --> 41h ; mantissa =3D 1.570797, MANT =3D 37,408 --> 9220h ; ; Unless otherwise specified, overflow and underflow values are = silently ; clipped to the maximum magnitude (7FFFFF for positive, FFFFFF for = negative) ; and zero, respectively. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu ------=_NextPart_000_008C_01C484FF.33A959C0--