GE / IP FANUC Series 90/30 In Stock

World's Largest Warehouse

of GE 90-30, Genius, and RX7i

Mon-Fri 8AM-5PM EST


PLC Algorithm Implementation

Programmable Logic Controllers (PLCs) are used as a hardware platform on which a control program is executed. They are the most popular and powerful devices used in industrial process control applications. A PLC program or algorithm can be defined as a combination of various functions that are needed to automate a given task. Automation principles are developed to substantially aid process control using PLC systems in a variety of industrial automation applications. While a PLC program is created by the user and downloaded onto the CPU of the PLC.

Once the user program is downloaded to the CPU, and if the PLC is set in Run mode, it will continuously function according to the program. Hence, PLC programming is an essential task in designing and implementing control algorithms based on users’ needs. A PLC program consists of a set of user-defined instructions and commands either in graphical or textual form, which represent the algorithm to be implemented for specific real-time control tasks.

PLC Algorithm Development  

In simple terms, developing a PLC algorithm is the same as programming a PLC or writing a user-defined PLC program. In the current industrial automation sector, several leading PLC manufacturers have been developing typical PLC controllers ranging from low- to high-end PLC systems. Each and every PLC manufacturer provides a dedicated PLC programming software that allows the entry and development of user application programs. The user application code is then downloaded to the PLC hardware to program and configure the hardware. Even though a given PLC software can only be compatible with specific PLCs, there are IEC 61131-3 standardized PLC programming languages. Therefore, your choice for a PLC programming language will depend on your PLC manufacturer specifications. Some PLC manufacturers have common IEC 61131-3 programming languages, while others have dissimilar languages.

The IEC 61131-3 standardized PLC programming languages are basically divided into two types: (i) Graphical Programming Languages including Ladder Diagrams (LD), Sequential Function Chart (SFC), and Function Block Diagram (FBD). (ii) Textual Programming Languages which include Structured Text (ST) and Instructions List (IL). Many PLC systems users prefer using graphical languages to text-based languages, as the former consists of simple and convenient features which can be used to easily program PLCs. Ladder Logic or Ladder Diagrams (LD) is one of the most commonly used of the various IEC 61131-3 standardized languages. It is a graphical PLC programming language with a representation similar to that of relay-circuit diagrams. PLC programs written in Ladder Diagrams are ladder-like symbolically, while their commands are written into rungs.
Note, all the functions and functional blocks required when writing a PLC program are available in the standard library of every PLC software. These function blocks include strings, counters, timers, arithmetic, numeric, calling functions, bit shift, etc. The complete set of command-based instructions in a PLC software varies slightly from one PLC manufacturer to another. Also, the PLC software ensures that the HMI (Human Machine Interface) has a graphical representation of the program variables.

What is PLC Algorithm Implementation? 

Traditionally, PLCs have been used for Proportional-Integral-Derivative (PID) control or for simple ON-OFF control schemes. However, the recent technological developments have allowed even small-end, low-costs PLCs to implement more advanced and efficient user-defined algorithms. PLC Algorithm Implementation is all about how a PLC executes a given user-defined program; or rather it’s the way a programming task is accomplished by the PLC logic. Some of the tasks accomplished by a typical user-defined PLC program include: (i) Initiating all the conditions and parameters for starting a specified control task. (ii) Reading and evaluating all discrete and analog input signals. (iii) Specifying the appropriate output signals to all discrete and analog output devices. (iv) Executing interrupts as well as handling errors.

All the program logic happens in the CPU of a PLC, which is a -32 bit or -16-bit microprocessor with a memory chip and integrated circuits for communicating, monitoring, and controlling logic. With the CPU serving as the brain of the PLC, it carries out logic and arithmetic operations, communicates with I/O devices, and performs internal diagnostics. It also directs the PLC to execute the user program, whose algorithm comprises of a set of control instructions. This article explains how the CPU of a PLC executes and implements user-defined algorithms for various control tasks.

How does a PLC Implement an Algorithm? 

First off, a PLC is a special computer designed for industrial process control applications, it is connected to the processing unit through an Input/ Output module. While there are a variety of specific applications for different PLCs, all PLCs monitor data from input devices and other variables, and make decisions to control the outputs based on a stored user-defined program, ultimately automating a given process or machine.

