Execution time problem (PIC)

Status
Not open for further replies.

kappa_am

Full Member level 6
Joined
Jul 16, 2012
Messages
331
Helped
19
Reputation
38
Reaction score
19
Trophy points
1,298
Location
Vancouver
Visit site
Activity points
3,859
I have written following code. it is simple and just consist of some bit check and bit set.
but execution time is rather high. I wonder why! for example in line 10 it takes 2 cycle to write a number to a variable. of if conditions consume about 10-15 step times.
I wonder why?, while I have not experienced such problem.
i also be grateful if you recommend a way to reduce execution time.


Code:
unsigned short CPS[3], PH, CH, DCH, CAPL[3], IPH[3],CAPL1, CPS1;
 signed short  LLO;
void main() {
for (PH=0; PH<3; PH++)
{
CPS[PH]=0;
CPS1=0;
CAPL1=CAPL[PH];
if(IPH[PH]) // add input current direction
{ CH=254;
 DCH=253;
}
else
{ CH= 253;
  DCH=254;
}
 if (CAPL1.B2)
 {
 CPS1 = CPS1 | ~DCH;
  }
 else
 {
  if (CAPL1.B5)
   {
    CPS1.B5=1;
    }
   else CPS1=CPS1 |~CH;
   }
for (LLO=1; LLO>-1; LLO--)
{
  if (CAPL1 & (1<<LLO))
  {
   if (CPS1.B0 == CH.B0)
   {
     if (CPS1.B4){
        CPS1.B4=0;
      CPS1=(CPS1<<1) | ~DCH;}
     else
     {
      CPS1=((CPS1<<1)+1) & CH;
      CPS1.B5=1;
      }
     }
     else CPS1=((CPS1<<1)+1) & CH;
     }
     else
     {
     if (CAPL1 & (1<<(LLO+3)))
     {
     CPS1=CPS1<<1;
     CPS1.B4= 1;
     }
     else
     {
     if (CPS1.B0=DCH.B0)
      {
      if (CPS1.B4){
         CPS1.B4=0;
         CPS1=CPS1<<1 | ~CH;}
         else
         {
         CPS1=((CPS1<<1)+1)| ~DCH;
         CPS1.B5=1;
         }} } } }
         CPS[PH]=CPS1;}
         
         }

P.s: I have not set registers yet. just a program in MikroC
 

If you really need to control the execution time the only way is to write in assembly language. When you use high level languages you lose control of things like variable placement and stack control. I can't be specific without seeing your assembly code listing but for example, you might be switching banks to access some of your variables, the compiler will add code to do this automatically but it adds to the number of instructions the PIC has to execute to complete the instruction.

Brian.
 

Does Mikroc convert lst file to hex or it directly convert C to hex file?
I mean if I change some instruction in lst file, will it considered in HEX file generating?

Thank you
 

mikroC will generate .lst file , .asm file, .cof file and also .hex file. Zip and post complete project files.
 

Everything is generated from C source, that's where you need to make your changes.

You can write inline assembly code (asm statements) to implement specific operations differently. I won't expect large speed improvements.

There's probably some optimzation potential in the arrangement of your data structures.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…