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.