Monday, April 10, 2023

Fundamentals of Ladder Programming

The ladder diagram is a graphical programming language that uses symbolic notation to express logical operations with Programmable Logic Controllers (PLCs). It consists of a series of rails and rungs containing different logic symbols that form decision-making expressions. There may be slight differences in the representation and usage of logical symbols among different PLC manufacturers. In this document, all symbols and logical expressions are aligned with SIEMENS PLCs, although other companies such as ALLEN-BRADLEY, MITSUBISHI, FANUC, DELTA, and OMRON have similar ladder programming methods. A ladder diagram comprises seven elemental components: Rail, Rung, Input, Output, Logic Expressions, Address notation, and Comments. The following picture illustrates the different elements in a ladder diagram.

 

How to write a Ladder logic program


To write a ladder logic program, you need to understand various symbols and logical expressions such as AND, OR, and NOT, which are used in the ladder diagram. The logical representation in ladder diagrams often involves Normally Open (NO) or Normally Closed (NC) contacts and series/parallel connections. In a ladder diagram, there are two rails, one on the left-hand side and another on the right-hand side, with Contacts, Coils, Logic expressions, and Internal variables arranged in between. Each component is interconnected and linked to the rails, forming a line of code called a Rung. Multiple rungs are written one after another, creating a ladder diagram. The following picture shows the standard format of a ladder diagram. 


The two principal symbol functions in ladder programming are Contacts and Coils. Contacts represent input elements, while Coils represent outputs in a ladder diagram. Additionally, there are "Box symbols" used in ladder programming to define different types of timers and counters.

 

Elements of a LADDER Programming

The following picture represents the individual elements used in PLC ladder diagrams. 

 

Contact - A contact serves as an input, similar to a switch, that can be activated or deactivated externally. Other elements such as outputs and internal relays can also function as contacts with logical operations. Contacts are typically categorized as Normally Open (NO) or Normally Closed (NC). The image below depicts both types of contacts.


With a Normally Open (NO) contact, the status is Logic 0 when there is no power flow through it. Upon activation, the status changes to Logic 1, allowing power to flow. Conversely, with a Normally Closed (NC) contact, the status is Logic 1 when there is power flow through it. When deactivated, the status changes to Logic 0, interrupting the power flow. Each contact is identified by an address written above the symbol. 

Coil - A Coil can be considered as a virtual relay that activates based on logical operations involving Contacts. Coils are commonly used to energize solenoids, relays, and motor starters. When the output status of a Coil is Logic 1, it triggers or energizes the connected element. Conversely, when the Coil status is Logic 0, it deactivates the element. Output Coils can also function as Normally Open (NO) or Normally Closed (NC) Contacts in a PLC program. A Coil is identified by an address written above its symbol. The following picture shows the symbol of a Coil used in a ladder diagram. 

Box - In ladder programming, a box symbol represents various logical functions such as timers, counters, comparisons, and math instructions. Several box symbols are used to represent complex functions, including timers and counters. The following diagrams show the symbolic representation of a typical Timer and Counter, which are frequently used in PLC ladder diagrams. 

Advanced PLC instructions are sometimes used to handle Non-Boolean integers and perform control functions. Data comparison instructions are employed to compare two Non-Boolean values and generate a Boolean output. Mathematical instructions and logical symbols are also used in advanced ladder logic programs to perform various mathematical operations. The following pictures illustrate some common comparisons and mathematical instructions used in advanced PLC programming. 


Using Contact and Coil with Ladder programming 

In the electrical circuit shown below, a push switch is connected to turn on the light. In the equivalent ladder diagram, the switch is replaced by a contact, and the coil represents the light. Since the switch is currently in the deactivated state, the light is not glowing.

 


When the push switch is pressed, the light will turn on. Similarly, when the contact is activated and its status becomes Logic 1, the coil will energize, resulting in the output status also becoming Logic 1. The following picture illustrates the activated state of the switch. In the respective ladder diagram, the contact and coil symbols will be enclosed in a grey box, indicating Logic 1 status for both the contact and coil.



Application of different symbols


Ladder programming logically applies multiple Inputs or Contacts to trigger an output Coil. In the example shown below, Contact-1 and Contact-2 are used to activate Coil-1. The status of Coil-1 depends on the states of Contact-1 and Contact-2. When Contact-1 and Contact-2 are both Logic 1, Coil-1 will also have a Logic 1 status.

 

