TemperatureController_minimal

Description

The following example shows the basics of generating a TwinCAT module from a Simulink model.

Overview of project directory

TE1400Sample_TemperatureController_minimal.zip contains all the files required for reproducing this example:

TctSmplMinTempCtrl.mdl

Simulink much of a simple PI temperature controller.
TemperatureController_minimal  1:

TctSmplTempCtrlParameters.mat

Contains all the necessary model parameters.

TctSmplMinCtrlSysPT2.mdl

Simulink model of a simple PT2 controlled system (not used in the following description)

_PrecompiledTcComModules

This subdirectory contains readily compiled TwinCAT modules that were generated from the enclosed Simulink models. They enable the integration of a module in TwinCAT to be tested, without having to generate the module first. They can be used in situations where a MATLAB license is not yet available, for example. A quick reference guide for module installation on the development PC is also enclosed.

Info: To start the module on an x64 target system, the system must be switched to test mode!

_PreviousSimulinkVersions

The MDL files described above are stored in the file format of the current Simulink version. This subdirectory contains the models in the file format of elder Simulink versions.

Generating a TwinCAT module

1. Open TctSmplMinTempCtrl.mdl in Simulink
2. Start Model Explorer
3. Under Configuration -> Code Generation, select the System target file TwinCAT.tlc - either key in manually or use the Find button:
TemperatureController_minimal  2:
4. Close Model Explorer
5. Start code generation via the Simulink menu item Tools->Code Generation-> Build Model or via the toolbar icon Incremental build
TemperatureController_minimal  3:
The progress of the code generation is shown in the MATLAB command window.

Using the generated TwinCAT module

Open the TwinCAT development environment and create a new TwinCAT project. Expand node System in the Solution Explorer. Select the menu item Add new item in the context menu of node TcCOM Objects. The following dialog is displayed:

TemperatureController_minimal  4:

Select the generated module from the group Custom Modules -> Simulink generated modules. If XAE was started before the end of the code generation, first press the Reload button.

Add a new task using the context menu of the node System ->Tasks and configure the new task with the default parameters of the generated module:

TemperatureController_minimal  5:


The module (with its default settings) should then have been configured automatically for attaching to this task. To verify this, select the object node Object1 (TctSmplTempCt) and open the Context tab. The Result table should contain the object ID and the object name of the task, as shown in the figure below:

TemperatureController_minimal  6:


The configuration is now completed and can be activated on the target system.

1. Select the target system, the current configuration should be activated.
2. If there is no license, activate a free trial license in order to execute the modules generated with Simulink (TC1320 or TC1220) on the target system.
3. Activate the configuration on your target system. Confirm the question to overwrite the current configuration, and start the TwinCAT system.
4. The status symbol on the target should change its colors to green (running).
5. If the Block Diagram tab was selected, the block diagram state changes to "Online", and the Properties table shows some online values.
TemperatureController_minimal  7: