S32K144 Control algorithm conversion

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

S32K144 Control algorithm conversion

Jump to solution
1,288 Views
liuqimin
Contributor IV

Hello:
  We have a control algorithm verified under simulink needs to be transferred to S32K144 to run. My idea is to replace the corresponding modules in the control algorithm with the calculation module in the S32K toolbox.However, there are some modules that do not have corresponding modules in the S32K toolbox. We would like to keep these modules and not replace them, but the data types of the modules do not match.

   Just like the Power operations and state space equations in the following figure.

   Is there any way to handle this situation?

pastedImage_1.png

pastedImage_2.png

Best Regards!

    Liu qimin

Tags (2)
0 Kudos
1 Solution
1,128 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi liuqimin

However, I am concerned that the generated code will run inefficiently on the MCU.Therefore, when generating code, the computation module in the original model should be replaced by S32K toolbox'module to improve the efficiency of code operation. Am I right?

100% true. Nonetheless, that's the main idea of Model-Based Design: Simulate -> Prototype -> Improve.

For sure it will not run efficient but you will have a baseline to start from.

The AMMCLIB User Manual is delivered with the MBDT Toolbox. Can be found in ..\\src\mbdtbx_s32k14x\AMMCLIB_s32k14x\doc

Attached here for your reference too.

pastedImage_1.png

and the procedure for computing the C1f is described for fixed point implementation only:

pastedImage_2.png

for the floating point case, you can see it in the example:

pastedImage_3.png

Best regards,

Daniel

View solution in original post

0 Kudos
5 Replies
1,128 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi liuqimin‌,

Relate with your original post: 

 Is there any way to handle this situation?

You should be able to generate the code from Simulink for the original model - even if it is represented in continuous time domain (1/s).  Not sure what error are you getting. If there is an error about data types i think you can use data type conversion between subsystems. You will probably lose some precision between double->single but it should work.

The S32K MCU has a FPU unit on 32bit hence it should deal with such algorithms pretty well. It will not be optimal but it should work.

An addition step that you can do to improve the execution on S32K MCU, is to convert your original model from s-domain to z-domain and implement it into single data type.

 In regards with your second post:

However, it is not correct to use the GFLIB_IntegratorTR_FLT module in the S32K toolkit instead.Perhaps the parameter fltC1 is incorrect.Is this parameter the same as the parameter in the discrete integral module as the gain coefficient?If not, how to determine this parameter?

Please have a look into the S32K14xMCLUB.pdf manual $5.48 page 567. It shows how to compute the paramter C1f depending on the type of integrator you may want to use.

Basically for the floating point implementation it should be: fltC1 = Ts/2 

Best regards,

Daniel

0 Kudos
1,128 Views
liuqimin
Contributor IV

Hi Daniel

Thanks for your reply !

Is that the manual you're talking about?I can't find a description of this parameter.

pastedImage_1.png

  As for generating S32K code directly with Simulink original model, I think it can be done.However, I am concerned that the generated code will run inefficiently on the MCU.Therefore, when generating code, the computation module in the original model should be replaced by S32K toolbox'module to improve the efficiency of code operation. Am I right?

  For fltC1, I'll try Ts/2.

Best Regards!

 Liu qimin

0 Kudos
1,129 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi liuqimin

However, I am concerned that the generated code will run inefficiently on the MCU.Therefore, when generating code, the computation module in the original model should be replaced by S32K toolbox'module to improve the efficiency of code operation. Am I right?

100% true. Nonetheless, that's the main idea of Model-Based Design: Simulate -> Prototype -> Improve.

For sure it will not run efficient but you will have a baseline to start from.

The AMMCLIB User Manual is delivered with the MBDT Toolbox. Can be found in ..\\src\mbdtbx_s32k14x\AMMCLIB_s32k14x\doc

Attached here for your reference too.

pastedImage_1.png

and the procedure for computing the C1f is described for fixed point implementation only:

pastedImage_2.png

for the floating point case, you can see it in the example:

pastedImage_3.png

Best regards,

Daniel

0 Kudos
1,128 Views
liuqimin
Contributor IV

Hi Daniel

  Thank you for your information!

  When Ts/2 is used for the parameter fltC1 of the GFLIB_IntegratorTR_FLT module, the running result of the replaced algorithm model is exactly the same as that of the original model。

  When useing C1 calculation formula of fixed point module as following before:

      pastedImage_1.png

The resulting parameters do not work at all.

    Follows is the results of correct operation:

   pastedImage_2.png

  Next step needs to be verified on MCU hardware.

   Best Regards!

   Liu qimin

0 Kudos
1,128 Views
liuqimin
Contributor IV

Hello:

     For the state space equation, let's change it to the following diagram. Now it's a new proble coming. When the continuous integral module in the figure is replaced by discrete integral module, it works normally.However, it is not correct to use the GFLIB_IntegratorTR_FLT module in the S32K toolkit instead.Perhaps the parameter fltC1 is incorrect.Is this parameter the same as the parameter in the discrete integral module as the gain coefficient?If not, how to determine this parameter?

pastedImage_1.png

pastedImage_2.png

Best Regards!

Liu qimin

0 Kudos