Monday, April 10, 2023

PLC Program

Introduction 

As discussed earlier, a control program is essential for the proper functioning of a PLC. Different logical instructions and sequential operations are written in a way that is meaningful for PLC operation. Typically, a PLC program is written by users on a separate computer and transferred to the PLC memory for storage. PLC programs can be composed in different languages, with the most common ones being Ladder Logic or LAD, Statement List or STL, and Function Block Diagram or FBD. Among these languages, Ladder Logic is the most popular and widely used by PLC manufacturers. The following example illustrates a simple electrical circuit and its equivalent PLC programming using LAD, FBD, and STL languages.


Ladder Logic or LAD

Ladder Logic or LAD is the most popular programming language used for programmable logic controllers (PLCs). The Ladder program is similar to an electrical wiring diagram. Here's a simple example of LAD diagram programming:

The left-side diagram presents an electric circuit with switches S1, S2, and S3, which are normally open (NO), and Lamp L1, which will glow when either both S1 and S2 switches are activated or only S3 is activated. If the corresponding circuit is written in Ladder logic, it would look like the picture shown on the right side. In this ladder logic diagram, I0.1, I0.2, and I0.3 are normally open (NO) inputs, and Q0.0 represents the output, which can light a lamp or run a motor. According to the program, if I0.1 and I0.2 are activated (Logic 1), Q0.0 will be activated (Logic 1), and the output status will also become Logic 1. Similarly, if only I0.3 is activated, the output status of Q0.0 will become Logic 1.

In a Ladder diagram, the left-side vertical line represents an energized conductor, the right-side vertical line represents an output element or return path, and the ladder logic diagram is always read from left to right and top to bottom. A complete Ladder diagram is divided into separate branches called Rungs or Networks, and each rung consists of several input instructions. Each rung has only one logical output, and multiple rungs make up a complete PLC program.

Statement list or STL

Statement List or STL is another popular PLC programming language. In an STL program, the operations to be performed are written on the left side, while the operands or items to be operated on are usually addressed on the right side. The following example illustrates the previous electrical circuit in Statement List or STL format: 

In this example, the operation 'A' represents the 'AND' logic, and 'O' represents the 'OR' logic operation. Inputs I0.2, I0.3, and output Q0.0 are considered operands. According to the program, if I0.1 and I0.2 are in the AND logic, the output status of Q0.0 will be Logic 1 when both inputs are activated. If only input I0.3 is activated (as it is in OR logic), the output status of Q0.0 will also become Logic 1. Various types of operations and operands are used in a PLC program written in Statement List or STL, and a series of instructions make up a complete PLC program. The use of STL language is limited to PLC programming.

Function Block Diagram or FBD

Some PLC programmers also use the Function Block Diagram or FBD programming language. In this language, operations or functions are represented inside separate blocks, while operands are written outside those blocks. Separate blocks are used for different operations. If the previous electrical circuit were expressed in a function block diagram, it would look like the following:

In this example, the inputs I0.1 and I0.2 are placed in the AND operation block. The result is then added to input I0.3 in an OR operation block, and the output Q0.0 represents the result of the OR operation. A complete PLC program is written using several such block functions. However, the application of Function Block Diagram or FBD programming with PLCs is also limited.

How PLC programmed

A "Communication Port" on the CPU allows it to connect with an external programming device. There are two types of programming devices: a small hand-held unit for direct programming of the PLC and an all-purpose computer with specific software for PLC programming. The programming software is specific to the PLC manufacturer. For example, SIEMENS uses software like STEP 7-Micro and WIN32, which can only be used for SIEMENS PLCs and not for other companies like MITSUBISHI, OMRON, or FANUC. Similarly, a hand-held programming unit designed for one brand of PLC cannot be used to program a PLC from another brand. Using a computer is generally more suitable for PLC programming compared to a hand-held unit.

The most commonly used languages for PLC programming are Ladder Diagram or LAD, Statement List or STL, and Function Block Diagram or FBD. Most companies primarily employ Ladder Diagram programming for PLC programming. A PLC program is composed in a step-by-step format with different blocks using PLC programming software. A lengthy PLC program consists of several blocks, making it easier to understand and identify errors. After composing the program, it is checked for errors within the software. Once the entire program is reviewed and confirmed to be correct, it is transferred to the PLC unit from the computer using a cable. The PLC is then set to RUN mode, and its functions are tested accordingly. If there are any errors in the program while running the PLC, they can be rectified using an external computer. The corrected program is then transferred to the PLC, overwriting the old program. Small or medium-sized PLCs usually do not have a display unit, so the program cannot be observed directly. However, with advanced PLCs embedded with a CNC controller or connected to a robotic arm where a separate display unit is available, the PLC program can be edited through a keyboard.

 

