How do I get a real time clock in simulations using Simulink?
Date Last Modified: Thursday, July 22, 2010
| Solution ID: |
|
1-15JAW |
| Product: |
|
Simulink |
| Reported in Release: |
|
R12.1 |
| Platform: |
|
All Platforms |
| Operating System: |
|
All OS |
Subject:
How do I get a real time clock in simulations using Simulink?
Problem Description:
When I simulate my model, it executes really fast and I cannot interact with it. I would like to know how to get one second of simulation time to equal one second of wall clock time when simulating my model.
Solution:
It is possible to slow down a simulation to a rate close to real-time using hand written code.
The attached model illustrates how it is possible to slow down a simulation using the MATLAB Function block. In this example, the MATLAB function goes into a "busy wait" loop which kills time to slow down the simulation until the system clock catches up to the Simulink clock.
An example of a C MEX S-function used to slow down a model close to real-time can be found on the MATLAB Central File Exchange at the following address:
http://www.mathworks.com/matlabcentral/fileexchange/21908-simulink%C2%AE-real-time-execution
Note that the two above examples allow the system to run approximately in real-time, but not exactly. It should only be used to reduce the speed of a Simulink model so that a user can interact with it and observe the results in real-time.
For applications like Rapid Prototyping and HIL Simulation where accurate hard real-time is required, you should consider using xPC Target or Real-Time Windows Target:
http://www.mathworks.com/products/xpctarget/
http://www.mathworks.com/products/rtwt/
|
Related Documents/Files: