Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to reduce code excution time (make the code more efficiet)??

Status
Not open for further replies.

yzou_ua

Member level 5
Joined
Nov 5, 2008
Messages
92
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,869
I wrote the code in c fixed point Q16 format, and cost 120usec to excute the algorithm. Wanna reduce it to around 50usec. Any suggestions??
I have applied the built-in _Q16() functions for multiplication, power, sin, cos etc., but still too much time spent...
 

any chance you can increase the processor clock speed or increase the optimisation level of the compiler ?
 
  • Like
Reactions: yzou_ua

    yzou_ua

    Points: 2
    Helpful Answer Positive Rating
any chance you can increase the processor clock speed or increase the optimisation level of the compiler ?

I'm using dsPIC33 and just increase PLLFDB register from 45 to 58. The time excution does reduce by around 35usec!!! Thx a lot!!!
As to the better complier, I am currently useing C30, and have no clue about better one. Any suggestions??
Also, since I modify the PLLFDB in the code, do I need to do anything else correspondingly? I heard someone said "the freq in IDE need to be changed accordingly... " What's that suppose to mean??
 

I would suggest disabling the code optimization (and not increasing it) in order to remove any optimization that can lead to a subroutine, maybe you will see a difference and maybe not, it depends on the code

Check page 31 MPLAB C30 C Compiler User's Guide
-mpa=n
Enable the procedure abstraction optimization up to level n. If n is zero,
the optimization is disabled. If n is 1, first level of abstraction is allowed;
that is, instruction sequences in the source code may be abstracted
into a subroutine. If n is 2, a second level of abstraction is allowed; that
is, instructions that were put into a subroutine in the first level may be
abstracted into a subroutine one level deeper. This pattern continues
for larger values of n.
The net effect is to limit the subroutine call nesting depth to a maximum
of n.

Alex
 

are you using an external oscillator ? if so can you increase its speed
are you using the full version of C30? the lite/academeic version has certain optimisations disabled
 

Thanks, Alex and horace!
But WHERE to change the optimization option?? I mean, from which menu in IDE??
 

select Project > Build Options > Project > MPLAB C30 then Categories > Optimization
 
  • Like
Reactions: yzou_ua

    yzou_ua

    Points: 2
    Helpful Answer Positive Rating
Thx and I tried level-1 and -2 for optimization... It seems a little improvement but not much...
thx all the same...
 

Hi,

Functions like power, sin, cos etc. are very time consuming.
If you don't need the full precision, maybe you can use less precise but much faster approximations.
Can you tell about your application?
Regards

Z
 

I cannot agree w. you anymore!
My code is for motor drive space vector modulation (SVM) and require the magnitude of space ref. vector Vsp = sqrt(Valpha^2 + Vbeta^2). As to sin and cos, I'm using buildt-in _Q16sin() and _Q16cos() functions so does not consume much time actually...


Hi,

Functions like power, sin, cos etc. are very time consuming.
If you don't need the full precision, maybe you can use less precise but much faster approximations.
Can you tell about your application?
Regards

Z
 

What is the actual model of the dsPIC33F you are using in your design?

Are you using an internal or external oscillator? What is the actual frequency of the FOSC?

Have you examined your algorithms and looked for closed sets of values which are repeated used in the calculations? Isolating these closed sets, normalizing them and implementing a lookup table can dramatically increase calculation times.

BigDog
 

I agree with other posts, there aren't too many things that you can do.

- Log all your uses of a specific algorithm, and determine if there are few enough that you could convert to a look up table, or using a look up table plus approximation. Maybe the results will be close enough?

- Rewrite algorithm to speed it up.

- Increase compiler optimization.

- Increase clock of current microcontroller.

- Change to faster microcontroller in same or similar family, or change to faster microcontroller, like ARM, or even an ARM with floating-point, like ARM Cortex-M4F (see ST.com F4 series)
 

Probably ensure the Q16 code uses 16 bits word. Any conversion will add extra clock cycles. Look at EventHelix.com.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top