|
|
View previous topic :: View next topic |
Author |
Message |
suamikim
Joined: 03 May 2007 Posts: 2
|
Usage of atof increases used rom up to 14 % |
Posted: Wed May 09, 2007 2:20 am |
|
|
Hi @all!
At the moment I'm working with the PCW C Compilder IDE (IDE Version 3.41, PCM Version 3.190) on a PIC 16F877.
My problem is, that a single use of atof-function increases my used rom up to 14 %.
Heres a little sample-code:
Code: |
fVelHorz = atof(strVelHorz);
ClearDisplay();
sprintf(line, "%03.2f km/h", fVelHorz);
WriteDisplayString(line);
|
Rom-Usage: 43
Code: |
//fVelHorz = atof(strVelHorz);
ClearDisplay();
sprintf(line, "%03.2f km/h", fVelHorz);
WriteDisplayString(line);
|
Rom-Usage: 29
Is this behavior normal, is it a bug or maybe some other problem in my code?
Actually it's not a big problem, cause the program is finished so far, but i would really like to know, why this happens!
Any help would really be appreciated!
thks, regards
mike |
|
|
Ttelmah Guest
|
|
Posted: Wed May 09, 2007 2:36 am |
|
|
Totally to be expected.
atof, implies significant amount of arithmetic. The arithmetic is in floating point, which is the bulkiest thing around in general.
Try writing a 'simple' atof function. Include writing the code for the floating point arithmetic, using the raw integer arithmetic abilities of the PIC. After the first few hundred lines of code, you will get an idea of why it is bulky...
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 09, 2007 2:44 am |
|
|
Using float variables always consumes a lot of program memory and processing power, especially on a small PIC16 processor which has almost no hardware support for arithmetic. For example the PIC18 is still very basic but a leap forward as it has a hardware multiplier for 8-bit values. Now you know why these processors are so cheap.
In the old times of the '386 processor on the PC you had to buy a seperate coprocessor, the 80386-DX to do floating point calculations.
Even worse than multiplication is doing a division. The atof() function contains several multiplications and a division, hence the increase in program size. It's not a bug.
Important lesson: Try to avoid floating point variables on small processors whenever possible. An often used technique is 'scaled integers', also called 'fixed point' arithmetic. For an explanation of this technique have a look at http://www.embedded.com/98/9804fe2.htm. |
|
|
suamikim
Joined: 03 May 2007 Posts: 2
|
|
Posted: Wed May 09, 2007 2:58 am |
|
|
Thks for the pretty fast replies!
Somewhere in my mind i was aware of that "floating-point-problem", but i just don't wanted to belief it ;)
Now i know it better and I'm gonna check, if it's worth to learn the technique of "scaled integers"!
thks |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|