How To Write A PLC Program

How-To-Write-a-PLC-Program, How-To-Write-a-PLC-Logic, PLC-Programming 

20 March, 2021.

This post is divided into two parts. In the first post, we will understand how to write a PLC program using basic components. In the second post, we will write a program using timer and counter. If a programmer understands these basic concepts, he will then be able to write and understand complex programs further.

Every new programmer in industrial automation must understand the basic principle of writing a PLC program. Without it, he cannot be able to further troubleshoot or understand complex automation systems. As the logic is the heart of the system and the machine operates according to it, properly writing and understanding a program is an important aspect for a programmer. This post is intended to tell a new programmer how to write a PLC logic. As the post is divided in two parts, the first part will cover the basic components of a logic and try to write a program using it.

Types of PLC Programming Languages:

A PLC program consists of five types of programming languages – Ladder, Structured Text, Functional Block Diagram, Instruction List and Sequential Flow Chart. In this article, we will see the simplest one for understanding – ladder logic. The languages are different, but the basic fundamental is same – to control an output according to the input. Let me first clear your concept.

How To Write A Logic In PLC:

Someone has given you two push buttons and a lamp; and asked you to do it’s wiring in such a way that, on pressing start, the lamp will turn on and on pressing stop, the lamp will turn off. Now, as you do the wiring, you can do the same thing in a PLC logic. The motive is to control the output according to the inputs provided. A ladder logic has five basic components – Normally Open Contact (NO), Normally Close Contact (NC), Normal Coil, Set Coil and Reset Coil. NO and NC contacts are the input types; and the remaining three are output types.

Now, from the example, you find that the two push buttons of start and stop are the inputs and the lamp is an output. (It is important to note that the output can be used as an input too; which we will see later in the post.) See the below logic now and understand how it is written.

Ladder-Logic

When an input is pressed, the corresponding memory bit will turn on and when that input is released, the memory bit will turn off. So, when you write a logic, first remember that the power of the rung flows from left to right. In the above example, start button is used as NO contact and stop button is used as NC contact. The lamp is used as normal coil.

Let us understand it’s working now by referring the below image. When the input is off and NO contact is used for that input, the value of the contact will be zero in off condition and one in on condition. When the input is off and NC contact is used for that input, the value of the contact will be one in off condition and zero in on condition. Now, let us consider that both the inputs are not pressed. With the logic written, the lamp coil will not turn on as power will not flow from start contact. When start button is pressed, it’s NO contact will turn on and power will flow from it through the stop contact and finally to the lamp coil; to turn it on.   

Ladder-Logic_Example

Now, as you know that input is a push button, it will be momentary; when pressed, the input will be on and when released, the input will be off. Now, refer the below image. If you did not use the lamp contact in parallel with start contact; then, as long as the start button is pressed, the rung will be powered on. And, as soon as the start button is released, the power will again cut off. So, we use the lamp contact in parallel. As soon as the lamp turns on, the value of lamp contact becomes one and provides parallel power to the lamp coil. Now, even if you release the start button, the lamp coil will be powered on due to lamp contact.

Example-Of-Ladder-Logic

Now, if you press stop button, the value of stop contact becomes zero as NC contact is used; and it will off the power path to the lamp coil, as shown in below figure. Now, as long as stop button is pressed, even if you press the start button now; then the output will not turn on. This is because the stop contact is off in between. The rung will be again powered on if both the buttons are released as per initial condition.

Ladder-Logic-Examples

See the below image on how to use the next set of coils – set and reset. We will write the same case in a different way as shown. When start button is pressed and released, the lamp coil will remain on as a set coil is used for lamp variable. The same latching logic which we saw in first example is done by set coil; instead of the normal coil.

How-To-Use-Set-Coil-In-Ladder-Logic

When stop button is pressed and released, the lamp coil will turn off as a reset coil is used for lamp variable. The same unlatching logic which we saw in first example is done by reset coil; instead of the normal coil.

How-To-Use-Reset-Coil-in-Ladder-Logic

This is the way a logic is understood and written. You have to understand what is to be worked upon first. Then, you have to decide which types of contact and coil to use, so that the decided program works. Once you are familiar with the power flow, you will automatically write the logic in a fluent and clean way.

I have covered the general programming example of PLC. I have also not attempted to cover every theory of these design deeply; you can learn it easily once you get familiar with them. I have just given you an insight of these types of controls. In the next post, we will go a step further and cover timers and counters; and generate a little complex algorithm. Once you are done with these, I am hopeful you will be easily able to understand any logic properly. Learn the basics and explore a new type of study in this type of automation. It will take some practice and as you go on developing logic, you will become more familiar with it.

Thank you guys; I hope you enjoyed reading the practices normally used for this type of study in industrial automation.

Comments

  1. Very informative and explained in a very simplified way. It's really very helpful. Will be looking forward for more such articles.

    ReplyDelete

Post a Comment

If you have any queries, please let me know