CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC12F683 - including math.h and memory occupied

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
James
Guest







PIC12F683 - including math.h and memory occupied
PostPosted: Fri Mar 14, 2008 7:10 am     Reply with quote

I have a small question, it's normal for a 12F683, to have ROM occupation jumps up to 78% when i add math.h? i bet the answer is yes, but without experience might be good to ask for confirmation.

Moreover: there is no was to just include only part of math.h, right? i have to take the full package; so on the 12f683 there's just no space left for other includes; for more complex project (at least with CCS C) i must shift to a bigger PIC.

Is there an estimation of occupation for each library? how much does it costs in term of ROM for the "include" directive?

P.S. It's useless to store the read_adc() value in a float, right? it only returns an int (8 or 16).

Thanks !
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 11:14 am     Reply with quote

You can include as many libraries as you want as the compiler is smart and will only compile the functions you are actually using. So it doesn't matter if the library is small or huge, if you are only using one function than that single function will be in your compiled code and nothing else. Splitting a library can improve compilation speed but will do nothing to reduce your code size as that already is optimal.

If your code is increasing this much than it is because you have done more than just adding the #include. Most likely you are using one of the functions inside math.h. For example I just tested this in v4.057 with PIC12F683. Only including math.h gave a ROM usage of 1%. Using the exp() function increased ROM usage to over 60%.

You mention floating point. Realize that a PIC processor only calculates in 8 bit integers, all other data types are simulated by software. Especially floating point is a data type that uses a lot of resources (memory and computing speed). Often a better alternative is to use a technique called 'fixed floating point' also known as 'scaled integers'. The trick here is that you consider what precision you need, i.e. how many digits after the dot, and then 'scale' the float to become an integer. All arithmetic is done in integer format and only at the end, when showing the result to the user, you add the 'dot' again. Here an example to make clear what I mean:
- Assume you want to have a precision of 2 digits after the dot: 1.23
- Multiply by 100 will give you: 123, an integer!
- Do all your arithmetic in integers
- Show result to the user by adding a dot between the 2nd and 3rd last characters, use the %w parameter in printf for this.

Quote:
P.S. It's useless to store the read_adc() value in a float, right? it only returns an int (8 or 16).
True.
James
Guest







PostPosted: Mon Mar 17, 2008 10:26 am     Reply with quote

Thanks ! that was a real cristal answer !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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