PLCs, as an indispensable component of industrial automation, play a crucial role in the production process. In particular, Ladder Logic language, as a vital tool for PLC programming, provides precise and reliable support for the control of industrial systems. This article elaborates on the basic principles and functions of PLC programming, and delves into the definition, characteristics, basic syntax, and applications of the Ladder Logic language in practical industrial systems. Furthermore, it discusses the concepts and functions of PLC special block functions and user-defined function blocks.
In today's automation industry, programmable logic controllers (PLCs) play a crucial role. Ladder logic, which can be considered a rule-based rather than process-based language, is widely used in PLC programming, especially for processes requiring sequential control or complex automation systems.
This article discusses the basics of PLC Ladder Logic language, hoping to help you better understand PLC logic.
What is a PLC?
A PLC (Programmable Logic Controller) is a digital electronic system designed specifically for industrial environments. It uses programmable memory to store instructions for performing various operations (such as logic operations, sequential control, timing, counting, and arithmetic operations), and controls various mechanical equipment or production processes through digital or analog inputs and outputs.
Figure 1: This Crouzet EM4 PLC with integrated display is running the classic "Hello World!" program.
The basic function of a PLC is to convert input signals into device outputs through logic. This is similar to displaying the output on a screen after characters are entered on a keyboard. In industrial environments, PLCs are used to control various devices and processes, such as enabling robots to perform complex actions based on sensor signals.
What is Ladder Logic language? Let's first understand the types of PLC programming languages, as defined in IEC 61131-3. These include:
Ladder logic (LL)
Function Block Diagram (FBD)
Sequential Flow Chart (SFC)
Structured Text (ST)
Instruction List (IL)
Ladder logic is widely used, as it can quickly clarify the logic rules of a PLC. The layout of Ladder logic resembles a ladder.
Example: The ladder diagram shown below is a Modicon PLC program used for single-button control.
Figure 2: Ladder logic program implemented on Schneider Modicon PLC
When creating a new ladder diagram, you will first see two vertical lines (orange lines in the diagram). We write the ladder diagram program between these two vertical lines.
What is Rung?
As shown in the ladder diagram in Figure 2, each horizontal line is called a Rung. Ladder logic symbols are placed on these horizontal lines. Each Rung represents a rule, and we can read these logics and rules from left to right and from top to bottom.
Ladder logic language basic syntax
Before programming your PLC, please review the following basic programming symbols. These symbols also come with addresses or values that can be used to specify inputs, outputs, timers, counters, and other specific instructions.
Ladder logic symbol
Rung input
Rung output
To better understand, you can imagine "Rung Input" as a button/switch, and "Rung Output" as a light bulb/load. The inside slashes indicate normally open/normally closed states.
Logical AND
The above achieves the function: motor opening door = "switch 1 trigger" and "switch 2 trigger", that is, when switch 1 and switch 2 are triggered at the same time, the motor opens the door.
Imagine two security guards, each holding a key to a bank vault. Only when both of them turn the keys simultaneously will the vault door's motor activate and open.
Logical AND with NOT
The above achieves the function: motor-driven door opening = "switch-triggered" and non-"obstacle-triggered", that is, when the switch is triggered, but the obstacle is not triggered, the motor opens the door.
Imagine two security guards: one with the key to the bank vault, and the other patrolling for intruders. Only when the key is turned and no intruders are present will the vault door's motor activate and open. Of course, an obstacle could also be a stop button that hasn't been pressed.
Logical OR
The above achieves the function: motor opening door = "switch 1 triggered" or "switch 2 triggered", that is, the motor opens the door when either switch 1 or switch 2 is triggered.
Imagine two security guards, each with a key to the bank vault. Either guard turns the key, the vault door's motor activates, and the door opens.
Combinational Logic
The above achieves the function: motor opening door = ("switch 1 triggered" or "switch 2 triggered") and non-"obstacle triggered", that is, when either switch 1 or switch 2 is triggered, and the obstacle is not triggered, the motor opens the door.
Imagine three security guards: two with keys to the bank vault, and one patrolling for intruders. When any of them turns the key and no one is suspicious, the vault door's motor activates, opening the door.
A practical application example: air conditioning systems
Figure 3: Air conditioning system
We can see two rules:
Rung1: Functionality: Air conditioner turns on = "Switch triggered" and ("Temperature sensor triggered" or "Humidity sensor triggered"), that is, the air conditioner turns on when the switch is triggered and either the temperature or humidity sensor is triggered.
Rung2: Functionality: Cooling on = "Air Conditioner Triggered" and not "Heating Triggered", meaning that when the air conditioner is on and the heating button is not pressed, cooling is executed.
Note: In the second rule, the air conditioner changes from an actuator in Rule 1 to a checker in Rule 2. The "cooling" in Rule 2 can also become a checker if a new rule is written, feeding data to another output device such as the "compressor." This system allows for the decomposition and evaluation of very complex logic designs.
PLCs have many types of special blocks. These include functions such as timers, arithmetic operators and comparators, table lookup, text processing, PID control, and filtering.
More powerful PLCs can operate on a set of internal memory locations and execute operations within a certain address range, such as simulating a physical sequence drum controller or a finite state machine. In some cases, users can define their own special blocks, which are essentially subroutines or macros. A rich library of special blocks and high-speed execution enable PLCs to implement very complex automation systems.
User-defined function blocks (UDFB)
User-defined function blocks (UDFBs) are to programmable logic controllers (PLCs) what functions are to microcontrollers. Both are used to simplify code structure, making it easier to write, troubleshoot, and maintain. They are also the basic structures that allow code to be reused in the future.
UDFB example:
The simple UDFB we used in Arduino Opta. This UDFB was developed using Arduino PLC Integrated Development Environment (IDE) version 1.0.3.0.
Figure 4: UDFB instance
As shown in the diagram above, we will construct the UDFB highlighted in Figure 1. This block is used as part of the state machine. Its role is to act as a gatekeeper. If the machine's uiState state variable is equal to 1 and the block is enabled, the rest of the line is executed. From a C programming perspective, this is like a switch statement indexed by uiState. Note that the prefix ui is the Hungarian unsigned integer notation.
This special construction results in a relatively clean ladder logic. The English description of Rung 3 is as follows:
If UDFBFBuiEqual is enabled and machine state (uiState) continues
Additionally, if the main switch is on.
Similarly, if the momentary selector switch is in the forward position, then switch to state 2.
Otherwise, if the selector switch is momentarily in the reverse position, then switch to state 4.
Summarize
As an indispensable component of industrial automation, PLCs are increasingly widely used in modern industry. Ladder logic has evolved into a programming language, and understanding ladder logic can help you comprehend the logic of PLCs more quickly.
Editor's Note
As introduced in this article, Ladder Logic language holds an important position in PLC programming due to its intuitive, easy-to-understand, and flexible characteristics. Through its graphical representation, it simplifies complex control logic, enabling engineers to understand and write PLC programs more quickly. Therefore, Ladder Logic language has become the preferred programming language for many engineers. What experience or questions do you have regarding the characteristics and applications of PLC programming languages?