Floating point with pretty much any PIC compiler just isn't very efficient.
It's handy to have, but I try to avoid using fp unless it's just absolutely
necessary.
CCS C compiler with 16F876a target.
Code:
void main()
{
float a;
a = 2.45 * 299.95;
a /= 2.46;
printf("a = %3.3f\r\n",a);
} /* returns a = 298.730 */
ROM used: 670 words (8%)
Largest free fragment is 2048
RAM used: 11 (6%) at main() level
29 (17%) worst case
==========
Proton BASIC compiler, same target;
Code:
Dim a As Float
a = 2.45 * 299.95;
a = a / 2.46;
HRSOut "a = ",Dec a,13,10
' returns a = 298.730
Eats-up 487 words 5.94% code space, 47 bytes 12.5% RAM.
C is a little more efficient at managing RAM, but they both chew up a gob
of resources even for simple fp calculations.
If you move up to the 18F series, it's a lot more bearable, but might still be
a challenge squeezing a bunch of fp calcs in there.
Bookmarks