How to prevent implicit promotion from single to double when using CAN Pack block?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Fangjun Jiang
il y a environ 4 heures
Modifié(e) : Fangjun Jiang
il y a environ 4 heures
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 commentaires
Voir également
Catégories
En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!