Executing the generated module under TwinCAT
In TwinCAT 3, a TcCOM module can be called directly from a cyclical real-time task or from another module, e.g. a PLC. To specify the behavior of the individual module instances, the method of execution can be defined in the TwinCAT 3 development environment.
Context settings
A list of all Simulink sample times for the module can be found under the Context tab of the module instance. If "SingleTasking" is selected in the solver settings of the Simulink model, the number of tasks is limited to 1:
For each of the contexts listed in the table a task has to be specified, through which the module is to be called. The task assignment varies, depending on the settings under "Depend On":
"Depend On" setting | Description |
---|---|
Manual Config | The tasks can be assigned manually in the context table, by selecting or entering the object IDs of the tasks in the Task column. The selected tasks must meet all the criteria that were configured via the "Call parameters". |
Parent Object | Can only be used if the parent node of the module instance is a task in the project tree. In this case, the parent object is used as cyclic caller of the module. |
Task Properties | The tasks are automatically assigned to the module when the cycle time and the priority correspond to the values specified in Simulink. If there is no corresponding task, new tasks can be created and parameterized as required under the node "System Configuration -> Task Management". |
Configuration in XAE
Parameters that affect the behavior of Simulink module execution are:
Parameter | Options / description | |
---|---|---|
CallBy | Task | The module automatically appends itself to the tasks specified in the context settings, when TwinCAT is switched to Run mode. The tasks call the module cyclically until TwinCAT is stopped. |
Modules | The module is not called directly by the assigned tasks, but it can be called from the PLC or another module. Important: The calling module must be assigned the same task as the TcCOM objects to be called. | |
Step size | RequireMatchingTaskCycleTime | The module expects the "Fixed Step Size" specified in Simulink as cycle time for the allocated task. Multitasking modules expect that all allocated tasks were configured with the associated Simulink sample time. Otherwise the module (and TwinCAT) cannot be started. The start sequence is then aborted with corresponding error messages. |
UseTaskCycleTime | The module enables cycle times, which differ from the "Fixed Step Size" specified in Simulink. In multitasking modules, all task cycle times must match the corresponding Simulink sample times. | |
UseModelStepSize | The module uses the SampleTime set in Simulink for all internal calculations. This setting is primarily intended for use in simulations within the TwinCAT environment. | |
ExecutionSequence | This parameter is only available in modules that were generated with TE1400 Version 1.1 or higher. It can be used to adjust the order of the calculation and communication process, in order to optimize jitter and reaction time for the respective application. Modules generated with TE1400 version 1.0 always use the order "StateUpdateAfterOutputMapping". The differences between the different options are described under "order of execution". | |
IOAtTaskbeginn | Execution order: | |
StateupdateAfterOutputMapping | Execution order: | |
StateupdateBeforeOutpunkUpdate | Execution order: |
Access to these parameter in the TwinCAT development environment (XAE) is provided via the object node under the following tabs:
- Parameter (Init) :
- Block diagram :
If none of these tabs are displayed, the Simulink coder settings need to be adjusted for parameter representation in XAE. |