Analysis of generated code

조회 수: 2 (최근 30일)
Shrirang
Shrirang 2014년 10월 20일
댓글: Jon Boerner 2014년 10월 23일
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.

답변 (1개)

Jon Boerner
Jon Boerner 2014년 10월 21일
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
Shrirang
Shrirang 2014년 10월 21일
Hi Joe, Sorry forgot to insert image(Now image is attached), My gain value is just 0.01 but I am unable to figure out how it corresponds to 5243, Does this number represents value to be multiplied for data type changes.
Jon Boerner
Jon Boerner 2014년 10월 23일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by