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
- 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.
P.s: I have not set registers yet. just a program in MikroC
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