Question: What are the IO Idle Task and Plc Aux Task used for in TwinCAT, and how should their cycle, priority, and CPU allocation be set?
Background: Both the IO Idle Task and Plc Aux Task are automatically generated by TwinCAT with their cycle, priority, and CPU core automatically assigned. Given the flexibility of task configuration in TwinCAT, especially for TC3 users leveraging multi-core CPUs to balance CPU utilization, there's often a need to reassign tasks to different cores. This can sometimes lead to unexpected issues. Recently, colleagues and customers have encountered these situations
Here's my further understanding of these tasks:
IO Idle Task:
- Role: The IO Idle Task handles asynchronous communication between the master and slave devices in an EtherCAT network. This includes:
- Implementing state transitions for the EtherCAT Master.
- Sending mailbox commands (CoE, SoE, etc.).
- Initializing Distributed Clocks (DC) for the EtherCAT network.
- Checking and controlling the actual network topology.
- Execution Details:
- DC initialization, network topology discovery, and master state machine transitions are usually managed with default settings, automatically completed upon EtherCAT startup with minimal manual intervention.
- Users commonly need to adjust parameters or implement non-periodic mailbox commands, such as writing parameters from the Startup List to EtherCAT Slaves during initialization or using function blocks like FB_EcCoeSdoRead, FB_EcSoeRead during PLC operation, all managed by the IO Idle Task. Other communications like EoE (Ethernet over EtherCAT), FoE (File over EtherCAT), AoE (ADS over EtherCAT) are also facilitated through the IO Idle Task's mailbox channel.
- Configuration Considerations:
- Cycle:
- If there is significant non-periodic communication, adjust the IO Idle Task's cycle to reduce EtherCAT load (shorter cycle means faster communication but heavier load).
- The cycle should be between 1ms - 4ms.
- Priority:
- Should be lower than tasks requiring DC functionality, like those refreshing servos or XFC modules.
- If NC (Numerical Control) motion control is involved, the IO Idle Task's priority should be between SAF (Servo Adjustment Function) and SVB (Servo Velocity Bus).
- For NC interpolation movements, its priority can be even lower than SVB.
- CPU Allocation:
- Do not use automatic priority allocation in multi-core setups.
- It's recommended to place the IO Idle Task, along with PLC tasks and Plc AuxTask, on the first CPU core used by TwinCAT.
Plc Aux Task:
- Role: Manages ADS (Automation Device Specification) communications, where the PLC serves as an ADS Server to respond to requests from HMI or other TwinCAT ADS Clients, and as an ADS Client to send requests to other local ADS ports (NC: 501, other PLCs: 85x, OS: 10000, ScopeView: 14000) or to other controllers.
- Execution Details:
- This task deals with file operations by the PLC, various non-real-time Ethernet communications, all conducted in the background via ADS communication with different TwinCAT servers.
- Configuration Considerations:
- Cycle:
- Event-driven, no fixed cycle; the volume and frequency of communication can vary greatly.
- Priority:
- Set to the lowest priority as these are non-real-time tasks. It can consume significant CPU resources at times.
- CPU Allocation:
- Similar to IO Idle Task, placement on the first CPU core used by TwinCAT is advised.
- Monitoring:
- Use the TwinCAT Realtime Monitor to observe the execution sequence of PlcTask, Plc AuxTask, and Idle Task for performance tuning.
The above diagram shows that the Plc Aux Task runs during idle ticks when both the PlcTask and Standard tasks are not active. However, since the PLC program used for the screenshot is very small, this does not conclusively prove that the Plc Aux Task always selects ticks where PlcTask does not need to run. For instance, if the PlcTask also has a 1ms cycle, there would be no idle ticks available.
The exact mechanism is not publicly disclosed, but when diagnosing your own project, you can use the Realtime Monitor to deeply analyze the execution of each task to pinpoint issues. For example, when zoomed in, the diagram shows that the actual execution time of the Plc Aux Task is 18.2 microseconds:
If your project involves a large amount of ADS communication, you can enable different communication combinations to analyze which type consumes the most time. If the Plc Aux Task uses too much CPU resources, you might consider assigning it its own core or placing it on a CPU core that has lighter task loads.
Summarizing, the cycle, priority, and CPU allocation for Plc Aux Task are as follows:
- Cycle:
- Set to zero; no need to configure.
- Priority:
- By default, maintain the lowest priority.
- CPU:
- Preferably, place it with the PLC Task and IO Idle Task on the first CPU core available for TwinCAT. If issues arise or if the utilization of the first core is already high and the AuxTask is time-consuming, you can move the AuxTask to a core with less critical tasks and lighter load.
- Do not share a core with tasks like NC or XFC which require high Distributed Clocks (DC) accuracy, to avoid impacting these latency-sensitive tasks.
Conclusion:
For everyday simple applications or small projects, users typically pay little attention to the IO Idle Task and Plc Aux Task, sticking with the default configurations. However, in large projects, projects involving XFC, or those with high communication volumes, understanding these principles provides an additional avenue for troubleshooting when intermittent issues arise. Carefully review whether these tasks are set up correctly and if they could potentially cause problems on-site. Temporarily disabling certain communications or adjusting settings can help narrow down the troubleshooting scope.