How to prevent override with double data type on certain block when deriving simulation ranges with Fixed-point Tool
38 views (last 30 days)
Show older comments
Hello Community
I'm using Simulink's Fixed-point Tool to optimize my design. There is a manually optimized part in my design, i.e. it alrady uses the best possible data types. I want the Fixed-point tool to ignore this part during optimization. Therefore, I checked the "Lock ouput data type setting against changes by the fixed-point tool" on all blocks in this part.
I want to derive the signal ranges by simulation. If I now start the iterative conversion, then all signals are overritten with the double data type. This is fine but the problem is that Simulink also does this on my already optimized part mentioned above. My optimized part contains of bit operations, e.g. logical left shift blocks. Now I get an error because those blocks do not work with double data types.
How can I prevent Simulink from overriding those signals not only during the optimization process, but also when deriving signal ranges?
0 Comments
Answers (2)
Andy Bartlett
on 15 Oct 2020
Edited: Andy Bartlett
on 15 Oct 2020
I'll elaborate on that.
To prevent Data Type Override from changing a numerictype, set the property
DataTypeOverride = 'Off'
For example, change
fixdt(1,5,2)
to
fixdt(1,5,2,'DataTypeOverride','Off')
This can also been done using a Blocks Data Type Assistant interface.
Step 1
Step 2
Step 3
If all the data types in a subsystem are changed in this way, and we have Data Type Override set to Double model wide
set_param(bdroot,'DataTypeOverride','Double')
then that subsystem's types will stay the same.
I've attached a example function that shows how to do this more automatically.
To use it, open the attached model
example_DTO_inherit_off_R2015b
I saved to model to work as far back as R2015b. But 'DataTypeOverride','Off' is even older than that.
notice that Data Type Override to Single is in effect
set_param(bdroot,'DataTypeOverride','Single')
and has forced all the types to single, even though fixed-point types are specified on the many blocks.
To prevent that on two of the subsystems, run the attached example function like, so
change_data_type_settings_for_DTO_inherit_off(['example_DTO_inherit_off_R2015b/SubSys1'])
change_data_type_settings_for_DTO_inherit_off(['example_DTO_inherit_off_R2015b/SubSys2'])
these scripts will attempt to set Data Type Override inheritance to Off for the data type parameters under these subsystems. Command window output will show what's happening such as
For block: example_DTO_inherit_off_R2015b/SubSys1/In1
Parameter: OutDataTypeStr
Current value: Inherit: auto
LEFT UNCHANGED
For block: example_DTO_inherit_off_R2015b/SubSys1/Dbl-to-FixPt
Parameter: OutDataTypeStr
Current value: fixdt(1,5,2)
New value : fixdt(1,5,2,'DataTypeOverride','Off')
For block: example_DTO_inherit_off_R2015b/SubSys2/Dbl-to-FixPt
Parameter: OutDataTypeStr
Current value: fixdt(1,wl1,2)
New value : dtoInheritOffWrapper( fixdt(1,wl1,2) )
The two subsystems that were change now have Data Type Override inheritance Off. The 3rd subsystem is still reacting to Data Type Override to Single.
HTH,
Andy Bartlett
Andy Bartlett
on 16 Oct 2020
Edited: Andy Bartlett
on 16 Oct 2020
Too bad the prior approach was not sufficient.
Another approach is to use Model Reference.
Each parent and child in a Model Reference heirarchy can have a different Data Type Override setting.
There is risk of data type errors at the boundaries between a child model and the parent model.
To avoid these conflicts when using different data type override between parent and child,
configure the parent to just accept whatever data type the child proposes.
If the signals crossing the boundaries are just scalars, vectors, matrices, ..., then it's not too hard to achieve flexibility.
(If the signals crossing the boundaries are buses, then mixing Data Type Override settings can be very difficult.)
For parent signals leading to child model inputs put in Data Type Conversion Blocks set to inherit via backpropagation.
For parent signals coming from child model outputs, also put in Data Type Conversion Blocks, but set the non-override type on the output.
The attached set of models is an example with 3 different Data Type Override settings in successfully in effect.
There are also a few individual signals set to have DTO inheritance Off.
set_param('PositionController_MdlRefPair_Fxp','DataTypeOverride','Double')
set_param('Controller1_Fxp','DataTypeOverride','Single')
% Controller2_Fxp DataTypeOverride is Off
HTH,
Andy
3 Comments
Andy Bartlett
on 20 Oct 2020
Hi Dominik,
My team would like to contact you to see if we can unblock your workflow.
Please send me an email with your contract information.
-Andy
See Also
Categories
Find more on Data Types 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!