Skip to main content

Fieldbus Devices and I/O Drivers

The technical basis for each fieldbus device configured in the device tree is the I/O driver.

The I/O driver is the link between the fieldbus stack, the IEC application, and the IDE. The driver configures the fieldbus stack from the data of the device configuration. It provides diagnostic information, offers an API for the IEC application, and is responsible for the I/O mapping.

This chapter provides a brief overview of the basic functionality of I/O driver devices, without discussing the details of specific bus systems. Some recommendations for the configuration are also provided.

Bus cycle task

The bus cycle task is the IEC task with the context where the I/O driver is executed. Some I/O drivers use multiple tasks: usually one real-time-critical task (with high priority), which is used for the transfer of I/O data, and another task with low priority for tasks such as evaluating diagnostic data and executing acyclic services of the bus system.

With real-time-critical bus systems, it must be ensured that no operations are executed in the context of this bus cycle task which would interrupt the bus cycle task due to the execution time.

The bus cycle task can be configured in the I/O mapping dialog of the I/O driver device. Note that the settings of the parent device are inherited by default. If this device is the PLC, then its PLC setting applies in the bus cycle task.

Important

If the bus cycle task is not configured, then the task with the shortest cycle time is used. In this way, a non-real-time I/O driver may be executed unintentionally in the task context of a real-time-critical driver, thus interrupting its communication. To diagnose these communication problems, checking the task monitoring is recommended.

For more information, see the following: Bus Cycle Options

I/O mapping

An essential function of an I/O driver is to update the I/O mapping. This means the mapping of the I/O data of the bus system to variables of the IEC application, and vice versa.

The I/O data is mapped cyclically by copy and conversion operations in both directions from the internal memory image of the bus system to IEC variables assigned to the %I and %Q addresses.

For the I/O driver, there is no internal difference whether symbolic names or "direct" access to the %I and %Q addresses are used for this I/O mapping. For the maintainability of the application, always using descriptive variable names is recommended – for example, a "TemperatureReactor" variable instead of "%IW117" access.

Updating the I/O mapping can be set with Always update variables – globally in the PLC Settings or individually for each device in the I/O mapping dialog:

  • Disabled:

    Only I/O data used in the application is mapped.

    This may improve performance by avoiding the copy operations, but may cause confusion if the I/O data in the I/O mapping dialog is not updated – the values are then grayed out. This setting is recommended for an application with a completed development.

  • Enabled 1:

    All data is updated.

  • Enabled 2:

    Important

    The availability of this option depends on the device description.

    Caution: For productive use in special cases only.

    As a result, inconsistent I/O data may occur because the bus cycle task reads and writes this data while the application code uses it in other tasks.

For more information, see the following: Tab: <device name> I/O Mapping

Consistency of I/O data

The programming system allows the IEC application to use multiple tasks executed in parallel – for visualization, field buses, or other POUs. The application code can access I/O data from the context of these tasks via the mapped IEC variables. By accessing the same data from different tasks, inconsistent or corrupt data could occur – for example, due to interrupted write access.

The I/O driver ensures data consistency by providing each task executing a task cycle with a consistent mapping – a snapshot, so to speak – of all I/O data used.

Thus a code as in the following example cannot cause problems: Note DIV_BY_ZERO

IF(inputData <> 0) THEN              // inputData is mapped to %I
    x := y / inputData;              // This will never result in DIV_BY_ZERO Exception
END_IF                               // inputData is not updated by bus cycle during execution of POU

Important

This mechanism is overridden with the Always update variables option set to Enabled 2 – always in bus cycle task. Accordingly, the application code must take this into account.

Services

In addition to the basic functionality, some I/O drivers provide services that can be called from the IDE, such as the device scan function or the setting of device addresses.

General recommendations

. Settings:
  • PLC Settings: _cds_icon_checked.png I/O updates in stop:

    The bus cycle continues even when the application is stopped, for example when the application is on a debug breakpoint. In this way, communication with the field devices is maintained and can be continued immediately without interruption.

  • PLC Settings: Always update variables is set to Enabled 1 – use bus cycle task if not used in any task:

    During the development of the application, it is useful to see the values of all I/O data.

. Task configuration:
  • Especially for real-time-critical fieldbus systems such as PROFINET, EtherCAT, or CAN, which depend on maintaining an exact send/receive cycle, using a separate bus cycle task with high priority is recommended. For less real-time-critical tasks – visualization, for example – a significantly lower priority should be selected than for the bus cycle task.

  • In order to achieve maximum I/O throughput with as little offset as possible, separate POUs can be executed in the bus cycle task of the fieldbus system. However, these then must meet the real-time requirements – for example, no file access or blocking socket functions may be executed, but only the calculation of the output data.

Troubleshooting for multiple I/O drivers and tasks

If consistent access to I/O data from multiple tasks and possibly across multiple I/O driver instances need to be synchronized, then unwanted reciprocal interference between the bus task and application task may occur under certain circumstances.

This happens in the following cases, for example:

  • The overall system load is high.

  • The same task uses I/O data from the real-time-critical fieldbus system and I/O data from a slow and blocking local bus system.

If unexpected communication interference occurs with the particularly real-time-critical fieldbuses EtherCAT, PROFINET or CAN, then first check the task monitoring. Pay attention to particularly high jitter and outliers in the cycle time. To do this, compare the maximum value with the average value of the cycle time.

The Task Deployment tab shows details about which tasks are using which I/O data. Check if any of the following measures can be implemented:

  • Use I/O data from different bus systems in separate tasks.

  • Reduce the number of I/O tasks.

For more information, see the following: Tab: Task Deployment

Recommendations for task configuration

Caution

Make sure that no other fieldbus, such as Modbus, unintentionally gets included with the high-priority tasks. This happens, for example, via the standard task assignment "use parent".

  • Use a separate task with priority 0 or 1 for each particularly high real-time-critical fieldbus, such as EtherCAT or PROFINET.

  • Never use two tasks with the same priority in a project.

  • Create as few tasks as possible in the project. More than 5 to 6 tasks are useful in exceptional cases only.

  • Always offload blocking calls to low-priority tasks. Access to the file system is a blocking call, for example.

  • Process the I/O data in the bus task of the respective fieldbus as directly as possible. However, perform calculations in the bus task only. Avoid blocking calls such as memory allocation or semaphores there.