Analysis of generated code
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have generated a code in Target link for a gain block.(Attached the sanpshot of model) I/p to gain block is Int16 (Resolution 2^ 0 ), Gain block ==> Data type UInt16 (Resolution 2^ -4 ); Output ==> Data type UInt16 (resolution 2^-4).
Generated code is as follows Aux__a = ((MPT_Int32) in) * 5243; Gain = C__U16SHRI32C6_EQ15_SATl(Aux__a); I am unable to map the code and model especially i am wondering presence of " 5243 " in code.
Réponses (1)
Jon Boerner
le 21 Oct 2014
It looks like your model is not attached to the question, but here is my best guess at what is happening.
You refer to the resolution of the variables in your description, so I assume you are using some kind of fixed-point numbers. When you generate code for fixed-point numbers, everything is stored as integer values. For example, a value of 5243 as an integer corresponds to bits with the following values (for a 16-bit storage type):
0001010001111011.
If the binary point is at the end of that representation, you get 5243. However, if the binary point is four places to the right (as indicated by your resolution change):
000101000111.1011
The value actually being represented is 327.6875, even though it says 5243 in the code. The generated code does not explicitly state where the binary point is, but is generated to account for it.
This explanation might be way off base, and the picture of your model might help significantly if you could attach it.
2 commentaires
Jon Boerner
le 23 Oct 2014
I am not really familiar with TargetLink and was actually basing my answer on how the Mathworks products generate code, but it looks like the following is happening.
The binary representation is still
0001010001111011
If a resolution of 2^0 indicates a binary position of
0.001010001111011
(which makes sense because the most significant digit has a resolution of 1), then a resolution of 2^-3 indicates a binary position of
.(000)0001010001111011
Note the three zeros in the parentheses are digits that are part of the representation but are not actually saved in the uint16. That number actually evaluates to 0.01 in decimal.
Voir également
Catégories
En savoir plus sur Execution Speed dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!