Skip to main content

Introduction to PLC Programming [Ladder Diagram]

 Ladder Diagram (LAD) is the best visual language for PLC programming. It looks very similar to a relay circuit diagram, so if you know something about relay control and electronic circuits, it will be very easy to learn!

In this tutorial, we will learn about the use of ladder diagrams for PLC programming. Now, let's get started!

What is a ladder diagram

Ladder diagram is a PLC programming language, also known as Ladder Logic. It is called a ladder diagram because this kind of program is composed of horizontal lines and looks like a ladder.

Ladder diagram was invented for electrical engineers. It is a graphical programming language, which means that the process of programming is not to use text, but to combine various graphical symbols. Since the target user is an electrical engineer, the symbol used Very similar to circuit symbols, so that electrical engineers can understand.

Ladder diagrams are mainly used for bit logic operations, and PLCOpen is responsible for formulating their specifications. Therefore, ladder diagrams are a standardized PLC programming language. The standard is IEC 61131-3.

How to read ladder diagram

One difference between ladder diagram and circuit diagram lies in the different compilation and drawing methods. Ladder diagrams are usually compiled from left to right and top to bottom. The reasons are:

1. Easier to read pictures

Our eyes naturally read the picture from left to right, and then continue to the next line, just like when you read.

2. Easy to program on the computer

When programming the ladder diagram on the computer, you can program one row at a time. As more and more rows are drawn, they will be superimposed on top of each other, looking like a ladder. The best way to view a ladder diagram with many lines is to scroll up and down the screen.

3. The order of execution

The last reason lies in the order of execution, that is, the order in which the PLC runs the ladder diagram. More precisely, it is how the instructions in the ladder diagram are executed in sequence: PLC always starts from the top of the ladder diagram and then executes sequentially downwards.

Ladder diagrams look very much like circuit diagrams. This is how most people learn to compile ladder logic diagrams. But there are still some differences, the main differences are:

PLC executes one line of the ladder diagram each time, and then continues to the next line

In the electrical system, many circuits are activated at the same time

Knowing these key differences, let us now start to learn ladder logic.

Ladder Diagram Basics

When creating a ladder diagram, the first thing you see is two vertical lines, that is, the ladder diagram is compiled between these two vertical lines. Each horizontal line is called a Rung (horizontal line):


Ladder logic symbols are placed on these horizontal lines. As you can see in the figure above, I have marked numbers on each horizontal line in order to understand how the PLC executes the ladder logic. You may have heard of PLC scan time or scan period. Simply put, the PLC scans its input first, then executes the program, and finally sets the output.

But how does the PLC execute our ladder logic?

One horizontal line at a time.

This is probably the most important rule of ladder logic: PLC can only execute one horizontal line at a time, and then the next one. In fact, the PLC can only execute one logic symbol at a time.

Programming ladder logic

Each symbol in ladder logic is an instruction, which at first seems rather confusing. But don't worry, I will explain it with a simple example. Let me give you a simple example in which two ladder logic symbols will be introduced.

So, what exactly are these symbols or instructions?

They are basic logic instructions that allow you to create a small piece of logic, which is your PLC program. If you look closely at the following example, you can see two instructions (symbols):

Closed circuit inspection instruction

The first instruction is called a closed loop check, and the symbol of the instruction looks like this:
This is a conditional instruction, which means that this instruction is used to check whether a certain condition is met, for example, to check whether a certain data bit is in the ON state.

The closed-circuit check instruction is used to check a specific bit of an address. In the above figure, it refers to a specific bit of a digital input. It can also be a memory bit or even an output bit.

The closed circuit check command is also called a normally open command, which is basically similar to a normally open contact in a circuit, so it can correspond to a jog switch.

What needs to be pointed out is that each closed-circuit check instruction must set an address in the PLC.

Both input and output are memory points in the PLC. In the above example, the closed-circuit judgment instruction sets the address I0.0 as the condition, and this address belongs to the first input of the PLC.

