I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it is a cycle of 50us . But the generated code assumed 220us , i do

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it is a cycle of 50us . But the generated code assumed 220us , i do

935 Views
zqwaidy
Contributor I

 I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it  is a cycle of 50us . But the generated code assumed 220us , i do not know why assumed so long time . I hope this time is reduced to 40us. I am very confused. The following is the RTW generated code . The function is void FOC_INTC_test1_z_FOC_ISR(int_T controlPortIdx) in FOC_INTC_test1_z.c file.  Very thanks.

Original Attachment has been moved to: FOC_INTC_test1_z.c.zip

0 Kudos
2 Replies

690 Views
dumitru-daniel_
NXP Employee
NXP Employee

Can you share the model?

From the generated code, i assume you are using some Simulink division blocks. As you know division is highly inefficient on embedded processor and usually ends up in compiler runtime function calls.

You should look for ways to minimize the divisions like:

#1: precompute the inverse of a1 and use multiplication instead

rtb_Divide_e = (real32_T)FOC_INTC_test1_z_B.SFunction / a1 * a2;

rtb_Sum = (real32_T)FOC_INTC_test1_z_B.SFunction_e / a1 * a3 - a4;

#2: use additional coefficients to pre-compute the constant multiplications/divisions

rtb_Fcn = (((real32_T)FOC_INTC_test1_z_B.SFunction_i / a1 * a3 - a4) * a7 + rtb_Sum) * a5; 

#3: try using shifting instead of divisions whenever is possible

An additional question: does your application requires such fast control loop @50us ? Typically in FOC the inner loop (current control) can be executed at 100us while the outer loop (speed/position control) is usually executed at 1ms.

Hope this helps!

Best regards,

Daniel

0 Kudos

690 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hello, 

Did you enabled the Optimizations from Simulink/Configuration Parameters/Optimization ?

0 Kudos