Quick start

Starting with a simple Simulink® model

Feel free to use our built-in samples for first steps with the TwinCAT Target for Simulink®. The MATLAB® Command Window provides a list of available samples via TwinCAT.ModuleGenerator.Samples.List
1. For example, select the SimpleTemperatureController and start the sample using the Start link in the Command Window.
Quick start 1:
In the following, the Quick start is executed along this sample.
2. Start at the beginning by selecting the button Open the model in the Live Script.
For the further configuration steps in Simulink® you can simply click the next button in the Live Script.
Quick start 2:

Beginner video

The following video (only available in English) can also be used as an introduction: TwinCAT Target for Simulink®

The configuration steps in Simulink®

1. Select a fixed-step solver. To do this, go to the Configuration Parameters of the model.
Quick start 3:
2. Select the system target file to "TwinCatGrt.tlc".
Quick start 4:

Optional: Under Optimization, set the parameter Default parameter behavior to Tunable so that you can continue to change model parameters in TwinCAT. See also Parameterization of a module instance.

3. Save your changes in the Simulink® model.
4. Start code generation via the Simulink CoderTM App.
Quick start 5:
Quick start 6:

Insert TcCOM in TwinCAT

1. Open TwinCAT (TwinCAT XAE or TwinCAT in a Visual Studio environment).
2. Instantiate a new TcCOM object.
Quick start 7:
3. Select the desired object.
Quick start 8:
4. Create a cyclic task.
Quick start 9:
5. Assign the created task to your TcCOM instance.

Note that the cycle time of the task and the SampleTime in Simulink® (here 5 ms) match.

Quick start 10:
6. Activate the configuration.
Quick start 11:

Configure and link TcCOM instance

The data exchange of the TcCOM instance takes place via mappings of the process image. Simulink® inputs and Simulink® outputs are automatically mapped as inputs or outputs in the process image and can be linked to I/O or other objects.

In the Parameters (Init) area of the TcCOM instance, you can optionally configure the instance differently than specified when it was created from Simulink®.

Quick start 12:

For example, you can set the parameter Kp to "52" here. The TcCOM module would then use this value as the startup value for this instance.

Insert as PLC function block

The PLC library used in the following is only available if the following parameters are set in Simulink®:

Quick start 13:

If these options have not been set, this can be done subsequently without using Simulink® and the TwinCAT Target for Simulink®. See Create and install PLC library.

Brief overview of action steps PLC library/function block

Quick start 17:
Quick start 18:

Calling a TcCOM object also possible from the PLC

In addition to the variant described here, you can also call an instance of a TcCOM from the PLC. See Applying the TcCOM Wrapper FB.