For the PLC to function as programmed, it must continuously communicate with the field I/O devices it is tasked to monitor and control. Various communication protocols are available for use with PLC control systems including EtherNet/IP, Modbus, Interbus, ProfiNet, ControlNet, and DeviceNet. The PLC then compares the actual conditions of the field input devices with what its algorithm instructs them to do and updates the field output devices accordingly. PLC operation is thus simple. The operational sequence is as follows:

  • The input switch is pressed  
  • Then, the PLC input module puts a “1” into the input data table, 
  • The developed PLC algorithm (can be a Ladder Diagrams program) notices the “1” and causes the “1” to be placed in the output data table,
  • The output data table makes the PLC output module to energize the associated output, 
  • The output field device gets energized as well. 
  • The input switch is pressed again, and the execution process restarts

As previously mentioned, the PLC’s processor (CPU) makes control decisions based on an algorithm/ program developed by the user. Then, the big question is, how does the CPU interpret and execute the user-programmed logic stored in the PLC software? Normally, the CPU implements a PLC algorithm by continually scanning user-defined programs in cycles with three main steps.

The CPU Operating Cycle

Typically, a CPU operating cycle consists of more than 3 three steps namely (i) Start scan; (ii) Internal Checks; (iii) Scan Inputs; (iv) Execute program logic; and (v) Update outputs. But in this article, we’ll categorize the five steps into three important steps, which include: 

A) Step 1-Check Input Status: When a PLC starts, the CPU runs checks on the software and hardware for faults, a process known as self-test. If the CPU detects no problems, then it will start the scan cycle. With the first step being to check the Input Status. At this stage the CPU takes an image of all the inputs and saves it in the RAM (Random-access memory). In other words, the CPU checks each input module to determine if the input is ON or OFF, and it records this information in a data table to be used in the next step.

For instance, the CPU will check if the sensor connected to the first input is on and save a binary value into its memory representing that particular input. It then goes to the second input and does the same, then to the third and so on. Let’s say you have a PLC with 6 discrete inputs, in which only the last input is ON or HIGH while the others are OFF or LOW. In such a case, when the CPU checks the status of all the 6 inputs, it will save the following binary number 000001. With each 0 representing a digital input with a low value, and 1 representing the last digital input with a high value. This makes implementation of the PLC algorithm much faster and prevents cases of an input changing its state from the start to the end of the PLC program.

B) Step 2-Execute Program Logic: After the CPU has checked the status of all the PLC inputs, it will then execute the program. Simply, the logic program you had written will now run. To implement a given algorithm, the CPU examines the user-defined program line by line; that is, one instruction at a time using only the memory copy of the inputs checked in Step 1. This is the way a PLC processor solves its logic.

For example, if your program requires that if the last input was ON then the PLC should turn the last output ON. And since the processor already knows which inputs are ON or OFF from Step 1, it will be able to decide whether the last output should be turned ON based on the state of the last input. The CPU will then store the execution results to be used during the next step. These results will be the output status as the logic of your PLC program has decided.

C) Step 3-Update Output Status: This is the final step, in which the processor of the PLC updates the status of the outputs to control the field output devices. The CPU updates the outputs status based on which inputs were ON during Step 1 and the results of executing the program logic in Step 2. Based on the example given in Step 1, the CPU would now turn the last output ON, because the last input was ON and your program required the PLC to turn the last output ON when this condition is true. After this step, the CPU will restart the PLC algorithm implementation process by initiating a self-check for internal faults, and it will repeat the other steps continually.

In a real-world scenario, the example discussed in Step 1 all through to Step 3 would involve implementing a PLC algorithm for turning ON a light bulb in a PLC controlled circuit, as shown in the diagram to the right. 

