Execute Real-Time Application with MATLAB Language

Run the real-time application with generated code to observe the real-time behavior of the model. This procedure uses the Simulink® model ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))). You must have already carried out the steps in Prepare Real-Time Application by Using MATLAB Language. In the model, select the output signal and mark the signal for data logging with the Simulation Data Inspector.

This example uses functions in the MATLAB Command Window to start and stop the real-time application. For more information about these functions, such as load, see SimulinkRealTime.target.

  1. In the MATLAB Command Window, type:


    The real-time application starts running on the target computer. In the Command Window, the status of the target object changes from stopped to running.

    Target: TargetPC1
    		Connected 			= Yes
    		Application 			= ex_slrt_rt_osc
    		Mode 			= Real-Time Single-Tasking
    		Status 			= running

    On the target computer screen, the Execution line changes from stopped to running. The AverageTET line is periodically updated with a new value.

  2. In the Command Window, type:


    The real-time application stops running.

    You can change many properties and parameters without rebuilding the real-time application. Two of these properties are StopTime and SampleTime.

  3. Change the stop time. For example, to change the stop time to 1000 seconds, type:

    tg.StopTime = 1000
  4. Change the sample time. For example, to change the sample time to 0.01 seconds, type:

    tg.SampleTime = 0.01


Some blocks produce incorrect results when you change their sample time at run time. If you include such blocks in your model, the software displays a warning message during model build. To avoid incorrect results, change the sample time in the original model, and then rebuild and download the model.

If you specify a sample time that is too small, a CPU overload can occur. If a CPU overload occurs, the target object property CPUOverload changes to detected. In that case, change Fixed step size to a larger value and rebuild the model.

See Also

Related Topics