Why do I receive a data type mismatch error when using a model reference in Simulink?

463 views (last 30 days)
My model contains a Model Reference block where the referenced model inport data type is set to AUTO. The referenced model uses the Compare to Constant block to compare the model input to a constant and output data of type UINT8. When I send the referenced model data of type double, I receive the following error:
Data type mismatch. Input port 1 of 'test_mod/Model' expects a signal of data type UINT8. However, it is driven by a signal of data type 'double'.
I do not think this should happen if the data type of the input port is set to AUTO.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This behaviour occurs because the Model Reference block in Simulink uses a compiled version of the referenced model, where all sample times and data types are explicitly set based on the block data types within the referenced model. Thus, a data type of AUTO in a referenced model cannot remain as AUTO in the model that references it. Instead the datatype must be specified explicitly.
In order to work around this, open the model that is being model referenced, and double click on the inports and outports (or any other approriate block where the data type is set to AUTO). Now click on the "Signal Attributes" tab, and then for the "Data type" property, explicitly specify the data type (e.g. BOOLEAN, INT8) attribute of the signal for those ports.
  1 Comment
Arthur
Arthur on 17 May 2023
I have the same problem (I use the same model for MCU code generation and it uses SINGLE and the same model for Simulink Compiler that CANNOT build FMU with SINGLE type in it!). I tried to make a different wrappers for MCU and FMU generation, but due to this bug the reference model stick to Single or Double without automaticaly inheretance! this is a quite annoying bug!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!