Why C codes generated by Matlab Coder contain strange dataor variables like 0U?
2 次查看(过去 30 天)
显示 更早的评论
greetings community
I am working on the C codes generated by Simulink, and when I generate the codes unknown variables appear. For example in the ".c" code, it appears in the 0U code, and in the libraries and other codes, I only find the following statement where that value appears.
On the other hand, in the file ".c" 0U appears as a value to compare (all the comparisons [<,> =, etc] that I make between the variables is with respect to zero). Is it normal for these situations to arise?
Below I show part of the function of matlab.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/335709/image.png)
Next, we have part of the generated code
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/335712/image.png)
I appreciate any information, see if I can trust the generated code and take the code to TI C2000 MCU
0 个评论
采纳的回答
Walter Roberson
2020-7-23
In the two subtractions that you do, at least one of the variables is uint16 datatype. Operations on uint16 are defined as converting the numbers to double, then doing the operations, then converting to uint16. Conversion to uint16 is defined as 0 for negative values, and 65535 for values larger than that, and otherwise the actual value.
If you follow the code sequence you can see it testing against 0 and 65536 and imposing those as limits.
0U is not an identifier name: it is zero with suffix U which indicates that it is 0 with datatype unsigned int
5 个评论
Walter Roberson
2020-7-24
You seem to also be discussing the same thing at https://www.mathworks.com/matlabcentral/answers/563510-help-with-code-generation-for-ti-c2000
Walter Roberson
2020-7-24
Change
function duty = MPPT_algorithm(Vpv,Ipa)
to
function duty = MPPT_algorithm(Vpv_u16,Ipa_u16)
Vpv = double(Vpv_u16);
Ipa = double(Ipa_u16);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!