Now that I’ve got CatTrack working, I’ve been having a look at refining the code. As I previously mentioned, I am using the CCS C compiler, basically because the ‘paid for’ version of their compiler is significantly cheaper than Microchip’s XC8 ‘paid-for’ version. I did begin to wonder though, just how much bigger would my code be, and how much slower would it run if I used the free version of Microchip’s XC8 compiler?
This is what the Memory usage currently looks like in the PIC16LF18345, compiled with CCS C:
It took a few hours of work to plough through the code and make all the necessary changes required to convert from CCS to XC8. So now the moment of truth, let’s see the Memory usage when using the free version of the XC8 compiler:
Oh. It appears that the free version of the XC8 compiler is creating more efficient code than the paid-for CCS compiler! Ignore the references to the PRO licence above – it was compiled in Free mode.
I then thought that although the CCS code takes up more space, perhaps it’s compiled for speed rather than space? To cut a long story short – no, it isn’t. The free XC8 compiled code took 26329 clock cycles to configure CatTrack and run an encryption routine, whereas the CCS compiled code took 31849.
So the headline so far is that CCS is 21% slower, takes up 4% more ROM and 38% more RAM than the free XC8 compiler!
Out of curiosity, I wondered how small the PRO version of the XC8 compiler could make the code. This is the answer:
Fairly remarkable! The PRO (paid-for) version of the XC8 compiler is creating code that consumes 63% less ROM and 15% less RAM than the paid-for version of CCS.
This prompted me to come up with a project specifically to compare the two compilers, so that’s what I’ve done. I’ve stuck it in git, here:
It’s designed to be opened in MPLAB X and is full of #defines, so it’ll compile fine using either CCS or XC8. The code sets up some IO, encrypts 128 bits using XXTEA then prints the encrypted result out of the UART.
Results are as follows:
|Compiler||ROM Used (words)||RAM Used (bytes)||Cycles to run||Price|
|XC8 v1.44 Free||1317||108||26371||£0|
|XC8 v1.44 PRO|
|XC8 v1.44 PRO|
|CCS v5.074||1798||196||38656||£112 (16F, command line only)
£450 (All PICs)
I think the results probably speak for themselves.
I wondered if this was limited to the 16F range of PIC devices, but it’s not. I converted one of my other projects which uses an 18F PIC. Migrating from CCS to the free XC8 compiler resulted in the ROM usage reducing from 22420 words to 20457 words.
So there you have it! I dismissed the free version of the XC8 compiler, but you really shouldn’t.
Is there any converter avaliable to convert CCS C code to XC code? Thanks.
Not to my knowledge I’m afraid – I can’t imagine it’d be worth anyone’s time writing a generic one, there are so many different features across the range of PICs. It shouldn’t take too long to convert the code, maybe a couple of days if the code is very complex. Worth it if you’re planning a software feature upgrade anyway!
Thanks for the comparison!
Even though I didn’t plan to buy CCS, I use often XC8 compiler and I’m very happy to hear that it works this good.
One thing that XC8 doesn’t allow you to do is recursion. I found out while porting the popular ELM Chan petitFAT + SD card driver to PIC18, but it was easy to get around. Don’t know if CCS supports recursion.
Thanks, thats what I was wondering.