simple method of forcing single precision floating point operations
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
There are some frustrating things that occur when trying to generate single precision math using embedded coder. I only have single precision hardware available so it's important to use single precision operations and variables.
In a simple demonstration function where the inputs and outputs have been set to single in the model explorer:
function y = fcn(u)
y = u;
for i = single(0:1000000-1)
y = i*2+i^2;
end
the bounds of the loop must be specifically set to single or else an error is raised. There are lots of little problems like this that come up that make editing preexisting code/simulink projects pretty frustrating to debug.
Also when using trig and square root functions, the generated c code uses sin and cos instead of sinf and cosf etc. despite the fact that the arguments are single precision. The generated code needs manual editing from what I can tell to get consistent single precision math throughout.
Is there a better way?
1 comentario
dpb
el 10 de Ag. de 2015
I'd guess the "better way" unless TMW fixes such issues which I wouldn't expect any time soon if ever for the latter problem would be to use #define to do the translation of the library function names.
I unfortunately don't have any suggestions for the other issue; I agree that lacking a declaration facility with Matlab makes dealing with such issues a pit(proverbial)a[ppendage]
Respuestas (3)
Adam Barber
el 12 de Ag. de 2015
Hey Jonah,
I'm not sure if you tried this already, but you should be able to specify single precision by following the steps here:
with an example here:
If you don't explicitly set data types anywhere, then Simulink should only generate code for single precision. If you do find inconsistencies I would definitely bring those up with Technical Support.
Hope that helps,
-Adam
3 comentarios
Amish Ghadiya
el 22 de Ag. de 2016
Editada: dpb
el 23 de Ag. de 2016
How matlab Embedded function support fixed point data type Help me if any one knows the solution.
*Below mentioned Embedded matlab function code*
function [Out1, Out2] = CheckCount(int1,int2)
%#eml
persistent var1 CNT;
if isempty(var1 ); var1 =[0 0 0 0 0]; end
if isempty(CNT); CNT=0 ; end
Out1 = 0;
Out2 = 1;
var1= [ int1, var1 (1:4) ];
if sum(var1) > 20
CNT = CNT + 1 ;
if CNT >= 5 ; CNT=5 ; end
Out2 = 1 - (CNT*0.2);
Out1 = 1;
end
if int2< 7.2
Out2 = 0;
end
input and output data type are same
ex: fixdt(0,16,0.1,0)
When i try to compile below mentioned error is displayed
*This assignment writes a 'double' value into a 'uint8' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches.
Function 'SCA__USSDIST_Embedded MATLAB ' (#1474.182.186), line 8, column 1: "Out1" Launch diagnostic report.*
1 comentario
leong
el 2 de Jul. de 2019
the code replacement library is intended for such use.. although it might not be as easy..
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!