CY8CKIT-037 Calculation time

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
MarkusS
Level 1
Level 1
First reply posted First question asked Welcome!

Hello

I use the CY8CKIT-037 Kit for a project to implement a MPC algorithm. 
After I implemented the code I realized that  some easy calculations take a very long time to process...

I just used one of the GPIOs that I set high at the beginning of the calculation and low at the end... 
My first idea was that maybe the ISR take too much processing time, then I copied some of the code into an empty project and it still takes way longer than expected..

What could be the reason for that?

One time measurement for example is a for loop for 10 iterations containing 6 additions and 7 multiplications and save the values into an array - this already takes 361µs which is way longer than the complete calculation takes on another chip - I simply have no idea why... 

I attached the whole project - maybe someone can help I - I am stuck...

 

Thank you very much in advance..

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Markus,

I downloaded your mini-project.

Here's my results:

362us

ISR_CTRL frame time Comment
362us No changes to your code.  Debug configuration
289us Change to Release configuration. 
281us Change Compiler/Optimization/Opti level = Speed
273us

Change Compiler/Optimization/Link time Opti = True

210ns

See code frag #1

750ns

See code frag #2

127us

See code frag #3

 

Code Frag #1

 

    ISR_CTRL_Write(1u);    

    ISR_CTRL_Write(0u);

 

Code Frag #2

 

    ISR_CTRL_Write(1u);    
    for (int k = 0; k < 10; ++k)
    {  
    } 
    isd[0] = isd_est[10];
    isq[0] = isq_est[10];
    
    ISR_CTRL_Write(0u);

 

Code Frag #3

 

    ISR_CTRL_Write(1u);    
    for (int k = 0; k < 10; ++k)
    {  
    isd_est[k+1] = MPC_A_d*isd_est[k] + MPC_B_d*wel_rads*isq_est[k] + MPC_C_d*VV_DB_d_best_store[k];
/*    isq_est[k+1] = -MPC_B_q*wel_rads*isd_est[k] +  MPC_A_q*isq_est[k] +  MPC_C_q*VV_DB_q_best_store[k] +  MPC_psi_C_q*wel_rads; */
    } 
    
    isd[0] = isd_est[10];
    isq[0] = isq_est[10];
    
    ISR_CTRL_Write(0u);

 

Summary

You're using floating point math.  The floating point libs take significantly longer to execute than integer math.

If you can convert to integer math or use floating point substitution tables, you should be able to improve the speed of computation.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
2 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Markus,

I downloaded your mini-project.

Here's my results:

362us

ISR_CTRL frame time Comment
362us No changes to your code.  Debug configuration
289us Change to Release configuration. 
281us Change Compiler/Optimization/Opti level = Speed
273us

Change Compiler/Optimization/Link time Opti = True

210ns

See code frag #1

750ns

See code frag #2

127us

See code frag #3

 

Code Frag #1

 

    ISR_CTRL_Write(1u);    

    ISR_CTRL_Write(0u);

 

Code Frag #2

 

    ISR_CTRL_Write(1u);    
    for (int k = 0; k < 10; ++k)
    {  
    } 
    isd[0] = isd_est[10];
    isq[0] = isq_est[10];
    
    ISR_CTRL_Write(0u);

 

Code Frag #3

 

    ISR_CTRL_Write(1u);    
    for (int k = 0; k < 10; ++k)
    {  
    isd_est[k+1] = MPC_A_d*isd_est[k] + MPC_B_d*wel_rads*isq_est[k] + MPC_C_d*VV_DB_d_best_store[k];
/*    isq_est[k+1] = -MPC_B_q*wel_rads*isd_est[k] +  MPC_A_q*isq_est[k] +  MPC_C_q*VV_DB_q_best_store[k] +  MPC_psi_C_q*wel_rads; */
    } 
    
    isd[0] = isd_est[10];
    isq[0] = isq_est[10];
    
    ISR_CTRL_Write(0u);

 

Summary

You're using floating point math.  The floating point libs take significantly longer to execute than integer math.

If you can convert to integer math or use floating point substitution tables, you should be able to improve the speed of computation.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MarkusS
Level 1
Level 1
First reply posted First question asked Welcome!

Hello,

thank you very much for your fast and detailes response - 
I'll have a look into the possibilites you mentioned ..

Best,
Markus

0 Likes