Its working principle is as follows:

When the PLC scan cycle starts, the PLC will first check the status of all inputs, and then write the input status (0 or 1) into the memory. If the input is LOW, the corresponding memory location is 0. If the input is HIGH, the corresponding The memory location is 1.

Output coil command

Each instruction itself also has a location in the PLC memory, and the PLC will store the result of the instruction. To understand what the PLC does with the results, let us look at the next instruction:

The output coil command is used to turn a data bit on or off.

As you can see, the symbol is located on the right side of the horizontal line, which means (on the same horizontal line) the previous instruction as the condition of the instruction. In our example, the previous instruction is the closed circuit check instruction.

Let us check the final result of the instruction to understand its working process:

a.PLC scan | input -> I0 byte
b.Program execution | I0.0 -> Xic result


In the above animation, you will see that the PLC first scans all inputs and stores the input status into memory. A memory byte is 8 bits next to each other.

Once the PLC has saved the state of all inputs, the program will start running. The first instruction to be executed is the closed-circuit check instruction. The result of this instruction is consistent with the state of the memory bit-this is why the instruction is called a normally open instruction-in the normal state (the memory bit is 0), the contact will be Keep normally open, the result will be 0, but if the memory bit is 1, the contact will be closed and the result will also become 1.

Finally, let's look at the output of this line:

XiC result -> output coil
Output coil -> output byte
Now, the output coil instruction uses the result of the previous instruction as a condition. This is called RLO (Result of Logical Operation). The result of logic operation is saved in a specific location in PLC memory. In Siemens S7 series PLC, this position is called status word.

In PLC terminology, a WORD is 16 bits, or 2 bytes.

The output coil command is very simple, it just sets its result to the same value as the condition.

All digital outputs in the PLC are also mapped to memory addresses. We call it the output bit, so the address Q0 corresponds to Q0.0-Q0.7. The result of the output coil command will be written into the memory bit Q0.0.

When the PLC executes the complete program, it will set the output. Each output is set to a state consistent with the output memory bit.

The concept of scan period is very important, so you must remember when programming ladder logic. Otherwise, your program may behave strangely. We will demonstrate this in the next example, introducing 3 new ladder logic instructions at the same time.

Output latch

In the previous example, we learned how to read the state of a digital input and set the digital output to the same state. It needs to be pointed out that the digital input is a transient button because it has a spring inside, which means that the button will only remain active when you keep pressing it.

The above ladder diagram works normally, but you may notice that the output will only be activated when the input is activated. So you have to keep pressing the button without your finger to keep the output active. But think about it, if the output controls a fan in a ventilation system, it would be unreasonable to require the operator to keep pressing the button. We need a way to keep the output active even if the operator has released the button.

In ladder logic, there are two ways to achieve this:


If you are familiar with the circuit, you will find that this is very similar. This cup is called latching or self holding.

The name reveals its working principle: the coil simply maintains its state in the previous scan cycle. Let's analyze it step by step:

When the PLC runs this ladder logic program for the first time (when the button is pressed), the output will be activated, just like the previous example. The interesting thing happens when the logic is run later. Because this is a transient button, it will not be activated all the time. Depending on the total running time of the PLC program, the button may no longer be activated during the second, third or fourth run.

Let's enter the first scan cycle after the button is released.

The output is still active because the previous scan cycle button was pressed. At this time, the PLC will read the input again and store it in the corresponding memory location. The memory bit I0.0" will be stored in "0" this time. Therefore, the closed-circuit judgment instruction result of I0.0 is false or "0".

But as you can see, there is another parallel closed-circuit judgment instruction, but the condition of this instruction is to output the memory bit, so its result is true or "1", because this is the output is still active. As long as the output memory bit is "1", the output will be activated, just like its own condition.

The reason why the self-holding instruction is connected in parallel with other instructions is to construct an OR condition. In this example, either I0.0 or Q0.0 will activate the output.

Open circuit check command

