Real-time workshop - using external time management
13 views (last 30 days)
Show older comments
I'm quite new to Matlab/Simulink. I am studying all the documentation but still can not find solution.
I am using Simulink to create a model and Real-Time Workshop to convert it to C++ code. Then, I have to integrate this code automatically generated, within other existing code. I can do it.
The existing C++ code can properly handle the inputs and outputs of the model. To do this I set the storage class of those signals such as ImportedExtern.
But now I need to use in the Simulink model an externally generated clock presented in the existing C++ code. I can do this? I'm trying to understand how time is handled in the simulation and which blocks can be involved.
Perhaps the question has a simple answer, most of what I think. I hope I was clear enough.
Thank you in advance.
0 Comments
Answers (2)
Guy Rouleau
on 18 Feb 2011
RTW will generate a "step" function. You just need to use your external clock to call this "step" function in your C/C++ application at the right time.
Typically, you need to call the "step" function at the same rate as the one specified in the model. That way, the "step" function will automatically increase its time internally.
If you want to call the "step" function asynchrounously, or at non-constant intervals, you should ensure that your model is sample time independant, as explained here:
http://www.mathworks.com/help/toolbox/simulink/gui/bq7cmsp-1.html#bq990zm-1
2 Comments
Kaustubha Govind
on 23 Feb 2011
The step function is generated as rt_OneStep, which you can tie in to your clock. I'm not sure what you mean by passing in a time variable - is this just something that the function must use as any other parameter, or do you want the model to somehow act upon this input by automatically running at the given frequency? AFAIK, the latter is not possible.
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!