xPC Target    

Entering the Simulation Parameters

The simulation and real-time run parameters are entered in the Simulink Parameters dialog box. They give information to Real-Time Workshop for how to build the target application from your Simulink model.

After you load a Simulink model and boot the target PC, you can enter the simulation parameters. This procedure uses the Simulink model xpcosc.mdl as an example and assumes you have already loaded that model.

  1. In the Simulink window, and from the Simulation menu, click Parameters. In the Simulation Parameters dialog box, click the Solver tab.

    Simulink displays the Solver page. This page defines the initial stop and sample time for your target applcation.

  1. In the Start time box, enter 0 seconds. In the Stop time box, enter and initial stop time. For example, enter 0.2 seconds. You can change this time after creating your target application by changing the target object property tg.Stoptime.
  2. From the Type list, choose Fixed-step. Real-Time Workshop does not support variable step solvers. From the integration algorithm list choose a solver. For example, choose 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 seconds (250 microseconds). You can change this value after creating the target application.

    If you find that 0.000250 seconds 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, 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 page should look similar to the figure shown below.

  1. In the Simulation Parameters dialog box, click the Workspace I/O tab.

    The Workspace I/O page opens. This page defines which model signals are logged during the simulation of your model or the real-time run of your target application.

  1. In the Save to workspace section, choose the Time, State, and Output check boxes.

    To save (log) data from signals other than the state values, you need to add outport blocks to your Simulink model and connect the signals to the outport blocks.

    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 page should look similar to the figure shown below.

Normally all the check boxes are activated, except maybe in the following cases:

  1. In Simulation Parameters dialog box, click the Real-Time Workshop tab.

    The Real-Time Workshop page opens.

  1. Click the Browse button.

    The System Target File Browser opens.

  1. From the list, choose xpctarget.tlc xPC Target. Click Ok.

    The System target file xpctarget.tlc, the Template makefile xpc_default_tmf, and the Make command make_rtw are automatically entered into the page. The Real-Time Workshop page should now look like the figure shown below.

  1. From the Category list, choose xPC Target code generation options.

    The Real-Time Workshop page opens to the options page.

  1. From the Mode list, choose either Real-Time or Freerun. Freerun is similar to a simulation, but with the generated code.
  2. Select the Log Task Execution Time check box to log the task execution time to the target object property tg.TETlog. Selecting the Enable Signal Acquisition (Scope) Engine check box allows you to add scopes to the target PC.
  3. In the Signal Logging Buffer Size in Bytes box, enter the maximum number of sample points to save before wrapping. This buffer includes the time, states, outputs, and task execution time logs.

    For example, the model xpcosc.mdl has 6 signals (1 time, 2 states, 2 outputs, and 1 TET). If you enter a buffer size of 100000, then the target object property tg. MaxLogSample is calculated as 100000 / 6 = 1666. After saving 1666 sample points the buffer wraps to collect the next 1666 samples.

    If you select a logging buffer size larger then the RAM on the target PC, the target PC displays a message, ERROR: allocation of logging memory failed, after downloading and initializing the target application. In this case you need to install more RAM or reduce the buffer size for logging. In any case the target PC has to be rebotted.

  1. From the Interrupt Source list, select a source. The default value is set to Timer.
  2. In the Name of xPC Target object box, enter the a target object name. The default target object name it tg.

    The options page should now look similar to the figure shown below.

  1. Click OK.

Your next task is to create (build) the target application. See Building and Downloading the Target Application.


 Troubleshooting the Boot Process Building and Downloading the Target Application