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

Multiple compilation units

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



Joined: 12 Dec 2014
Posts: 77

View user's profile Send private message

Multiple compilation units
PostPosted: Tue Feb 24, 2015 4:47 am     Reply with quote

Hi.
When is it an advantage to create a project with multiple compilation units and how effective is it compared to building a regular single project?
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 24, 2015 10:22 am     Reply with quote

I rather doubt there is any advantage,especially none with a single project. I believe the idea is to create your own 'functions' that several projects would use,say a 'driver' for a custom LCD module. Then that code could be 'imported' into several project.
Frankly I don't see ANY benefit,as CCS makes is easy to 'include' code like 'drivers', 'math routines', etc.
Perhaps someone who has done it, can explain why it was /is better but on the surface I can't see any real benefit.

Jay
picman62



Joined: 12 Dec 2014
Posts: 77

View user's profile Send private message

PostPosted: Tue Feb 24, 2015 10:51 am     Reply with quote

Thanks for clarifying this.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Sun Jul 05, 2015 1:04 am     Reply with quote

Here is an example of a project I did that has 3 different compilation units,

http://www.mculabs.com/projects/ssx32.html

You can basically create an 8ch, 16ch or 32ch servo driver.

In main, you see:
#define SSX32
//#define SSX16
//#define SSX8


the project will either compile for 18F26K20 or 18F46K20 depending on which option you choose.

With this way of doing this, I don't have to maintain 3 separate projects for 3 different servo controllers.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
Ttelmah



Joined: 11 Mar 2010
Posts: 19454

View user's profile Send private message

PostPosted: Sun Jul 05, 2015 10:35 am     Reply with quote

The same would work without multiple compilation units.

The key 'problem' to understand about MCU use. is the way the CCS optimiser work. The PIC doesn't have a variable stack (for the 12/14/16/18 chips), so where on most chips the stack can be used for transient variables, and variables that are only used locally to a routine, on the PIC these have to use the main RAM. CCS starts by building a tree of the routines, and then working across the tree, and re-using RAM space for local variables for each branch, into the same areas used for other branches. Unfortunately using MCU's, impedes the efficiency with which this can be done. The same code built with MCU's (depending on the actual code layout), can (will) end up using more RAM. :(

Now the reasons 'to' use MCU's, are on larger code, reducing compilation time (though generally most PIC code is so small that this is not worthwhile - this includes routines filling medium PIC24's, which still takes less than a couple of seconds to compile), or distributing libraries without distributing readable source code (for commercial reasons). This second, can be done in CCS using the encryption option instead.

Historically, CCS was a single pass compiler, without a linker, and it still works better if treated as if this was still the case.
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