How to prevent implicit promotion from single to double when using CAN Pack block?
9 views (last 30 days)
Show older comments
I am using the CAN pack block for my embedded system, and am trying to figure out how to prevent an implicit conversion from a single to a double in the code generation. When trying to evaluate the conditional statement (outValue > 2147483647.0), the packed variable gets implicitely promoted to a double.
I had a similar issue with the CAN unpack block assuming all variables would be doubles, and I was able to overcome this by using the signal specificaion block as shown here: https://www.mathworks.com/help/vnt/ug/control-can-unpack-block-output-type.html However, using the signal specifications for CAN packing does not achieve similar results 

0 Comments
Answers (1)
Fangjun Jiang
44 minutes ago
Edited: Fangjun Jiang
42 minutes ago
This code is likely coming from an implicit "single" to "int32" data type conversion operation, as the data value range of a "single" is larger than that of an "int32".
Also, "packedvalue" is "int16". Its range is not sufficient for the range of "int32" even with the factor of 0.1.
Basically, you need to arrange and figure out the proper data value range and data type, to avoid this type of data type conversion that needs to check the boundary values. Adding a saturation block outside of the CAN Pack block might be a solution.
intmax('int32')
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!