Functions of Sensors and Actuators with the PLC program

Input elements or sensors are connected to the PLC through an Input Module, while output devices or actuators are interfaced through an output module. The output status changes based on the statements of the PLC program and logical instructions in the CPU, as well as the status of the sensors or input devices. This means that input and output devices have a close and intimate relationship with the PLC program. The following two diagrams illustrate the connection of sensors and actuators with a PLC, along with a simple PLC program to light a lamp. 

Different elements and their symbols used in PLC programming

PLC manufacturing companies use various components (internal and external) and a variety of symbols for writing PLC programs. Although the functional elements remain the same in almost all types of PLCs, the symbols used may vary. Here are some common and widely used elements and symbols in PLC programming:

Input - Status information (Active / Deactive) collected from sensors connected to the PLC is referred to as an input. It is commonly used in logical circuits to activate multiple outputs, timers, and counters. In a PLC program, inputs are represented or addressed as 'I' or 'X' followed by a numerical number (e.g., I1.5 or X4.7). SIEMENS PLCs use the letter 'I' to address inputs, while FANUC PLCs use 'X'.


Output - The signal information conveyed from the PLC to activate different actuators or output elements is referred to as an output. Sometimes, timers or counters are controlled using logical operations to trigger these outputs. Outputs in a PLC program are addressed with 'Q' or 'Y' followed by a numerical number (e.g., Q1.5 or Y4.7). SIEMENS PLCs use the letter 'Q' and 'Y' to address outputs, while FANUC PLCs use similar symbols.

Internal Relay - An internal relay in a PLC acts as a virtual relay and behaves like a physical relay in conjunction with other PLC elements such as inputs and outputs. There can be different types of internal relays present in a PLC, but they have no physical existence. Internal relays are stored in the memory of the PLC and are given different names by manufacturers. SIEMENS refers to them as "Flag," MITSUBISHI calls them "Auxiliary Relay," and TOSHIBA identifies them as "Internal Relay." Internal relays can be either retentive or non-retentive. Retentive internal relays retain their last logical state (Logic 0 or Logic 1) even after the PLC is powered off. Non-retentive internal relays switch to a Logic 0 state immediately after the power supply is turned off. In SIEMENS PLCs, these internal relays are identified by the letter 'M'.

 

Set Coil - Similar to an output, a set coil is triggered by different logical operations involving inputs, outputs, and internal relays. When the logical functions collectively result in a Logic 1 status, the set coil remains in a Logic 1 state regardless of the state of other logical operations. The status of the set coil stays at Logic 1 even if the collective nature of the logical functions becomes Logic 0. Typically, an output, timer, counter, or internal relay is turned on using a set coil, and it is denoted by the symbol 'S'.


Reset Coil - Similar to the set coil, a reset coil is triggered by logical operations involving inputs or internal relays. When the logical functions collectively result in a Logic 1 status, the reset coil changes its state from Logic 1 to Logic 0. If the reset coil already has a Logic 0 state, it does not change its state even if the result of the logical function becomes Logic 1. In a PLC, the reset coil is used to reset timers, counters, or any internal relays, and it is denoted by the symbol 'R'.

 

Timer - Timers are used in PLCs to measure time intervals. They have no physical presence but can be easily implemented through programming. Different types of timers are employed in PLCs, such as ON Delay and OFF Delay timers. They are represented by the letter 'T' followed by a numeric number (e.g., T5 or T10). Typically, an input, internal relay, or output is used to activate or deactivate a timer. Various timers and their operations are explained in detail in a separate chapter.

Counter - Counters are used in PLCs to count objects and usually have two signals: a UP count and a DOWN count. Similar to timers, counters do not physically exist inside the PLC but are built-in and operated based on the program requirements. Different PLC manufacturers represent counters differently in their programming styles, even within the same company's different models of PLCs. Counters are represented by the letter 'C' followed by a numeric number (e.g., C5 or C10) within a PLC program. Various types of counters and their operations are covered in a separate chapter.

No comments:

Post a Comment

Popular Posts