MATLAB: How to debug the Simulink model on the Target with xPC Target 5.0 (R2011a)

debugs-functionSimulink Real-Timetargetxpc

My model runs perfectly under Simulink on my computer but when I run it on the xPC Target it does not run as expected. I expect that there is a problem with a custom S-Function.
How can I debug my model and the S-Function on the xPC Target?

Best Answer

Given the real-time aspects of the xPC Target kernel, there is no direct way of debugging on the target. You can however insert PRINTF function calls in the source code of the S-Function or in a MATLAB Function block using CODER.CEVAL.
As printing text to the Target's display takes time, adding PRINTF calls to the model will result in an increased Task Execution Time (TET). In order to avoid overloads, you will want to slowdown the sample time of the model. It is also advisable to disable the graphics on the xPC Target. A Target with the target scope disabled is faster in displaying text and can also show more text. You can disable the target scope with the xPC Target Explorer under Configuration > Appearance.
A Simulink model that includes PRINTF statements in a simple S-Function and in a MATLAB Function block is available for downloading below. Please build the S-Function before running the model in simulation mode.