Note, when the CPU is performing all the functions described in the three steps (reading the input’s status, solving logic, and writing the execution results for the program logic to the outputs), it can be said that the PLC is implementing the algorithm developed by the user. Generally, PLCs implement algorithms by continually scanning their programs and repeating the scanning process many times per second. The length of a program scan cycle is called the PLC scan, defined as the time the processor takes to execute the three steps listed above. Presently, PLC manufacturers are providing robust and cost-effective PLCs that can scan user programs very rapidly. PLC scan rates much faster than 100 ms (millisecond or msec) are common. It is also worth noting that when a PLC is in the run mode, its processor (CPU) performs other additional functions. Like running memory routines to ensure the memory is not damaged, constantly checking the entire PLC system to avoid programming errors, and updating the internal timer and counter values.

Ladder Logic Scan

As discussed earlier, PLCs are often programmed using Ladder Diagrams (LD), which is a simplistic graphical PLC programming language that is well suited for industrial control applications. It is therefore important to know how the processor of a PLC executes a Ladder Logic, during Step 2 of the PLC scan cycle discussed above.

PLC Programs written in Ladder Diagrams are based on relay logic and can be thought of as a set of PLC inputs and outputs connections. To apply such a ladder logic program, the PLC first checks all the inputs from analog or digital devices such as the sensors connected to field input devices and compares them to the set output points. If the setpoints are satisfied, then the CPU will consider the input to be “True”, and if they are not satisfied then the input will be considered “False”. When an output setpoint is finally reached then the input will become “True”, and the CPU will activate the output. This logic of LD-based PLC algorithms allows PLCs to be used in automating functions (like turning a water pump ON or OFF) based on set parameters (such as low- and high-water levels in a tank).

Since the elements of a ladder logic program are written into rungs, the processor executes one rung at a time in a fixed sequence. It begins a ladder logic scan at the top rung, and it traces a path on the left side across the rungs with various inputs. At the end of the first rung, it interprets the top output first, then the branched output below it. On the second rung, it solves the logic of the branches, before moving along the rung. If an input relay is “True” then the traced left path will continue, and if it is “False” it will not. If there is a complete “True” path on the right side across the rung, then the processor will complete the ladder logic scan and set the output to “True” or “Energized”. If the processor cannot trace a left or right path, then the output will remain “False” or “De-energized”.

PLC algorithms developed by Ladder Diagrams can be simple or very complex. For instance, a ladder rung can be completed by an “OR” condition based on an alternative input condition.

Note, the ladder logic scan is performed by the processor during Step 2 of the PLC scan cycle, and this happens only when the PLC is programmed using Ladder Diagrams. Otherwise, a different program logic can be executed in Step 2 depending on the language used to write the PLC algorithm.


This article has comprehensively explained how a PLC algorithm is implemented. It will therefore assist you to understand how a PLC processor executes a user-defined program or algorithm. Normally, in every PLC, a processor implements a given algorithm by continually scanning its program in three-step cycles which involve reading the inputs, evaluating and executing the program logic, and writing the outputs.

Overall, for easier implementation, the PLC algorithm should be adaptable and flexible without requiring major changes on PLC controlled process setup, and with minimum engineering efforts during implementation in the real world (factory floor). Also, the developed PLC algorithm along with the software environment in which it is executed should provide an easy to operate, flexible, and user-friendly platform. For example, a structured PLC algorithm can be developed using the RSLogix5000™ software, a tool that supports the use of IEC 61131-3 standardized PLC programming languages. For more information or to discuss which equipment might be best for your application, please visit our website here, or contact us at sales@pdfsupply.com or 1-919-535-3180. 

This entry was posted on October 26th, 2021 and is filed under Education, PLC, Uncategorized. Both comments and pings are currently closed.

Comments are closed.

PDF Electric & Supply Inc. sells new, new surplus and refurbished products which are sourced through independent channels. All warranties and support, if applicable, are with PDF Electric & Supply Inc. and not the manufacturer. PDF Electric & Supply Inc. is not an authorized distributor or representative for the listed manufacturers and makes no representations as to any quality control performed by any listed manufacturer on the products. The products listed on this website may vary as to their country of origin; the accessories, and other items included with the product; and the language used on the packaging, the parts, and any related instructions or printed material related to the products. This website is not sanctioned or approved by any manufacturer or tradename listed. Designated trademarks, brand names and brands appearing herein are the property of their respective owners.