CODESYS Tutorial: How To Get the Actual Cycle Time of a Current Task

By Zhou Gong, Control Engineer, Festo

Overview

  • Exploring the importance of task cycle time monitoring in control systems to improve efficiency, detect bottlenecks and enhance system stability.
  • Understanding the TIME() Function for measuring the time between events.
  • Understanding the CmpIecTask library, which is designed specifically for measuring task cycle time in control systems and offers microsecond-level precision. When in doubt, the CmpIecTask library should be your primary choice, as it offers greater precision and reliability compared to the TIME() Function.

Introduction

A software suite for automation technology, the Controller Development System (CODESYS) offers a comprehensive development environment for programming controller applications according to IEC 61131–3 industrial standards. It plays an important role in industries like manufacturing, energy and transportation to create control systems for various processes.

When it comes to automation and control systems, including those in CODESYS, it’s crucial to monitor task cycle times. Understanding this metric is important for optimizing performance, ensuring tasks are completed efficiently, identifying potential issues that may slow down the system and facilitating process synchronization to ensure the system runs smoothly without delays.

Whether you’re an engineer, technician or hobbyist working with automation systems, here’s a quick tutorial on how to obtain task cycle times in CODESYS, enabling you to improve your ability to optimize and troubleshoot your system.

Measuring Task Cycle Time and Common Challenges

Task cycle time is the period required to complete a specific task or operation within a control system. It starts when a task is initiated and ends when the task is completed. In CODESYS, task cycle time is a critical parameter that you can monitor and analyze in order to further understand the behavior of a particular process or function within the system.

Measuring task cycle time in CODESYS can present some challenges. Variations in system load, network latency and hardware performance can all affect the accuracy of measurements. Improper configuration or a lack of understanding the system’s intricacies can also lead to incorrect readings. Measuring task cycle times requires careful consideration of the system’s architecture, proper use of CODESYS tools and a clear understanding of the specific task being measured.

Measurement Methods: Understanding and Using the TIME() Function

Here are a few methods to measure actual task cycle time:

  • Using the built-in TIME() function.
  • Using the TIME() function to capture the start time before running the code.
  • Executing the code you want to measure. In this example, we use two for-loops to simulate a time-consuming task.
  • Using the TIME() function again to capture the end time after the code has run.
  • Determining the elapsed time by subtracting the start time from the end time.

The cycle time for the task in this example ranges from 6 to 8 milliseconds. You can add a trace to monitor the variable, providing additional insights into the cycle time. In this example, the cycle time occasionally jumps to 10 milliseconds. If you have a soft motion task defined with a cycle time of 4 milliseconds or less, however, exceeding this cycle time may cause exceptions.

In terms of pros, the TIME() function is straightforward to use, making it accessible even for those new to CODESYS. It also requires minimal code and can be quickly implemented into existing projects. On the other hand, the TIME() function provides a resolution in milliseconds, which may not be suitable for tasks that require higher precision or for applications that require microsecond-level accuracy.

Understanding and Using the CmpIecTask library

CODESYS includes the CmpIecTask library, which provides functions for accessing the IEC-Task manager. Once this library is added to a CODESYS project, initialization is a simple process, requiring only a few lines of code. After initialization, you can access a structure that contains detailed task information, including metrics like task cycle time and average cycle time. We have therefore retained the same working-load simulation code we used previously.

In terms of advantages, you can place the code utilizing the CmpIecTask library anywhere in the program, achieving flexibility in integration within different parts of the control system. The library also handles the recording and calculation of task cycle times, eliminating the need for manual tracking. This automation simplifies the process and reduces the potential for human error. Finally, with the use of the library, the cycle time is calculated at a higher resolution — in microseconds — which is far more precise than the values obtained from the TIME() function.

In terms of drawbacks, using the CmpIecTask library means adding a library to your CODESYS project. In short, however, this library offers a convenient way to access task information — including cycle time within CODESYS. Its flexibility and automation of cycle time calculations are significant advantages.

This article originally appeared in Medium on August 20, 2023.

Share This Post:

About Festo

For over 50 years in the US and almost 100 years globally, Festo has been a positive force for manufacturers. Our passion is automation — intelligent automation solutions that transform the way people work — and the way companies compete. Ultimately, it’s about continuously stimulating progress. In big ways and in small ways.

Copyright © 2024 - Festo Corporation. All Rights Reserved