[SOLVED] PIC code improvement

Status
Not open for further replies.

dmta

Member level 2
Joined
Mar 25, 2013
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Earth
Visit site
Activity points
1,650
Dear all,

I have this program where inside a timer interrupt I need to carry out certain things. One of this is to execute the following line of code. But when I do this the microcontroller takes some time to compute the value. Can you give me any suggestions to improve it? the variables are in type int

HTML:
 z_n = xor + ((z_n*63)>>6);
          xor_sum = z_n>>6;

Best regards
 

cannot see any obvious way to improve performance - clearly the * is the longest operation - can you give more details of the algorithm?
how often does the timer interrupt? if only mSeconds there should be no problem but get 50000 interrupts/second and you could have timing problems
can you increase the processor clock by using clock multipliers which are available on the more powerful PICs?
 


I would try to convert

z_n*63 -> ((z_n << 6) - z_n) // = z_n * 64 - z_n = z_n*(64-1)




Re writing


HTML:
 z_n = xor + (((z_n << 6) - z_n)>>6);
          xor_sum = z_n>>6;


Hope it helps.

Simao
 
Reactions: dmta

    dmta

    Points: 2
    Helpful Answer Positive Rating
very sorry for this late reply... the answer is correct. !!!!!!!!!!!!!!!
 

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…