This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello, how to use Digital Control Library in Simulink for C2000 F28388D microcontroller? In particular, I would like to use the PID controller and the Refgen functions. The functions require pointer variables and structs as arguments. I tried so far to integrate the functions with the coder.opaque/coder.ceval Matlab-Coder command and with the C-function caller block. But there were always errors that the variable rgen does not exist.
Hi Maximilian,
You can use the DCL Simulink model available in the {C2000ware Directory}\libraries\control\DCL\c28\models\DCL.slx library file for simulation and code generation using Simulink. These are 1-to-1 model of the algorithm used in DCL in Simulink.
Han
Hello Han,
thank you very much for your answer. In the DCL User Guide it is written in chapter 4.7.1 that the Simulink blocks are not suitable for code generation. I would like to find a way to insert the optimized assembler function of the DCL library into the code generation with Simulink. I would like to add the Refgen and Dlog functions and others.
Hi Maximilian,
The Simulink blocks are not particularly optimized for code generation and will result in higher cycle count to execute compared to using code from DCL. If you want to use the optimized code from DCL, you can use C function block in Simulink to call the library function. You can refer to this post from MathWorks forum discussion on a similar topic.
Han
Hi Han,
thank you very much for your help. This information has already brought me a little further. I tried to integrate the Refgen function with the C Function Block. During the compilation the following error message occurs now.
In line c:\ti\c2000\c2000ware_4_00_00\libraries\control\dcl\c28\include\DCL_refgen.h:477:error: 223, function "__fsat" declared implicitly
| p->ya = __fsat(p->ampl * p->ya + p->yr, p->umax, p->umin);
I have no idea in which library the ___fsat function can be found.
I have put the Simulink model in the attachment.
Maybe you have some more good advice.
Hi Maximilian,
The __fsat is a C intrinsic function for C28x FPU. This function will be translated to MAXF32 and MINF32 instructions during compilation. The intrinsic function is something built into the compiler, hence there is not a header file that declares these functions. You can add your declaration of the function in the C function you create in MATLAB like below. For more details, you can refer to section 7.6.2 of the user's guide for C2000 compiler at https://www.ti.com/lit/spru514 .
float __fsat(float val , float max , float min );
Han
Hello Han,
thank you very much for your quick reply. I have added the intrinsic __fsat function to the C function block, but the error still persists.
Hi Maximilian,
Can you please share a simplified version of your Simulink file with the C block. I will need to do some further testing on your particular case to provide more detailed support. Thanks.
Han
Hi Han,
thank you very much for your support. I have shared a simplified version of the Simulink model which includes only the C function block.