quarc_system_timebase_demo.mdl
Open this model

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

quarc_system_timebase_demo

QUARC System Timebase Demo

This example demonstrates how to use the System Timebase block from the QUARC Targets library to allow a normal simulation to be run in real-time. This demonstration highlights benefits and limitations of using this block. For details of this block, please refer to the System Timebase block reference page in the QUARC documentation.

System Timebase Demo Simulink Diagram

The System Timebase block allows the model to run in very soft real-time in normal mode without having to generate and compile code which saves time attempting to build the model. In addition to the System Timebase block, we have included the Host Mouse and Host Keyboard blocks from the QUARC Targets library in this model. The reason for including these blocks is to demonstrate the fact that with the System Timebase block, you can read data from an input device in real-time when running a normal simulation. For more information on the Host Mouse block, please refer to the Host Mouse block reference page. There is also a demonstration on this block called the QUARC Host Mouse Demo to which you can refer. For more information on the Host Keyboard block, please refer to the Host Keyboard block reference page. There is also a demonstration on this block called the QUARC Host Keyboard Demo to which you can refer.

Warning Although the System Timebase block can be useful since it saves the time it takes to build a model, it should never be used for real-time control applications. In particular, the running model stops when double-clicking on a block to change a parameter (e.g., online parameter tuning). It might just stop as well when moving the Simulink model window. Therefore, THE SYSTEM TIMEBASE BLOCK SHOULD NOT BE USED TO RUN A REAL-TIME CONTROLLER CONNECTED TO AN ACTUAL PIECE OF HARDWARE, as such a controller might stop and make the hardware go unstable for a variety of reasons. To summarize, you can read data from an input device but should never write data to an output device when using the System Timebase block in normal simulation.

Configuring the Demonstration

To set up the demonstration, open the Model Properties by choosing the File/Model Properties menu item in the model window. Navigate to the Callbacks pane and select the PreLoadFcn item. In the Model pre-load function field, check that the K, tau, Kp and Ki variables are all initialized here. These variables will be used as the plant's DC gain, its time constant, the controller's proportional and integral gains respectively. You can change these variables, close and re-open the model to apply the changes.

Demonstration

Double-click on the Scope block to display the actual signal vs. the desired signal.

Start the model by clicking on the Run button on the SIMULATION tab.

The Scope will display the desired (yellow) vs. actual (magenta) signals.

System Timebase Demo Scope

Notice how the model is being run in real-time as opposed to a simulation without the System Timebase block in which the time passes by as fast as possible.

Now, press on the F1 key on the keyboard to change the source of the desired signal to the mouse' X coordinate. While holding the F1 key, move the mouse back and forth in the X direction. The Scope is now tracing a the path taken by the mouse cursor in the X coordinate as the desired signal while the actual signal (the output of the plant) is trying to catch up with the desired signal.

System Timebase Demo Scope

While the model is running in normal mode, try to move around the diagram window. As a matter of fact, the moment you click on the left mouse button while the cursor is inside the model window, the model stops running and the Scope stops tracing the signals. As another test, double-click on the Signal Generator block to change one of its parameters (online parameter tuning). Once this block's parameters window pops up, the model stops again and the Scope stops tracing the signals one more time.

To highlight the System Timebase limitation, consider the case where the output of the plant would actually be written to an actual piece of hardware instead of being fed into the Scope block). The moment you pause the simulation (be it online parameter tuning or just moving around the model window) the hardware will go unstable.

Click on the Stop button on the tabref name="SIMULATION"/> tab to stop the model.

Running the example on a different target

To run the example on a different target, refer to the instructions on the Running QUARC Examples on Remote Targets page.