How to prevent implicit promotion from single to double when using CAN Pack block?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Fangjun Jiang
2025년 11월 13일
편집: Fangjun Jiang
2025년 11월 13일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!