TwinCAT is a time-slicing, multitasking real-time system. In the TC2 era, all tasks ran on a single CPU core, and usually, automatic priority sorting was sufficient. In the TC3 era, with support for multi-core CPUs, tasks can be assigned to different cores. By default, when creating a TC3 project, all tasks are assigned to Core 0. To fully leverage the multi-core computing capabilities of the CPU, some tasks must be manually assigned to other CPU cores.
Unlike single-core projects in TC2, in TC3, two tasks running on different CPU cores cannot have their execution order strictly controlled, which can lead to issues with data consistency and unpredictable I/O refresh sequences, potentially causing unforeseen consequences.
This public account has previously published two articles on TwinCAT task management, discussing in detail the work content and characteristics of several typical tasks, along with recommended configuration rules:
- IO Idle Task and Plc Aux Task
- CPU Allocation for PLC and NC Tasks
Considering that some users are pressed for time and do not wish to delve into the underlying mechanism
Task Category | Task Function | Cycle | *Priority | **Recommended CPU Core |
---|---|---|---|---|
NC Task | Handling NC axis computation and servo data refresh | >=1ms e.g. 2ms | Higher than non-NC, non-XFC tasks | 2nd CPU core for TC, isolated core preferred |
Motion-related Tasks | PLC tasks for axis control (if separable) | e.g. 10ms | Not specified | Same core as NC Task, isolated core preferred |
PLC Task NC | Task where Axis_Ref is located (if axis control cannot be separated) | e.g. 2ms | Not specified | Same core as NC Task, isolated core preferred |
PLC Task XFC | PLC task for variables associated with XFC modules | e.g. 1ms | Higher than non-NC, non-XFC tasks | Isolated core preferred |
Non-Motion Tasks | Other logic | e.g. 10ms | Not specified | Different core from NC Task |
IO Idle Task | Handling asynchronous communication between master and slave | 1-4ms | After NC and XFC tasks | Different core from NC Task, 1st core for TC preferred |
Plc Aux Task | Responding to ADS requests, e.g., HMI, Scope View | N/A | Lowest | Different core from NC Task, preferably same as IO Idle Task, or can be moved elsewhere |
Task Category | Task Function | Cycle | *Priority | **Recommended CPU Core |
---|---|---|---|---|
NC Task | Handling NC axis computation and servo data refresh | >=1ms e.g. 2ms | Higher than non-NC, non-XFC tasks | 2nd CPU core for TC, isolated core preferred |
Motion-related Tasks | PLC tasks for axis control (if separable) | e.g. 10ms | Not specified | Same core as NC Task, isolated core preferred |
PLC Task NC | Task where Axis_Ref is located (if axis control cannot be separated) | e.g. 2ms | Not specified | Same core as NC Task, isolated core preferred |
PLC Task XFC | PLC task for variables associated with XFC modules | e.g. 1ms | Higher than non-NC, non-XFC tasks | Isolated core preferred |
Non-Motion Tasks | Other logic | e.g. 10ms | Not specified | Different core from NC Task |
IO Idle Task | Handling asynchronous communication between master and slave | 1-4ms | After NC and XFC tasks | Different core from NC Task, 1st core for TC preferred |
Plc Aux Task | Responding to ADS requests, e.g., HMI, Scope View | N/A | Lowest | Different core from NC Task, preferably same as IO Idle Task, or can be moved elsewher |
Here are some basic operations which experienced TC3 users can ignore:
- Real-Time Settings Interface
- Task Configuration and CPU Core Specification Settings
2 .Priority Setting
*Do not use automatic priority settings.
**For CPUs with 4 or more cores, you can reserve one core for Windows, setting the others as isolated cores for TwinCAT use only.
***If the axis control program cannot be separated, create a new Task specifically for refreshing Axis_Ref, see: CPU Allocation for PLC and NC Tasks.
Appendix 1: Shared / Isolated Cores
- By default, all tasks are set to Core 0. For multi-core CPUs, you need to first 'Read From Target', then 'Set On Target', with changes taking effect after a controller restart. For CPUs with 4 or more cores, you can set 3 cores as Isolated, assigning all TwinCAT tasks to these Isolated cores while letting Windows use one core exclusively. For a 2-core CPU, allocate 1 Isolated core. Tasks with high real-time requirements, like NC and XFC, should be placed on isolated cores.
Appendix 2: Router Memory
- The default Router Memory setting is 32M, which is the minimum allowed by Beckhoff's smallest controllers. For larger systems like CX20xx or C603x, which often require more ADS communication, it's necessary to set a higher Router Memory, for example, 1024M.
Appendix 3: Stack Size
- The default Stack Size is set to 64K, again the minimum allowed by Beckhoff's smallest controllers. For larger systems like CX20xx or C603x, which might need more stack space, it's advisable to set a larger Stack Size, for example, 1024K.