Why does TI C2000 with CLA crash with the generated code for mod blocks

4 views (last 30 days)
I have mod blocks for int16 and single inputs in CLA subsystem. The generated codes for CLA on TI C2000 contains the functions, "div_s16_floor()" for int16 and "rt_modf_snf()" for single. The two functions are causing CLA to stop executing or executing incorrectly.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Nov 2021
The mod block creates the functions, "div_s16_floor()" and "rt_modf_snf()", in model.c file. In general, CLA cannot access the function defined in a .c file. Currently, the mod block cannot be inside CLA due to the creation of two functions in the .c file.
 
CLA is a floating point processor unit where integer modulus operation is not supported. 
 
For single modulus, you can make use of "CLAdiv()" function provided by TI and that is part of CLA math library function. This can be done in Simulink by using the following statement in a MATLAB function block: 
function rem = fcn(num, den) 
%#codegen 
Quotient = int32(0); 
if isequal(coder.target,'rtw') 
   Quotient = coder.ceval('CLAdiv',num,den); 
   rem = num - single(Quotient)*den; 
else 
   rem = mod(num,den); 
end 
end 
Note: CLAdiv will return the result of float type. 
 
You can also refer to the example “c28035pmsmfoc_cla.slx” where a similar implementation of other CLA math library functions has been made. In the example, look inside the park transformation block in the following path c28035pmsmfoc_cla/FOC Algorithm/Torque Control Algorithm/Generating Space Vectors/Generating Raw Space Vectors/Park Transformation. 

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!