MPLAB C Compiler VS Hi-Tech C PRO Compiler

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby redips_id » Sun Mar 13, 2011 8:32 am

Hi Cytron,

I have used MPLAB C Compiler and Hi-Tech C PRO Compiler to program PIC18F452 and create LED blinking for 1 second by using delay for(.....) method. Both I set HSPLL with 10MHz crystal.

MPLAB C Compiler: for(i = 0; i < 345000; i--) // about 1 second
MPLAB Hi-Tech C PRO Compiler: for(i = 0; i < 910000; i--) // about 1 second

My question, is it TRUE? haha.. I mean MPLAB Hi-Tech C PRO Compiler execute faster than MPLAB C Compiler? I'm sorry asking a silly question, just want to know.

Thank you :D
Request for complete solution for FYP? Why don't request for graduation certificate?
redips_id
Discoverer
 
Posts: 82
Joined: Wed Jan 20, 2010 6:23 pm

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby ABSF » Sun Mar 13, 2011 1:51 pm

MPLAB C Compiler: for(i = 0; i < 345000; i--) // about 1 second
MPLAB Hi-Tech C PRO Compiler: for(i = 0; i < 910000; i--) // about 1 second


Why are you counting down?

Is "i" defined as 32 bits integer?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby redips_id » Sun Mar 13, 2011 10:48 pm

Oh sorry, i++ actually.. typing error, huhu..

I don't know how to create delay in second for PIC18. For PIC16F877A we can used __delay_ms(x); right to create delay in second, so i just try create delay for(....) to create 1 second in PIC18F452, and accidentally i found this different..

No big deal, just wonder.. :)
Request for complete solution for FYP? Why don't request for graduation certificate?
redips_id
Discoverer
 
Posts: 82
Joined: Wed Jan 20, 2010 6:23 pm

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby shiyan » Sun Mar 13, 2011 11:41 pm

redips_id WROTE:Hi Cytron,
I have used MPLAB C Compiler and Hi-Tech C PRO Compiler to program PIC18F452 and create LED blinking for 1 second by using delay for(.....) method. Both I set HSPLL with 10MHz crystal.

MPLAB C Compiler: for(i = 0; i < 345000; i--) // about 1 second
MPLAB Hi-Tech C PRO Compiler: for(i = 0; i < 910000; i--) // about 1 second

My question, is it TRUE? haha.. I mean MPLAB Hi-Tech C PRO Compiler execute faster than MPLAB C Compiler? I'm sorry asking a silly question, just want to know.

OK, I am not Cytron :D , nor their staff, just busy body wondering around.

AFAIK HI-TECH is the most optimized C Compiler for PIC in the market. This means the code size and execution time is smallest and shortest.

When you write a code in C you cannot know how fast the code is being executed because C Compiler will change C code to Assembly first and Assembler will further translate that into hex code. A good compiler will change the C code into Assembly code in a efficient way, less instructions :lol: and less instruction = faster execution time, right?

though the delay is being calculated from same value, but we do not sure how C18 and HI-TECH C PRO convert the same C function in to Assembly. Anyway if you like to check, you can use the Disassembly Listing under View of MPLAB IDE.

Share with us when you find something.
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby redips_id » Mon Mar 14, 2011 12:04 am

Thanks shiyan, i agree with your answer.. :D

What is Disassembly Listing? It convert C to assembly language? I never learn assembly language for PIC, and i think it will took a lot of time to me to understand it.. huhu.. However I like the way your answer because it same with my opinion, hehe.. Maybe we can look n stay for the answer from another 'otai' in programming.. :lol:
Request for complete solution for FYP? Why don't request for graduation certificate?
redips_id
Discoverer
 
Posts: 82
Joined: Wed Jan 20, 2010 6:23 pm

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby ABSF » Mon Mar 14, 2011 5:57 am

;PIC Time Delay = 1.0000040 s with Osc = 10.000000 MHz
movlw D'1'
movwf CounterD
movlw D'13'
movwf CounterC
movlw D'187'
movwf CounterB
movlw D'171'
movwf CounterA
loop decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
decfsz CounterD,1
goto loop
retlw


I used "PICLoops V2.1" to calculate the delay for one second and it takes a constant of 0x1DBBAB ie 1948587 decimal to do the delay. I am not sure if PIC18F has any instructions to make the program faster and shorter.

