How to initialize Simulink Data Store Memories with Real Time Windows Target

15 views (last 30 days)
Hi!
I use Data Store Memories through various subsystems of my Simulink Model. I use the Data Store Memory Block in the model root level. In the field "Initial Value" of this block I entered a workspace variable "InitVal". If I compile (built) the Model for Real Time Windows Target, the value of InitVal is used as initial value of the Data Store.
And here is the problem: If I now change the value of the workspace variable InitVal (for example from a m-file), then connect to the target and start the simulation (both from a m-file), the initial value of the Data Store Memory is not updated. It stays at the value that InitVal had, when the model was built.
Is there any possibility to init a Data Store Memory in a compiled Simulink Model from a m-file? Without re-building.
Thank you very much for your answers! Arne

Answers (2)

Jan Houska
Jan Houska on 7 Feb 2013
You are correct that this does not work and it should. I'm filing a bug record for this.
To work around the problem, you can use Data Store Write together with an enabled subsystem. First, connect a Data Store Write block with constant with the value of InitVal. Then put these two blocks into an enabled subsystem. And, connect the enable port of the subsystem to an output of Clock compared with zero. This way, the Data Store is initialized by InitVal at simulation start and not affected later. If you are interested in an example model, please send me an e-mail.
  2 Comments
Arne
Arne on 7 Feb 2013
Edited: Arne on 7 Feb 2013
Hi Jan, thanks for your answer. I also thought of this workaround. And this workaround works (I just tried it).
But is there perhaps a possibility to initialize the Data Store by setting the Value from a m-file called at simulation start? In other words: Is there a way to set the value of a Simulink Data Store Memory with Matlab code?
Jan Houska
Jan Houska on 8 Feb 2013
I don't know about any possibility to write Data Store in compiled code using MATLAB code. Only parameters can be changed from MATLAB code, but the immediate value is not a parameter. The initial value is a parameter, but it is too late to change it after the model is loaded and initailized.
Currently, I think there is no workaround other than already presented above.

Sign in to comment.


Arne
Arne on 11 Feb 2013
Hi Jan,
I just found out, that the integrator-Block has the same problem with the init value. If you type a workspace variable "InitVal" in the "Initial Condition"-Textbox, the Init Value won't be updated if you change the value of "InitVal" in the workspace but don't rebuild the model!! I think, that's a bug, too.
But in this case, the workaround is easy: use an external init source and connect a constant with the "InitVal" workspace variable...
Or am I missing something?

Categories

Find more on Introduction to Installation and Licensing 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!