Development, begins together.
Banner alanı
IFM Sensor

Looping Techniques in PLC Arrays

Cengiz Özemli

Academic
  • Dokuz Eylül Üniversitesi
  • 1771304474593_1_pnfjxqu0.jpg

    ## Looping Techniques Over Arrays in PLCs

    Arrays are used in PLC programming to process large datasets. However, when you want to extract a portion of this data, a loop structure is required. In this article, methods for creating loops in PLC logic and example applications will be shared.

    Loops in PLCs are program structures that execute a specific block of code a predetermined number of times. They are generally preferred for searching within arrays. Arrays are tags consisting of the same data type (e.g., INT, REAL) where each entry is accessed by an index. Loops allow access to the desired data by incrementing this index value.

    There are two main ways to create loops in a PLC: The first is done during the PLC scan cycle, and the second is accomplished using jumps and labels.

    When implemented correctly, loops offer easy searching in large data structures. However, if implemented incorrectly, they can lead to processor errors, stopping the program and potentially causing equipment damage.

    ### Looping with PLC Scan Cycle

    PLC logic is scanned from top to bottom, left to right. We can use this scan order to increment a pointer value and execute the logic. This method is easy for debugging and carries no risk of slowing down the processor.

    For example, for a 10-element array (Array1[0..9]), the data at the pointer index is evaluated and the pointer is incremented with each PLC scan. When the pointer reaches its limit, it is reset. This method does not require special blocks and preserves the PLC's scan order.

    ### Creating Loops with Jumps

    Loops can be established by jumping to labels that move up and down. In this method, the pointer indexes the array, and with each increment, new data is evaluated. The pointer is reset at the array's boundary, and the loop continues based on the jump condition.

    1771304474596_1_568skyxy.jpg

    Since the jump function alters the scan in this method, it must be used carefully. The label name must be unique, and the array must be at the very beginning.

    ### Processor Errors and Risks

    Two main errors can occur when indirect addressing is used in arrays: Data overflow and watchdog timeout. Data overflow occurs when the pointer goes outside the array's bounds, causing a processor error.

    A watchdog error occurs when loops run excessively long, causing the processor to become unresponsive. Infinite loops or too many nested loops can cause this. Such errors stop the program and shut down all outputs; in some cases, they can lead to equipment damage.

    ### Applications of Loops

    Loops are ideal for analyzing data in an array and are commonly used in part tracking applications, such as pallet or slot data. When used correctly and controlled, loops in PLCs are functional and practical.

    ### Technical Specifications

    • Loop types: Processor scan and jump/label
    • Arrays: Indexed data sets of the same data type
    • Pointer limit: Must be controlled according to array length
    • Error types: Data overflow, watchdog timeout
    • Loop risks: Infinite loops and processor slowdown

    PLC Loop Example


    1771304475281_3_t1qj1zrx.jpg
     
    Back
    Top