There is also a "Delay Calculation" on the "support Materials" on the http://www.cytron.com.my web site. But I dont know how to use it as it looks like a .DLL file.

The HT compiler PRO can achieve 910000 counts in one second is considered very efficient compiler. There are overheads to take care before going into the real delay loops for C.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby Brian Griffin » Mon Mar 14, 2011 9:29 am

I calculated the respective delay values for 345000 and 910000 on the first post - theoratically it's 0.0345 seconds and 0.091 seconds respectively, if the crystal is 10MHz and with 4x PLL.

I do believe that I once did with those 1-second delays before - it's usually a plus or minus 10,000,000 (32 bit unsigned long), despite the overheads. I can double check this using MikroC and the other compiler (MPLAB) on my hand.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby ABSF » Mon Mar 14, 2011 2:13 pm

CODE: SELECT_ALL_CODE
;PIC Time Delay = 1.0000040 s with Osc = 10.000000 MHz
   movlw D'1'              ;counter D=0x01
   movwf CounterD
   movlw D'13'             ;counter C=0x0D
   movwf CounterC
   movlw D'187'            ;counter B=0xBB
   movwf CounterB
   movlw D'171'            ;counter A=0xAB
   movwf CounterA
loop decfsz CounterA,1  ;counterA--, if counterA=0 then skip next instruction
   goto loop
   decfsz CounterB,1     ;counterB--, if counterB=0 then skip next instruction
   goto loop
   decfsz CounterC,1     ;counterC--, if counterC=0 then skip next instruction
   goto loop
   decfsz CounterD,1      ;counterD--, if counterD=0 then skip next instruction
   goto loop
   retlw                    ;return to calling program


I went through the program and found that my calculation is wrong. As counterD = 1, it becomes 0 when decremented and should straght away exit the delay loop. So the correct count should be 0xDBBAB or 900011 decimal. The total number of machine cycles = 2,500,009. Time = 2,500,009 x 0.4uS ~= 1.0000036 seconds.

Because the 16F RAM registers are all 8 bit wide, it has to split into 3 smaller loops. If using 18F, where the RAM registers are 16 bits wide, the program would need only 2 variables with larger constant values and it should be able to run faster.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby ober » Tue Mar 15, 2011 2:40 pm

ABSF WROTE:Because the 16F RAM registers are all 8 bit wide, it has to split into 3 smaller loops. If using 18F, where the RAM registers are 16 bits wide, the program would need only 2 variables with larger constant values and it should be able to run faster.
Allen


Allen, actually 16F and 18F have the same 8-bit RAM size. PIC18F have 16-bit wide instruction set, this mean each instruction set, for example MOVWF will take 16-bit of space in program memory, but the CPU/ALU can only process 8-bit data.

There are 2 scenarios that we can compare here. Between PIC16F and PIC18F, and between 2 type of C compiler.

I would agree with shiyan about the compiler differences. Even with C18 and HITECH compiler, there is a feature called optimization. This optimization will actually decide how optimize the C code is translate into assembly before turning into hex code. If the optimization is good, the hex code will be smaller in size and of course faster execution time. HITECH is well known for high code optimization.

As for PIC16F compare with PIC18F, though both are 8-bit MCU, there are significant differences between their instruction sets. PIC16F has around 35 instruction sets while PIC18F have 77 instruction sets (normal case). These instruction sets will actually determine the time and length of certain subroutine in C.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: MPLAB C Compiler VS Hi-Tech C PRO Compiler

Postby ABSF » Tue Mar 15, 2011 3:19 pm

Allen, actually 16F and 18F have the same 8-bit RAM size. PIC18F have 16-bit wide instruction set, this mean each instruction set, for example MOVWF will take 16-bit of space in program memory, but the CPU/ALU can only process 8-bit data.


Ya, you're right. I didn't check the datasheet and just took for granted that 16 bit MCU are also having 16 bit registers. The thing is that 18F is able to move the contents of one FR to another FR using MOVFF is very convenient. I have to define a macro to do this before. And the addition of Branching instructions are also very useful for those from the Intel and Motorola MCU family freaks.

I also read from somewhere that the optimization of the C18 compiler can be turned on or off for certain reasons. So with this facility, you can compare the size of hex codes generated with or without optimization.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron