How to prevent implicit promotion from single to double when using CAN Pack block?

10 visualizaciones (últimos 30 días)
Alex
Alex el 12 de Nov. de 2025 a las 22:55
Editada: Fangjun Jiang el 13 de Nov. de 2025 a las 13:11
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

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 13 de Nov. de 2025 a las 13:09
Editada: Fangjun Jiang el 13 de Nov. de 2025 a las 13:11
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')
ans = int32 2147483647

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by