xPC Target    

Entering Parameters for Outport Blocks

During a simulation, Simulink saves signal data to MATLAB variables using Outport blocks. The default MATLAB variables are tout, xout, and yout. While running a real-time application, xPC Target uses these same variables to pass signal data to target object parameters. A target object is a structure in the MATLAB workspace that xPC Target uses to interact with a target application. The default target object is tg, and the default parameters are tg.Time, tg.States, and tg.Output.

After you add an Outport block to your Simulink model, you can enter parameters. This procedure uses the model xpc_osc1.mdl with an outport block as an example. To add an Outport block, see Adding a Simulink Outport Block.

  1. In the MATLAB Command Window, enter
  1. A Simulink window with the model xpc_osc1 opens.

  1. In the Simulink window, from the Simulation menu, click Simulation Parameters.
  1. The Simulation Parameters dialog box opens.

  1. In the Simulation Parameters dialog box, click the Solver tab.
  1. Simulink displays the Solver pane. This page defines the initial stop and sample time for your target application.

  1. In the Start time box, enter 0 second. In the Stop time box, enter an initial stop time. For example, enter 20 seconds. To change this time after creating your target application, change the target object property tg.Stoptime to the new time using the MATLAB command-line interface.
  2. From the Type list, select Fixed-step. Real-Time Workshop does not support variable step solvers. From the algorithm list, select a solver. For example, select the general purpose solver ode4 (Runge-Kutta). In the Fixed step size box, enter the sample time for the target application. For example, enter 0.00025 second (250 microseconds). You can change this value after creating the target application.
  1. If you find that 0.000250 second results in overloading the CPU on the target PC, try a larger Fixed step size such as 0.002 seconds.

    If your model contains discrete states, which would lead to a hybrid model with both continuous and discrete states, the sample times of the discrete states can only be multiples of the Fixed step size. If your model does not contain any continuous states, enter 'auto', and the sample time is taken from the model.

    The Solver pane should look similar to the figure shown below.

  1. On the Simulation Parameters dialog box, click the Workspace I/O tab.
  1. The Workspace I/O pane opens. This page defines which model signals are logged during a simulation of your model or while running your target application.

  1. In the Save to workspace section, select the Time, States, and Output check boxes.
  1. Note When running your target application in real time, data is not saved to the variables tout and yout. Instead, data is saved to the target object properties TimeLog, StateLog, and OutLog. However, you must still select the Time, States, and Output check boxes for data to be logged into the target object properties.

    The Workspace I/O pane should look similar to the figure shown below.

Normally you select all of the Save to workspace check boxes. However, you may want to consider clearing some or all of them off in the following cases:

  1. Click OK.
  2. From the File menu, click Save. The model is saved as xpc_osc1.mdl.

Your next task is to add an xPC Target Scope block to your Simulink model. See Adding an xPC Target Scope Block.


  Adding a Simulink Outport Block Adding an xPC Target Scope Block