xPC Target | ![]() ![]() |
Signal Logging with MATLAB Commands
You analyze and plot the outputs and states of your target application to observe the behavior of your model, or to determine the behavior when you vary the input signals.
Time, states and outputs. Logging the time, state, and output signals is possible only if you add, before the build process, outport blocks to your Simulink model, and in the I/O-Workspace page select the Save to workspace check boxes. See Entering the Simulation Parameters
Task execution time. Plotting the task execution time is possible only if you select the Log Task Execution Time check box in the xPC Target code generation option page. See Entering the Simulation Parameters.
After you run a target application, you can plot the state and output signals. This procedure uses the Simulink model xpcosc.mdl
as an example, and assumes you have created and downloaded the target application for that model.
The target application starts and runs until it reaches the final time set in the target object property tg.StopTime.
The outputs are the signals connected to Simulink outport blocks. The model
xpcosc.mdl
has just one outport block labeled 1 and there are two states.
This outport block shows the signals leaving the blocks labeled Integrator1
and Signal Generator.
plot(tg.TimeLog,tg.Outputlog) figure plot(tg.TimeLog,tg.StateLog)
Values for the logs are uploaded to the host PC from the target application on the target PC. If you want to upload part of the logs, see the target object method getlog.
The plots shown below are the result of a real-time execution. To compare this plot with a plot for a nonreal-time simulation, see "Running a Simulation Using the Simulink Graphical Interface" on page 3-4.
The task execution time (TET) is the time to calculate the signal values for the model during each sample interval. If you have subsystems that run only under certain circumstances, plotting the TET would show when subsystems were executed and the additional CPU time required for those executions.
After you run a target application, you can plot the last execution time. This procedure uses the Simulink model xpcosc.mdl
as an example, and assumes you have created and downloaded the target application for that model.
plot(tg.TimeLog,tg.Outputlog) figure plot(tg.TimeLog,tg.TETLog)
Values for the logs are uploaded to the host PC from the target application on the target PC. If you want to upload part of the logs, see the target object method getlog.
The plots shown below are the result of a real-time run. The output is shown on the left and the task execution time is shown on the right.
tg.AvgTET or get(tg,'AvgTET')
MATLAB displays the following information.
ans = 0.000009
In the example above, the minimum TET was 8 µs, the maximum TET 11 µs, and the average TET 9 µs. This means that the real-time task has taken about 3 % of the CPU performance (Average TET of 9 µs / Sample time of 250 µs).
![]() | Signal Logging with xPC Target Graphical Interface | Signal Tracing | ![]() |