You just learned how to make a useful PLC ladder diagram program. A button to activate the output. In our example, this may be a contact connected to a fan, and the output can be self-holding.

But there is a problem with this program, how to turn off the fan?

We hope to be able to turn off the fan again. The easiest way is to add a stop button, which will be connected to the second input of the PLC, so its memory address is I0.1.

The question is, what command do we use for the stop button? More importantly, where should we put it in the ladder diagram?

The answer to the first question is another ladder logic instruction: open circuit check instruction, it looks as follows:
This instruction works in the opposite way to the closed-circuit check instruction, and the result is a conditional reversal. This means that if the condition is "0", then the result is "1" and vice versa.

If you think about it, you will find that this is exactly what we want the stop button to do. To turn off the output coil, we must give the condition "0".

Now is the second question, where to put this instruction?

We need to put it after the self-locking instruction, or in other words, connect it in series. Otherwise, when the stop button is pressed, "1" will still be output.

Now, the ladder logic is as follows:

You can see that the open circuit check instruction passes the result of the inversion of its condition to the output coil. To activate the output again, you need to press the start button again.

In the above example, I used an open judgment command as the stop button. This is not good practice!

We finally follow the best practice, and the modified ladder diagram is as follows:


Although we have modified the instructions, the operation of the ladder diagram has not changed. This is because we have also modified the working mode of the physical stop button.

Comments

Popular posts from this blog

What is a Torbar? – Averaging Pitot Tubes

 The Torbar is employed for flow measurement of liquids, gases, or steam in circular, square, or rectangular section ducts for large flow rates. The Torbar is an insertion type multi-port self-averaging primary sensor for flow measurement. Torbar TORBAR is a set of Pitot tubes mounted on a bar across the pipeline with no moving parts. An averaging Pitot tube is a technology, while TORBAR is a manufacturing brand name. There are several brands available in the market with VERABAR, ANNUBAR, etc. Averaging Pitot Tube Principle Purpose Averaging Pitot tube can be employed when the average velocity of the flow profile, rather than the velocity in a specific point in the cross-section is desired. Averaging Pitot Tubes Principle It measures the differential pressure between the static pressure tap and the tap of full pressure of a stream. Thus such magnitude of differential pressure is directly proportional to the square of the flow rate. Working The TORBAR is designed in such a way that ...

Ferrules and Cross Ferruling

 Ferrules are identification labels provided for every wire terminations in an instrument, equipment, or electrical/instrumentation control panels. These tube-shaped sleeves can be inserted easily on each individual wire in a multi-core cable. In earlier days fixed digits/letters are used as ferrules, but now Instrumentation engineers/technicians prints out desired ferrules by using a ferrule printing machine. Typical Ferrule The numbers/ letters on the ferrules will be given as per the approved electrical hook up or loop diagrams. This helps technicians to easily identify a particular loop/wiring from a series of terminal blocks and to troubleshoot the desired terminal connection. Separate numbers on the ferrules distinguish the positive and negative polarities of wires, thus ensure the polarity protection of the instrument. Cross Ferruling  As a wire is connected on its both ends, it is quite useful to use a cross reference method for wire identification. Unlike normal ferru...

Thermowell Insertion and Immersion Length

 The thermowell is the industrial housing for temperature elements like RTD or thermocouple or temperature gauges. Thermowell is directly exposed to process fluid/media. Inside the thermowell, element/gauge is installed. Thermowell transfers the heat to the temperature element. Depending upon the element type, the fluid temperature can be known. So Thermowell protects the temperature element against harsh conditions and process fluid. It enables removal of the temperature element for replacement, repair, or testing without affecting the process system. Generally, thermowells are provided with all-temperature Elements like RTD or Thermocouple or temperature gauge. A few exceptions would be bearing RTD, skin type thermocouple, air duct thermometer, etc where thermowell is not applicable / required. When the thermowell assembly is inserted into the pipe, it is subjected to vibration. This vibration is caused by vortices to be generated alternately on either side of the thermowell. The...