A complete ladder diagram can have multiple Coils or outputs and various sets of instructions to activate them, along with several logical functions for different Coils. Each Coil and its associated logical functions form a ladder rung, and a complete ladder diagram consists of multiple ladder rungs. The following picture shows a ladder rung and different symbols used with their addresses. 


Addressing of symbols 


Addresses are usually indicated on top of symbols to identify them in a ladder diagram. For example, if the address written on a symbol is I1.2, it means that the following Contact is assigned the input address I1.2. Supplying a 24V DC voltage to input module terminal I1.2 will make the Contact status Logic 1, and the Contact symbol will appear in a light-colored box. Similarly, if the Coil symbol is addressed as Q2.3 and its status is Logic 1, a 24V DC voltage will be available at the output module terminal, and the Coil symbol will also appear in a light-colored box. The following picture illustrates the representation of different address symbols in a ladder diagram. 


Latching circuit with Ladder diagram

In some cases, it is necessary to maintain output in a PLC program based on certain circuit conditions. This can be achieved using a Latching circuit in a ladder diagram. For example, when a push switch serves as the starter for an electric motor, the output should remain on to keep the motor running until another push switch is used to stop it. A Latching circuit is employed in the PLC to fulfill this requirement. It requires at least one input to set the latch and another input to reset it, while the output holds the latched state. The following diagram illustrates a Latching circuit in a ladder diagram.

 

 

In addition to the previous ladder diagram, let's assume that the Coil output is used to energize a motor, and "Input-A" and "Input-B" are two push-button switches used to start and stop the motor, respectively. Input-A is a Normally Open (NO) switch, and Input-B is a Normally Closed (NC) switch. When Input-A is activated or its status becomes Logic 1, the output status of the Coil will also become Logic 1. As Input-B is an NC contact, its state will remain Logic 1 as long as it is deactivated. By applying an AND logic operation to Input-A and Input-B, the output status becomes Logic 1 when Input-A is pressed. The Output is also used as a Contact signal, in parallel with Input-A and applying an OR logic operation. When Input-A is released or turned off, its status becomes Logic 0, but the output status of the Coil remains Logic 1. The Output, combined with Input-A using OR logic, acts as a replacement for Input-A. As a result, the output status remains Logic 1, keeping the motor continuously running. This circuit is known as a Latching Circuit in a ladder diagram. 

To unlatch or deactivate the output status of the Coil, pressing Input-B will make the output status of the Coil Logic 0. When Input-B is activated and its status becomes Logic 0 (since it is an NC contact), the Output Coil status will also become Logic 0, resulting in the unlatching or deactivation of the output. The motor connected to the output or Coil will stop immediately. To reactivate the output, Input-A can be pressed again. The following diagrams illustrate three different situations of a Latching circuit.

 

In some cases, SET and RESET instructions can be used to latch and unlatch a Coil output. However, the SET and RESET functions cannot be written in the same rung of a ladder diagram. In the example shown below, if Input I1.2 momentarily becomes Logic 1, the SET symbol changes its state to Logic 1 and remains that way even if the status of Input becomes Logic 0. The Output address Q2.3, defined with the Set symbol, also changes its state accordingly. When Input I1.3 changes its state to Logic 1, it acts as a reset and changes the status of the Output address Q2.3 to Logic 0. The following picture illustrates the Set and Reset functions in a ladder diagram. 


Multiple outputs with Ladder diagram

Usually, a single Coil is used as an output in each rung of a ladder diagram. However, there are cases where multiple Coils or multiple outputs can appear in a single rung. The following ladder diagram represents two Coils (Output A and Output B) being energized by a single Contact (Input A). 

Ladder logic programming rules

There are some fundamental rules that apply to ladder logic programming across different PLC manufacturers, regardless of the specific programming commands they use: 

1. The signal flow in a ladder diagram always proceeds from the left rail to the right rail.


2. More than one output or Coil can be programmed in a single rung.


3. The output Coil can be used as an input signal or a Contact.


  

4. The output Coil, Timer, or Counter should not be directly connected to the left rail. There must be at least one input Contact at the start of each rung.


5. No Contact can be used on the line after the output Coil is turned on.

 

 


6. The input Contact cannot be taken as an output.




No comments:

Post a Comment

Popular Posts