JMP & LBL Instructions in Ladder Logic Programming

Hi friends, I hope you are very well; today in this tutorial, we will practice conditional jumping for performing some code at the occurrence of some conditions. Like any other programming language, jumping is one of the most common approaches to transfer the execution from its sequential mode to run different processes or instructions marked by a label and bypassing the lines of codes in between the last executed transaction before the jump instruction and the labeled instruction whom the program is going to move to. The good thing about this technique is shortening the scan cycle of the program due to not running the whole program. However, using jumping techniques in coding is very dangerous. It would help if you were careful of missing some open cases before going anywhere in the code. For example, let us say that we started one process. In the middle of the process’s sequence, one jump instruction is used to run some logic under some conditions, so jumping means leaving or skyping for some reason and going running some logic or code. Therefore, we should consider the skipped instructions’ effects and consequences on the whole process and program logic. In addition, because any jump instruction can target any label and many jump instructions can target the same label, you should pay great attention to make sure you name the correct label according to the designed logic to avoid losing the reason you plan your program to do. I know you might take it easy now and can not imagine someone right wrong label by mistake. But, when you will be writing a large-scale project which contains hundreds or even thousands of rungs and has couples of dozens of labels, in that case, you can quickly mistakenly write the wrong label.

JMP and LBL instructions

To perform jumping in the ladder logic program, two instructions are together, as shown in Fig. 1. The first instruction is JMP which tells the PLC you need to jump from where the jump instruction is to where you find the LBL instruction.

Fig. 1: JMP and LBL instructions

Now how to know the label to whom you want the program execution to go or jump? Well, that is an excellent question, and the answer is that you should specify the label name as a parameter of jump instruction and the label instruction. Therefore, you can notice, my friends, if Fig. 2, the JMP and LBL instructions have a question mark denoting you should specify the label name, which is the next station to programme execution.

Fig. 2: Jump and Label instruction showing the label name above of them

Jump instruction ladder logic example

Now friends, let us see how jump and label instructions work together, as shown in fig. Three depicts a straightforward example of ladder logic in which JMP and LBL instruction work together, referring to the same label Q2:0. In this example, if input contact I1/0 is activated, JMP instruction will take the execution where the Q2:0 label “LBL” instruction is. As a result, the rung 001 has been bypassed.

Fig. 3: ladder logic example for jump and label instructions

How about going with a situation where we need to employ JMP and LBL instruction? Yes, in the example shown in fig. 4, You can notice here in this example. There are a couple of motors and for these motors. We need to. Use Siri. The command of the jump. And in combination with the uh label instruction. 2. Let some motors work in one scenario. And in another scenario, we will let some of these motors worworkd the others are not working. So you can imagine if you are working with Couples of pumps and want to run all pumps together in one scenario, so you do not activate the JMP command. But, in another scenario, if you’re running some of these pumps. So what we are going to do here in this example is to activate the JMP command to bypass some of these pumps, which are between the JMP and LBL commands.

Fig. 4: a real example of jump instruction

Figure 5 depicts the execution of the sample program that demonstrates JMP instruction. This case shows what happened in the first scenario example. If we do not activate jump instruction in rung 3, then all motors 1,2,3,4,5,6 and 7 will run based on the status of their firing contacts which are I:0 0 to 7, respectively. And the program execution continues running other motors after the JMP as it is not activated by touch I:0 3.

Fig. 5: test when JMP is not activated

On the other hand, Fig. 6 depicts the second scenario when activating JMP instruction by contact I0:3 at run number 3. By activating the jump command, We can notice only the motor before jump instructions are running based on their command contacts when the pumps in between jumps and label commands are bypassed, and the other engines after label instruction are running. So motors 1,2 and 3 are running, motors 4,5 and 6 have been ignored by activation of jump command instruction, while motor seven is running, which is at label command.

Fig. 6: test when JMP is activated

What’s next,

I want to thank you all for following me in this short and essential tutorial that can help you utilize the jump and label command instructions to control the logic flow of your program based on the situations and the logic design of your program. So now you can perform safety control to avoid running some equipment under some circumstances to protect the operator and equipment. In addition, you can run many logic scenarios in one program based on the status of input and output devices. In the following tutorial, we will take something neer to jump, which is subroutines, showing you how you can make your program modular and divided into subroutines to be organized and readable and easy to maintain, follow, and being modified. So be ready, and let us meet soon to learn and practice the new ladder logic programming tutorial.

Analog Input Scaling in Ladder Logic Programming

Hi friends and hope you are doing very well. Today we would like to take one tutorial which is very essential in the industry which is analog input processing for handling analog measurements of physical signals like temperature, humidity, pressure, distance, flow and level of liquids, etc. Typically, sensors produce two types of analog signals to represent the equivalent measured signal which is current and voltage signals. The currently produced signals would be within the range of 4-20 mAwhile voltage signals are in the range of 0-10 v. because, that output signals represent physical signals, the limits of output signals are 0 to 10 v for voltage based sensors and 4 to 20 mA for current-based sensors, these values should be scaled to represent the equivalent value as regards to physical signals. By completing this tutorial, we will have elaborated on the concept of handling analog signals and how we scale them to represent the physical signals. In addition, we will go through practical examples for handling analog inputs with ladder programming and then we will enjoy practicing these examples on the simulator to validate the written ladder code and show practically the analog processing in PLC.

In computer systems, plc, and microcontrollers all processing work that has been done inside is processed in digital which is 0 and 1 representation. So, one may ask how analog signals which change continuously within a specific range could be processed by computers, PLCs, or microcontrollers? Well, that is an exciting question and its answer will open the door to show the aim of this tutorial. Figure 1 shows an example of analog signals of the voltage that represents the temperature sensor reading.

Fig. 1: Output voltage of temperature sensor

As you see in fig. 1, the output of the temperature sensor would be either a voltage signal or a current signal based on the type of the sensor. And the output of sensors is applied to the analog input module that converts the analog signal to a digital signal to be processed digitally by the PLC.

Scaling analog inputs

The output signals of sensors either voltage or current signal should be scaled to represent the physical signal and at the same time, it has its equivalent digital values. For example, let the temperature that is being measured has a range between 0 to 100 °C, and the sensor that we use produces voltage output from 0 to 10 v. Therefore, each 0.1 v change in voltage is equivalent to a change of 1°C. Also, assuming the maximum digital value that can be received is 4000. So, 0 V is equivalent to 0 as a digital value and 10 voltage is equivalent to 4000 as a digital value. So, it is crucial to scale the output voltage to determine accurately the equivalent change in sensors’ reading in terms of voltage to represent the temperature in digital value and the real range of the physical signal.

Scaling with parameters

Again, we have two sides to be scaled from one to the other. Therefore, the parameters that are needed for achieving such scaling are as follows:

  • The input value: represents the physical signal that comes out from a sensor. And it typically could be from 0-10v for voltage-based sensors, or it could be 4-20mA for current sensors type.
  • The scaled value represents the digital equivalent of that value. And it depends on the word size or the number of bits that we use for representation in digital format. For example, for 16 bits size, the scaled value is up to which is +/- 32768.

So we can imagine together now the scaling function block in ladder logic should be as shown in fig. 2. It shows the input minimum and maximum which could be 0 and 10v or 4 and 20mA. In addition, there are scaled min and max which could be from 0 to 32768 for 16 bits size conversion.

Fig.2: the SCP block in Allen Bradley

Analog input processing in Ladder logic

We are going to show a complete example of analog input processing in Siemens and AB as well to present the merits of analog conversion in both brands. Figure 3 shows a primitive rung of the ladder logic program that processes the analog input reading. The ladder rung uses a scaling with parameters (SCP) block that includes an input minimum of 4mA and an input maximum of 20mA. And it uses a scaled range from 0 to 32767 because it utilizes 16-bits word for representing the digital data.

Fig. 3: Ladder logic rung for analog input processing

Figure 4 shows the run of the simple example which shows up the processing of analog inputs. It shows that, when the input measured value was 12mA, the output was 16884 which is pretty accurate. It is good to mention that, the output is limited to be within the range of the scaled min and max meaning that it should be from 0 to 32767.

Fig. 4: Testing analog processing by the simulator

Let us give another example but in siemens s7-1200 which is represented by Fig. 5. The ladder code is very simple and it consists of two runs as shown in fig. 5; the first one is for validating the reading to be within the range which is from 0 to 27648 and the second rung is the main one which performs the analog processing in two steps. Firstly it normalizes the input based on the aforementioned range and then it scales the output back to represent it in the output signal format. In this example, we measure a battery voltage that is typically located in the range of 0 to 12v. Therefore, the min and max parameters in the scale_X block should be 0 and 12 v respectively.

Fig. 5: Example of processing analog inputs in Siemens S7-1200

Figure 6 demonstrates the test of the analog processing showing the output reported 5.858941 when the reading was 13499 which is high accuracy.

Fig. 6: Simulation of processing analog inputs in Siemens S7-1200

What’s next

I am truly thrilled to have you shared with me such a very important tutorial about analog input processing and scaling with parameters because this is a very common operation you might see in every operation in the industry as there are hundreds of sensors that read analog physical signals and be processed by the controller for deciding the next stage of the operation. Next time we are going to talk about jumping and branching techniques in the ladder logic program. So please be ready to meet very soon and learn together and enjoy practicing plc ladder programming

Comparator Operators in Ladder Logic Programming

Hi friends. Today we are going to go through one of the most commonly used topics in writing ladder logic programming which is using comparator operations. This includes the logical and mathematical comparison between variables to decide where the logic goes.

There are many comparator operations like equal (==), not equal (<>), less than (<), greater than (>), less than or equal (<=), greater than or equal (>=). All these comparator operations might be used in different logic scenarios while writing a ladder logic program. In this tutorial, we are going to go over each operator showing the input operators and output as well. In addition, we will practice some examples with the simulator to familiarize how to use them flexibly while developing ladder logic programs.

Input and output parameters of Comparator operations

Because they are used for comparing two the value of input variables, there will be two operators which are being compared. these input variables could be of any data type i.e. integer, real, boolean, character, string et cetera. And the output will be a boolean data type which denotes true or false, or “0” or “1”. As shown in Fig. 1 a typical comparator operator has two operands and one output which is called the result of logic (RLO).

Fig. 1: Comparator operation bock diagram

Table 1 lists examples for one of the comparisons between two variables of different data types and their output. In table 1, a typical example of “==” comparator operation between two strings considering the case sensitivity. The first column shows the values of the first operand and the second column shows the values of the second operand while the result of a logical operation (RLO) is represented in the third column. Now let us go over the station of each comparator operation for elaborating their operators, result, and give an example with simulation.

Table 1: example of comparator operation’s operands and RLO

Equal operator (==)

The equal operator is used to check if two operands are equal or not. The input operands’ datatype could be any of the possible data types in the language you are using. For example, Table 2 shows the parameters of the Equal operator in siemens S7. As you can notice, the input operand’ datatype can be any of the listed data types in the third column. One thing we need to highlight here is that datatype could be an array or structure of elements of the basic datatypes. For example, it could be an array of integers. In this case, the comparison will be conducted between every single element in the array of both operands. And if any of these elements have been found not match their equivalent in the other operand, the RLO will be false. Furthermore, the comparison not only does it apply to variables but also could be conducted between memory areas as shown in the third column. It can be used to compare input, output, marker, counter, timer memory data.

Table 2: the parameters of the Equal comparator operator

Example of equal comparator operation

Figure 2 depicts an example of an Equal comparator operation. .it compares literal constant with the variable of type integer saved in marker memory MW4 which is the location of a memory word.

Fig. 2: Example of Equal comparator operator

Figure 3 shows the simulation result of an example of an equal comparator operator. In the case of operands are not equal as in the example shown by fig. 3. The first operand is equal to 5 while the second operand is “0”. So the RLO shows false or “0”.

Fig. 3: simulation result of equal comparator operation when its operands are not equal

Figure 4 shows the simulation of an equal comparator when its operands are equal. The RLO is true or “1”. So the output coil is TRUE.

Fig. 4: simulation result of an equal operator when operands are equal

Not equal comparator operator

This operator is used to compare two operands. When they are not equal it produces positive RLO with High logic and when they are equal it returns false or “0”. Figure 5 shows the test result on the simulator of the NOT operator when the operands are equal. It returns RLO with “0” or false.

Fig. 5: simulation result of Not equal operator when operands are equal

On the other hand, fig. 6 shows the result of the simulation of the NOT operator when its operands are not equal. It gave RLO with logic Tru or “1”.

Fig. 6: simulation result of an equal operator when operands are equal

Greater-than “>” comparator operation

The greater than comparator operator is used for checking if operand 1 is greater than operand 2 or not. Figure 7 shows the rung of a ladder logic program that utilizes greater than comparator operation in which two operands of the integer data type are compared using the greater-than operator. The first operand is at memory location MW4 and the second operand is at memory location MW2. And the RLO represents the retuned result of the greater than comparator operation.

Fig. 7” ladder logic rung example of usage of greater-than comparator operation

Figure 8 shows the results of greater than comparator operation when operand one B is not greater than operand A. on the left side of the figure, it shows the case when both operands are equal and the right side shows the case when operand one is less than operand 2. In both cases, greater than operator sees its condition is not fulfilled so it returns false or “0” at the RLO and hence the output is false.

Fig. 8: simulation results of a greater-than operator when operand 1 is not greater than operand 2

Less-than “<” comparator operation

The less than comparator operator is used for checking if operand 1 is less than operand 2. Figure 9 shows a rung of a ladder logic program that utilizes less than comparator operation “A<B” in which two operands of the real data type are compared using the less-than operator. The first operand is at memory location MD8 and the second operand is at memory location MD12. And the RLO represents the retuned result of the greater than comparator operation. Also, it shows that, when oper1 is not less than oper 2, the result of logic output RLO is false and output is not activated.

Fig. 9: ladder logic rung example of usage of less-than comparator operation

Figure 10 shows the results of less than comparator operation when operand “oper1” is less than operand “oper2” the returned RLO is high or “1” and the output is activated. Now, one may question the case if the two operands are equal? Well that is is a good question and the case of equality between the two operands is considered false for both less than and greater than comparator operations.

Fig. 10: simulation results of less than operator when operand “oper1” is less-than operand “oper2”

Please see fig. 11 which shows the less comparator operation returns false when the two operands are equal. The next section will show the case of greater than or equal comparator operators “>=” and the less-than or equal comparator operator “<=”. In those cases, the equality between the two operands is included and the returned RLO is True or “1”.

Fig. 11: the less-than operator returns false when the two operands are equal.

 

Greater-than or equal comparator operator “>=”

Figure 12 shows a run in a ladder logic program that uses greater-than or equal “>=” operator. As you can see, the output shows true when the two operands are equal.

Fig. 12: greater-than or equal “>=” when two operands are equal

Less-than or equal comparator operator “<=”

Figure 12 shows a run in a ladder logic program that uses less than or equal “<=” operator. As you can see, the output shows true when the two operands are equal.

Fig. 12: the less-than or equal “<=” when two operands are equal

In-range comparator operator

Do all comparator operations take two operands? The answer is almost yes. However, there are very few operators that take only one operand. For example, the in-range operator compares the input operand with upper and lower limits to check if it is located within a specific range or not. Figure 13 shows a ladder logic rung uses that comparator operator to check operand oper1 of type real to see if it is in the defined range which is between 0 to 10.0. because the value of the operand oper1 is 11.5 which is out of the defined range. The RLO shows false or zero. Therefore, the output is deactivated.

Fig. 13: in-range comparator operation for the real data type variable

Figure 14 shows the RLO is true when the operand’s value is located between the defined limits of the in-range block. Also, there is out range comparison operator that is the opposite of the in-range operator about the logic.

Fig.14: in-range comparator operation returns true when operand located in the range

 

Larger example

In this section, we want to show you how these comparator operators can be combined to achieve a logical expression in ladder logic programming. let us imagine a scenario that we have a garage with a full capacity of 100 parking spots and we utilize a counter to count up cars get in and count down the cars that get out of the garage. Figure 15 shows a very simple logic of the validation and comparison to decide if the garage has room for a further car or it is full and no further car is allowed at present. Assume that the output of the counter is an integer data type variable that is stored in memory location %MW20. Now you can see the logic is straightforward. In the first step, the counter output is validated to make sure that it plays in a valid range which is from 0 to 100 which denotes empty to full capacity of the garage. It applies the limit function to the counter in case it is out of range to reset it to be within the designed range. Then program checks in the second step the value if it is less than the full capacity of the garage which is designed to be one hundred cars, it states true indicated with green lamp output meaning there is still room for cars to get in the garage; otherwise, it checks if it is greater than or equal of the maximum limit meaning there is no room for further cars to enter, it shows false meaning garage is full at the current time by activating a red lamp.

Fig. 15: garage status ladder logic example

Figure 16 shows the case when the garage still has room for further cars and the green lamp is activated for incoming cars.

Fig. 16: when the garage has room for further cars

Figure 17 shows the case when the garage is full and has no room for further cars. So the red lamp is activated for telling users no further empty spots available at the moment.

Fig. 17: when the garage is full

What’s next

As usual, I want to express my delight in your following up our tutorial, and let me take this chance to announce one of the most important and exciting tutorials which are about processing the analog inputs and how to scale the analog inputs. Did I tell you my friends that will be the next chapter? So be ready for enjoying processing analog inputs with practicing real-life situations in the industry.

Mathematical Calculations in Ladder Logic

Hi friends, today we are going to explore mathematical computations in ladder logic. Like in any programing language you should find logic and mathematic computations, here in PLC programming you often need to process the input data that is collected from reading analog devices like temperature, level, flow et cetera. Then you need to run some calculations on this data to derive some other variables for deciding to run or stop some device or even to determine analog output to output to analog device i.e. valve or actuators. In the following sections, we are going to explore the mathematical functions and their input operators and outputs as well. Then we will show how to utilize such functions in ladder logic with simple examples and as usual enjoy practicing them thanks to the PLC simulator.

What are mathematical operations we have

You may find some minor changes in the set of mathematical functions from brand to brand of PLC controllers. However, you will find in most of them are common in every controller. For example, you will find the basic mathematical functions are available like addition, subtraction, multiplication, division, negation by applying two’s complement, modulus, increment and decrement, absolute, maximum, and minimum. In addition, trigonometric functions like sine, cosine, tangent are included. Let us go over these functions and explore their operators and output and how they can be utilized in PLC ladder logic programming.

Functions operators and outputs

For all these functions, they have input operators and one or more returned outputs. Most of them have two inputs like addition, subtraction, multiplication, and division. While some have only one input parameter like negating function, maximum, and minimum. And they all have only one input. Table 1 lists all these functions and their input operators and output.

Table 1: the functions’ input parameters and outputs

 

Operator and Output values data types

It is very important to be familiar with the type of data you are trying to process using these mathematical functions. So, simply you just need to know that the smallest size data type is a bool data type which is true or false or “1” or “0” and it uses only one single bit. Then character “char” or byte data type which is 8 bits while word data type is formed of 2 bytes or 16 bits and that is the word size in PLC. Also, there are doubleword data types that occupy 4 bytes or 32 bits. Moving to mathematical data types there are integer data types that can be stored in one word and the double integer “DINT” which can be stored in two words or 32 bit for holding numbers up to = 4294967296 for unsigned integers and half of that value for signed integers. Also, there is a real data type for holding numbers with floating-point. It needs 2 words or 32 bits and for a long real LREAL data type extends to 4 words or 64 bits.

How to use the mathematical function in ladder logic

In the TIA portal for siemens, there are two ways to add mathematical functions in a rung of ladder logic program. Figure 1 shows the first method which uses an empty box in the block interface and then you can select the function and its inputs and outputs parameters.

Fig. 1: Adding an empty box for including math functions

Figure 2 shows a list of functions from which you can choose the mathematical function you want to use.

Fig. 2: A list of math functions to select

Figure 3 shows another way to add a mathematical function by going to the basic instructions and then going over the math functions on the most right part of the window as shown and selecting the function you want to use.

Fig. 3: The second way to add a mathematical function

Figure 4 shows how to define the input and output parameters of the used mathematical function. For example, in figure two input parameters are defined as the function’s input operators which are literal number five and variable “x” which is predefined as an integer in the variable declaration section in the middle top section. Also, the Variable sum is defined as an integer. So the add function will add X to 5 and assign the result to variable Sum.

Fig. 4: Defining function parameters and outputs

 

Mathematical function ladder example

In this example, we are going to show how mathematical functions can be used in a ladder logic program and also show the simulation results. As in fig. 5, we design a simple calculator that uses the mathematical functions and each function can be triggered by a switch on a contact that is connected in series to the enable line of the function box.

 

Addition function math example

Figure 5 shows an additional example in ladder logic. It shows two operators A and B of integer data types. The variable A is located at address MW2 and variable B is located at address MW4 while the result is stored in variable RES which is located at address MW6. All of these variables are of type integer and size one word or 32 bits. The figure show simulation results on the PLC simulator and shows the RES variable holds summation of A and B.

Fig. 5: Addition function example

 

Subtraction math function example

Figure 6 shows a subtraction example in ladder logic. It shows two operators A and B of integer data types. The variable A is located at address MW2 and variable B is located at address MW4 while the result is stored in variable RES which is located at address MW6. All of these variables are of type integer and size one word or 32 bits. The figure shows simulation results before triggering the subtraction function on the PLC simulator. So, the RES variable holds zero before enabling the function.

Fig. 6: Subtraction function example not triggered

Figure 7 shows the simulation results after enabling the subtraction by switch or the “SUB” command contact. The Res variable now reflects the results of subtraction.

Fig. 7: Subtraction function example in ladder logic programming

Multiplication math example

Similarly, Fig. 8 shows an example for performing the multiplication process. First, the “MUL” is selected and two input operators of multiplications are given and output. The simulation result shows the RES variable holds the result of multiplication of the input operators.

Fig. 8: Multiplication function example in ladder logic programming

   

Division function example

Similarly, Fig. 9 shows an example for performing the Division process. The “DIV” is selected as an instruction to be executed and two input operators of division are provided and output. The simulation result shows the RES variable holds the result of the division of the input operators.

Fig. 9: Division function example after triggering

 

MOD function example

Similarly, Fig. 10 shows an example for performing the MOD function process. The MOD function determines the remainder of the division process, in this example we are dividing 25 by 10 which gives 2, and the remainder of 5. “MOD” function firstly is selected as an instruction to be executed and two input operators of MOD function are provided and output. The simulation result shows the RES variable holds the remainder of the division of the input operators.

Fig. 10: MOD function example in ladder logic programming

General calculation

Now, one may ask how I need to do the calculation in form of an equation that has many processes? This is a very smart question! Many programming tools support this, fortunately. For example, in Siemens, there is a function called “calculate” which can take two inputs and perform mathematical equations on these two variables and return the result in an output variable as shown in Fig. 11. It shows the function which is called “CALCULATE” and it has two inputs “IN1” and “IN2” and one output “OUT”. I triggered the help to show you an example that states OUT can be determined from the equation in inputs and also shows all functions that can be used including logic and mathematical functions. So we can use this function, in general, to act like any mathematical or logical function separately or by combining two or more functions in one equation.

Fig. 11: Using equations in ladder logic

 

Example of performing equation in Ladder logic

As you can see in the given example in fig. 12, the output variable can be determined based on multiplying the summation and subtraction of the input parameters as an equation. The result of the program is validated with a calculator.

Fig. 12: Using equations in ladder logic

Combining mathematical function

There is another way to perform combine many mathematical functions as shown in fig. 13. As you can notice, the output variable “out” can be determined by multiplying the summation of input variables “in1” and “in2” by “in1”.

Fig. 13: Combination mathematical function in ladder logic

Negate function

Negate function is one example of a single operator function in ladder logic programming. it reverses the sign of the input variable. For instance, fig. 14 shows an example of converting the sign of input variables “in1” to show the negative value reflected in the result in “res”.

Fig. 14: Single operator mathematical function in ladder logic programming

Absolute function

Figure 15 shows an example of getting the absolute of variable “RES” and saving it in variable “b”.

Fig. 15: Absolute function in ladder logic

Minimum and maximum in ladder logic

Getting minimum and maximum is one of the most frequently used in the mathematical operation. Figure 16 shows an example for getting a minimum of two input variables “in1” and “in2” while fig. 17 shows an instance of getting the maximum of two input variables as well.

Fig. 16: Getting a minimum of two input variables in ladder logic programming

Fig. 17: Getting a maximum of two input variables in ladder logic programming

 

Decrement and increment in ladder logic

One of the most commonly used functions is incrementing and decrementing one variable. For example, the counter variable all the time gets incremented and decremented through the logic of the program. Figure 18 shows an example for decrementing and incrementing an input variable. First, the initial value of the variable was 15, and then after incrementing it. The variable became 6 and then by applying decrementing operation it return to 5. It is very crucial to notice that, the user variable in increment and decrement operation works as input and output at the same time. Therefore, you can see in the increment and decrement blocks, it is defined as input-output “input”.

Fig. 18: Increment and decrement operation in ladder logic

Limiting variable in ladder logic

Now, let us use one of the very useful functions to secure a variable at specific limits. Figure 19 shows an example of limiting the value of one variable “in” to be sited between the specified minimum and maximum values. In that very example, the input variable has had a value of 5 and because it exceeds the set limit of maximum it is set to 4 which is the maximum allowed value to the variable thanks to the limit function.

Fig. 19: limiting variable in ladder logic programming

Trigonometric functions in ladder logic

Also, trigonometric functions like sine and cosine and other related functions can be executed in ladder logic. Figure 20 shows one example of how to use a sine function in ladder logic. The first rung in the example shows how to convert the degree into rad thanks to mathematical functions multiply and division. Ultimately, the sin function block is used to determine the sine of the given angle in rad.

Fig. 20: Triogonometrical function in ladder logic programming

 

What’s next

I am so happy that you be that patient to reach these points of tutorial and you know got familiar with most of the mathematical functions and how to use them flexibly through your program. The next round will go with the comparison operators and more deeply in mathematical logic flow using operators such as >,<,>=,<=, and ==. So please be ready for our next session of that ladder logic tutorial.

Interlock in Ladder Logic Programming

Hi friends and hope you are all very well. Today, we are going to deal with one of the most important and common problems that would be there in everyday tasks in industry and its solution. The problem is the safety of equipment and operators by preventing the machine from running under specific conditions for realizing the safety of equipment and human as well. Not only does it fulfill safety but also it is for performing the designed sequence of operation. If there is a problem, then it should be the solution for it. the solution is what so-called “Interlock”. So, what is interlock? And why do we need it? And how we can design a good interlock? Well! We may find such concerns exist in two aspects which are safety and operation sequence. In the first aspect, safety happens when we need to make the execution of one operation or process locked by some condition for realizing the safety of the operator or equipment. The second one is operation sequence for which we need to sort the operation into sequential and concurrent tasks according to the logic philosophy of the operation. That can be realized by preventing one task of execution until one other task is finished or letting one task wait until one or more conditions are fulfilled. I hope that makes the reason why we need interlock close comes to your mind. Now, how we can perform interlock? Well! It can be done in many approaches. However, we can say simply there is only and only one idea to do interlock. It is by putting the condition “contact” on which it will be decided if the process will go on or not, or based on it, one piece of equipment can go running or keep stopped. By completing this article, you will have known what is interlock, why we need it in industry daily life problems, its techniques, and for sure how to program interlock. Furthermore, types of interlock, real examples from industry, and how you can implement it using ladder logic programming in different ways will be ready for you to learn and practice in this tutorial.

What is interlock?

Interlock is how to prevent one process or equipment from running to satisfy safety requirements or fulfill the logic of the operation. A clear example of an interlock is to prevent cutting weapons from executing as long as the hands of the operator are away from the working area. In this case, there will be two push buttons on the left and right of the operator and out of the working space to make sure, when the operator requests the cutting machine to operate, his hands were pressing those two push buttons which are out of the working space. The previous example shows how to employ interlock for realizing safety purposes. Another instance that shows how Interlock can be used to satisfy the operation logic requirements is when we need to drive the motor in two directions. In that case, we commonly use two relays or contactors for forward and reverse directions. So, there should be an interlock of each contactor to each other meaning we cannot activate both at the same time because that will end up with a short circuit on the motor or the supply.

What are types of interlock?

There are two main types of interlock which are safety interlocks and machine or equipment interlocks. Safety interlocks for securing people from getting hurt while they operate the machine. And machine interlock concerns with securing the safety of machine parts and or realizing specific philosophy of logic. Figure 1 shows the different types and subcategories of interlock. The machine or equipment interlock can be classified into three types which are mechanical, electrical, and logical interlock types. And from their titles, the mechanical interlock can be physically satisfied by making mechanical connections between equipment to let or prevent them from running. An electrical interlock can be achieved by using electrical devices like relys’ coils, sensors, and switches. The first one which is relays’ coils is the most interesting electrical interlock technique as they can be utilized in creating a dependency between equipment so we can design flexibly dependence between two motors, for example, to not running simultaneously meaning one of two running scenarios. The last type is the logical interlock which is the most important here in this tutorial and I hope you get an astonishing start to master that type because that is the most frequently used in real life in the industry. Do you know why? Because it is done programmatically without the need for mechanical connections and setup or even electrical devices or hardwiring. Also, it is very flexible as you can change it when there is a need to change the logic at any time.

Fig.1: interlock types

Figure 2 shows the very example of a safety interlock to protect the operator from entering the zone of robot work to save him from the movable parts. Is that a mechanical or electrical interlock? Or maybe logical? What do you think? Well! Let’s move forward in the tutorial and come back to this question to see if you know the answer or not.

Fig. 2: the safety interlock

The non-safe interlock is designed for protecting equipment and lock specific processes from execution. The machinery interlock is classified into three main categories which are mechanical, electrical, and logic interlock. In mechanical interlock, a set of mechanical setups is designed to prevent equipment or operation from running at some operating conditions. Figure 3 shows a schematic of a mechanical interlock for a setup that makes the motor spin either forward or reverse direction and prevent enabling both at the same time. The dotted line represents the mechanical interlock between the two contactors for reverse and forward contactors for guaranteeing to enable only one of them at any given time.

Fig. 3 mechanical interlock example

Figure 4 shows the case of missing the mechanical interlock between the two contactors. It shows the possibility of activating bother of them at a given time. In that case, you can see the damaging effects on the motor and the short circuit possibility on the power lines.

Fig. 4: fault condition due to missing interlock

Another example of mechanical interlock is car steering interlock as shown in fig. 5. The steering wheel is interlocked mechanically and unlocked by inserting the key.

Fig. 5: car steering mechanical interlock

The mechanical interlock was commonly used in the past and my be exist nowadays but very rarely. On the other hand, the electrical interlock is the most commonly used in control systems currently. Similarly, the idea of electrical interlock can be achieved by preventing the flow of current between two devices at the same time. Typically two contactors or relays are used for achieving such electrical interlock. One of these contractors will be normally open and the other will be in a normally closed configuration as in Fig. 6. It is very clear that for energizing the lamp, CR2 will be energized when CR1 is de-energized.

Fig. 6: electrical interlock example 1

Another example of electrical interlock which is very common is the thermal overload shown in Fig 7. It shows two contactors are used in electrical interlock configuration. The main contractor is in a normally open configuration while the thermal overload contactor is in a normally closed configuration. When there the temperature is getting high to a specific value the thermal overload turns over from normally closed to normally open to disconnect the load.

Fig. 7: electrical interlock example 2

Now, let's move to the logical interlock which is our target in this tutorial. Logical interlock is applying the same concept of interlock programmatically. In this type, there is no mechanical or electrical physical connection for achieving interlock. Instead, programming is used to perform the interlock. This logical interlock saves the effort of commissioning including mechanical or electrical connections. In addition, it realizes reliability and flexibility.

Logical interlock in ladder logic programming

Figure 8 shows one example of logic interlock. You can notice the left part of the figure shows there are no mechanical or electrical hardwiring or connections between pumps 1 and 2. However, pump 2 is interlocked with pump 1 logically as shown in the most left part that shows the ladder logic code. To have pump 2 running, pump 1 should run first by the level switch. As shown on the right part of the figure below, when the level of the liquid reaches above the level switch, the switch is turned on and energized pump 1 which activates pump 2.

Fig. 8: logic interlock example 1

Figure 9 shows another logic interlock example in which a timer of type on delay is used to interlock equipment. As shown on the left the ladder logic code and on the right, an image shows the scenario of the logic with astonishing visualization. It shows that, when the operator presses the start pushbutton and keep pressing on it for the preset time value which is 3 second, the timer contact turns on and the coil of the contactor is energized. Now let us go to the lab and open our simulator to run those examples to validate their logic and verify their proper operations.

Fig. 9: logic interlock example 2

Logical interlock using ladder logic

Let’s get to experimental work, now open your simulator, the first example as shown in fig. 10, there are two pumps. And we need to run one pump at every given time. So, no one of them will work when the other does. The ladder logic code shown in Fig.1, uses the contact of each pump’s coil to lock the other pump. For instance, if the first pump is running, that will open the path to prevent energizing the second pump’s coil when it is requested to run. Similarly, the first pump’s coil is hindered from running while the second pump is running. It looks smart but let us test and see if the logic we designed matches the real-time environment or there is an issue to solve!

Fig. 10: The first example ladder logic program

Simulation example 1

Well! Now we have started our simulation. Figure 11 shows the initial case when no pumps are requested to run. So you can see each pump is all set to run once being requested.

Fig. 11: the initial case when no pumps were requested

Figure 12 shows the case when we requested the first pump to run. Because the stop button is not raised and the second pump is not running; The first pump goes running as shown in figure 12. So the question is that what is going to happen when requesting pump 2 to run?! Let’s see

Fig. 12: starting the first pump

Fig. 13 shows the case when we request pump 2 to run by hitting its start push button “start-pump2”. As expected, the second pump does not run for the interlock condition we designed for by putting a contact of the first pump’s coil as a condition to run the other pump. So let’s remove the hindering condition of interlock by stopping pump 1 and trying to run pump 2 and see.

Fig. 13: requesting one pump to run when the other is running

Figure 14 shows what happens when we remove the interlock condition. By hitting the stop push button of the first pump “stop-pump1”, the first pump has stopped. Consequently, the second pump went running once the interlock conditions has been removed. So now simulation verifies our design and proves our code of interlock is working great. Well done!

Fig. 14: remove the interlock condition by stopping the first pump

Interlock ladder logic example 2

As we aforementioned section earlier, the interlock could be done by sensors state or reading, running and stopping statuses of other equipment, or logical devices like timers or counters as well. Timers and counters can be used as an interlocking technique for creating a running condition based on some delay or specific counting. Figure 15 shows one example of a timer-based interlock in which the pump won’t run by hitting the start button until the operator holds the start push-button pressed for 3 seconds then the pump goes running.

Fig. 15: timer-based interlock ladder logic example

Figure 16 shows the simulation of the second example. My friends, please notice, despite the start pushbutton having been hit by the operator; the pump does not start because it waits for the timer to count 3 seconds, and then it can run.

Fig. 16: pump wait timer to start

Now after 3 seconds of holding start push-button pressed, fig. 17 shows the pump goes running because the interlock condition is no longer there. I am very happy you would get that!

Fig. 17: pump start running after 3 seconds

What’s next?

My friends, before talking about what we are going to practice next time; I just want to express my appreciation that you patiently follow up till this point and hope your experience moves forward and gets more and more every lesson. Next time we will navigate the mathematical functions and how to perform mathematical computations in your ladder logic programming. my friends I really can’t wait to see you very soon to practice mathematics in ladder logic programming.

How to use Counters in Ladder Logic Programming?

Hello friends! We hope you are very well! Today we are here for complementing our knowledge with one of the most important topics in PLC programming and practice its implementation in PLC ladder logic programming. Our topic today is about counters which help us to know the production size at any time, the repetition of specific tasks and events. Many real-life situation problems need counter like garage capacity should be tracked by using counters to report how many cars are inside and if there is room for incoming cars or it's full. Another critical problem is to count the repetitive tasks and events in manufacturing. Furthermore, counting products and pieces for taking an action like performing maintenance, stop operation, turn over to next production stage... et cetera.

Counter in conventional control

Counters are used in conventional or relay logic control. they mainly receive pulses and count these pulses and when it reaches a preset value the output coil of the counter is energized. They mostly include an LCD showing the counting as shown in figure 1.

Figure 1: Omron counter [1]

The main idea of most counters is counting input pulses by using logic circuits i.e. flip-flop and determining the output based on which an output relay is energized. There are two main types of the counter as regards structure: synchronous counters when all flip-flops and asynchronous counters when each flip-flop is connected to its separate clock. In addition, counters can be classified based on functionality into UP, DOWN, and UP-DOWN counters. If you are not familiar with logic circuit components like flip-flops so do not worry as it's not our concern here. We just want to let you know how physical counters in the traditional controller are complicated and take a lot of space as we need hundreds of flip-flops and other circuit components to have a counter which counts for a limited number. Figure 2 shows the logic circuit of the counter that can count from 0 to 9. It utilizes 4 flip-flops as shown. The type of this counter is an asynchronous counter as each flip-flop takes its clock from the output of the previous flip-flop. Furthermore, table 1 lists the truth table of the counter. It shows how the counter determines the count based on the output Q0, Q1, Q3, and Q4. For example, when all outputs are zeroes, that means the counter reads zero. When Q0 is high, Q1 is low, Q2 is low, and Q3 is high, that means the counter reads 9. But in PLC, it's the easier story, it’s software counters with flexible functionality and usability as well as we will see in the next section. So let's enjoy learning and practicing counters in ladder logic programming.

Figure 2: Asynchronous 0-9 counter

Table 1: the truth table of 0-9 counter

Pulse to be counted Q3 Q2 Q1 Q0
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
 

Counter in PLC

Simply, Counter in plc is an instruction to count up or down to preset value and energize an output at reaching that preset value. There are three types of counters in PLC which are:

Count up type

In this counter, each time a trigger input signal has been received at (CU), the counter counts up until reaching the preset value (PV) to energize output as shown in figure 3. The counter has three inputs: the trigger command, the reload command, and the preset value to set to what number the maximum counter is going to count up. Furthermore, it has two outputs: the counter output which is turned to true when the counter reaches the PV values, and the current value (CV) which tells the current value at any time to whom the counter reaches.

Figure 3: The counter Up instruction block [2]

Count down type

In this counter, each time a trigger input signal has been received at (CD), the counter counts down until it reaches zero at then the counter output is energized. As shown in figure 4, the counter has three inputs: the trigger command for counting down (CD), the reload command to reload to the PV value, and the preset value to set to what number the initial value from whom the counter starts the count down. Furthermore, it has two outputs: the counter output which is turned to true when the counter reaches the PV values, and the current value (CV) which tells the current value at any time to whom the counter reaches.

Figure 4: The counter down instruction block[2]

Up-Down counters

In this counter, the two functions of the count up and count down can be combined in one block. each rising edge of a trigger input signal has been received at (CD), the counter counts down. And each time it receives a command trigger signal at (CU), it counts up and so on till it reaches the PV values. At then the counter output is energized. As shown in figure 5, the counter has five inputs: the trigger command for counting down (CD), the trigger command for count up (CU), the reload command to reload to the PV value, the reset command to reset to zero, and the preset value to set to what number the initial value from whom the counter starts counting up or down. Furthermore, it has three outputs: the counter down output (QD) which is turned to true when the counter reaches zero, the counter up output (QU) which goes to true when the counter reaches the PV value, and the current value (CV) which tells the current value at any time to whom the counter reaches.

Figure 5: The counter Up-down instruction block[2]

Ladder program examples for counters

Now after we have introduced to counters in PLC as regard to their types, functionalities, inputs, and outputs, let’s get to have the fun of practicing our lab work for counters with our simulator.

Count up example

Figure 6 shows the ladder simple program example for a counter of type Up counter. In this example, the counter counts the input objects by a sensor that triggers the counter to increment. The ladder program is shown on the left side window while the simulator window appears on the right part. You can notice on the simulator window, we track all inputs and outputs as well. In the beginning, the current value (CV) is zero and the preset value is set to 10 meaning the counter will energize its output when it counts up to 10. Let’s press the input trigger and see what is going on. My friends, try to think before you go forward to see the simulator output as I am ganging will be the same as what you imagine!

Figure 6: Ladder example of a counter UP type

As you imagine exactly, figure 7 shows the counter is incrementing each time the input trigger signal is rising. Until it reach to or above 10 which is the PV value at then the counter output turns on as shown in figure 8.

Figure 7: The counter incrementing with triggering signal input

Figure 8: the counter output turns ON by reaching to or above the PV value

On the other hand, the reset signal can be used for resetting the counter to the zero to start over counting as shown in Figure 9.

Figure 9: the counter CV reset to zero by hitting the reset.

Count down example

This counter is used to count down from the PV value to zero. Figure 10 shows a very simple ladder program for the count down the program on the left part and its simulation appears on the right as well. The simulation windows show the PV value is set to 10 and the current value (CV) is initially starting from the PV value. Therefore, it starts with a value of 10. So let’s try to hit the input CD signal and see what the simulator shows.

 

Figure 10: Ladder example of count down counter

Figure 11 shows the counter is decrementing the CV by hitting the input CD. And continue decrementing until reaching zero. So what is going to happen then? Think!

Figure 11: the counter is decrementing by hitting the input CD

Exactly! And well though, as figure 12 shows, once the counter reaches zero, the output changes to true.

Figure 11: the counter output set to TRUE when reaching zero

Again, the reset button can be utilized to reset the counter to its initial state as shown in figure 12. You can notice that the CV reset to 10 which is the initial value and equal to the preset value (PV).

Figure 12: Reset button reinitiate the counter to the PV value

Count up-down example

Now we are going to combine all features in the UP and down counters in one counter which is called the UP-Down counter. Figure 13 shows a simple ladder example for that counter. The ladder code is shown on the left and the simulator window is on the right. The simulation window shows all inputs and outputs of the UP-DOWN counter.

Figure 13: A ladder example of UP-Down counter

Testing the up-down counter ladder program

We have two functions to test with this type of counter which is up counting and down counting. Figure 14 shows the initial state of the ladder program, it shows we start testing when the current value (CV) shows 2. So what do you expect when hitting the count up and the count down? Thinking and validate with the simulator results below.

Figure 14: initial state at the running of the up-down example

By hitting the count-up function, the counter acts like a UP counter and the current value is incremented as in figure 15.

Figure 15: count up function incremented the CV

On the other hand, by hitting the count down function, the counter acts as a down counter and the current value is decremented as in figure 16. And by pressing reset, the counter CV value will be reset to zero, while it reloaded to the PV value by pressing the load counter button. In addition, the output QU will be energized when the counter reaches or is higher than the PV value which is 10 in this example while the output QD will be true when the counter reaches zero. To sum up, this up-down counter can act as both types of counters UP and Down. I know someone is going to ask why we have such a counter when we already have one of each counter type? Well! That’s a really good question. And the answer is that, yes we can implement any problem relating to performing counting by using these two counters. However, some problems need to perform both functions UP and Down counting at the same time. For example, the Garage problem has cars getting in and out all the time and when cars get in we need to count up the cars and when cars get out we need to count down to report the number of cars in the garage at any time. So in such a problem, having one counter do the whole job is better than having two punters for reducing the conflictions and increasing the flexibility of calculations.

Figure 16: count down function decremented the CV

Next topic

I would like to thank you so much for following up with us up to this point of learning and practice. Despite briefly introducing the logic gates, we will elaborate in the next station on the logic gates and their functions and usage in ladder logic programming. So you be ready for more learning and practice the ladder logic and logic gates in deep detail.

How to Use Timers in Ladder Logic Programming?

Hello friends! I hope you are doing very well, today we have a very crucial topic which is “timers”. Yes! Exactly like what comes to your mind. For running equipment i.e. motor at a specific time and/or for some amount of time we need timers. Timers are used even before PLC in classic or relay logic conventional control. However, there is a big difference between capabilities and limitations between using physical timers in classic or old fashion relay logic and using software timers in PLC. By completing this article you will be able to know what are timers and their types and applications. In addition, we are going to show off how to use timers in ladder logic programming with examples.

What are timers used for in industrial applications?

Well! This is a very good question to start and its answer can be taken as a motive to learn timers comprehensively. Timers are used to turn on actuators i.e. motors for a specific amount of time or turn off them after a specific amount of time. They are used for scheduling tasks on and off based on the process sequences.

How do timers work?

There are many types of timers based on the functions. However, all timers are working in the same principle that they are preset to a specific amount of time. Then when their coils are energized, the timers’ contacts are changing over to the opposite of their initial states i.e. from ON to OFF or from OFF to ON based on the delay time and the timer type. Therefore, we can imagine the main components of timers are the coil and contacts as shown in figure 1 [1]. It shows a relay timer for Telemecanique type showing the setting for the time delays, coil, and the contacts.

Figure 1: physical relay timer

Advantages of Timers in PLC over relay timers

The relay timers are limited in time setting i.e. for 24 hours and a specific amount of physical NO and NC contacts. While timers in PLC are logical software components with the unlimited setting of time which makes them very flexible with logic requirements. In addition, using physical relay timers costs us more space and wiring. While we can use soft timers in ladder logic with no limitations. Types of timers as we are going to describe in detail later, are limited to basic functions in the relay timers while all types of timers can be implemented in PLC using ladder logic programming.

Timers types

All timers have a coil and contacts and the latter will be changed over their states by energizing their coil based on the preset time and the type of timer. In the following subsection the most common timer types are introduced:

ON-DELAY timer

This type of timer is used to postpone the start of running. Figure 2 depicts the timing diagram of the On-Delay timer. As shown in this timer delayed the output from the input by the preset delay time. The figure shows that, after the input gets started, the time counts up until the preset amount of time elapsed, then the output starts as long as the input is ON. However, in the second pulse of the input, we can notice the output was not started because there was no chance to reach the amount of delay time that is preset in designing the timer.

Figure 2: The timing diagram of the On delay timer [2]

OFF-DELAY timer

In this type of timer, we aim at delaying the shutdown of the output. Figure 3 depicts the timing diagram of the OFF delay timer in which, the output starts at the time input starts and the output lasts after a specific time delay after the input gets off. You can notice that, in the second pulse of the input, the output did not shut down after the second pulse of the input due to the incoming of another input pulse before the delay time reached the preset value.

Figure 3: The timing diagram of the Off delay timer [2]

Pulse timer

This timer type energizes the output in each rising edge of the input for a fixed amount of time. Figure 4 shows the timing diagram of a pulse-type timer. It shows the output comes active each time it finds a rising edge of the input and keeps active for a fixed amount of time which is preset for the timer.

Figure 4: Timing diagram of, the pulse timer [2]

 

Accumulative timer

In an on-delay timer, if the input does not stay on for the preset time delay period there would not be a chance for the output to be energized. So there should be another modified timer to accumulate the period each time the input is ON and activate the output when reaching the preset value. This timer is called an accumulative timer and its timing diagram is depicted in figure 5. In this example, assume the preset values of 12 s, the first input pulse shown in blue resumes for 4 seconds and it goes on for another 8 seconds. The time is accumulated from the first and the second pulse until reached the preset value which is 12 seconds. The output gets ON as long as the preset time has reached and the input is ON.

Figure 5: on-delay accumulative timer

Timers in PLC and ladder logic program

Timers of different types can be used in PLC with great flexibility. Now let’s learn and practice timers with our simulator. But before we get to start we just need to introduce ourselves to the timer blocks in the ladder logic program.

Generate ON delay timer instruction

Figure 6 shows the instruction for generating an ON Delay timer. As you can see the instruction has two inputs and two outputs. The first input “IN” is the input contact of type Boolean. This input contact triggers the timer and initiates it to start counting the time. The second operand is the “PT” by which we set the required time delay. Moving to the outputs, the first output is “Q” this is the main output of the timer and it turns to true when the timer reaches the preset time delay. The second output is the “ET” which reports the time elapsed so far since the timer started to count time. The “PT” and “ET” are of time data type format and can be in milliseconds, seconds, minutes, hours, days et cetera.

Figure 6: Generate ON delay instruction

ON-Delay timer example ladder program

Figure 7 shows a very simple example program that uses an ON Delay timer for delaying the running of a motor. The ladder code is shown on the right part of figure 7. It shows that one input contact connected to address “I0.0” and its tag named “trigger_timer” is connected to the timer input. And the preset value is set to be one minute “T#1m” which means one minute. Notice the format is very simple. You type T denoting the time format and then “#” followed by the amount of time and at last the unit of time which could be “MS” for milliseconds, “S” for seconds, “m” for minutes, “d” for days … et cetera. Moving to the outputs, the timer output “Q” is connected to the motor meaning that the motor will be running after the timer counts complete one minute. The other output is “ET” which tells the time elapsed so far since the timer set to start counting time. Let’s go to the simulator window on the left side. We added all inputs and outputs to control the inputs and show the output as well. You can notice that, by setting the input “trigger_timer” to true, the timer starts counting the time as you can read in the “ET” variable that shows the time spent so far “T#29S_335MS” meaning 29 seconds and 335 milliseconds have been elapsed since input set to true. Since the PT time is not reached, the output is still false as shown in blue color.

Figure 7: ON-Delay timer sample program with a simulator

Figure 8 shows the moment when the timer reached the PT value which is one minute in our example. You can notice on the left window, the ET value becomes one minute which is equal to the PT value. Therefore, the timer output turned to true and the motor is switched on consequently. To sum up, this example shows how the output has become ON after one minute delay of the input.

Figure 8: ON-Delay timer energized the output after one minute delay

OFF delay timer example ladder program

After we have shown how we can delay the start of a motor by using the On Delay timer. Here we are going to show how to delay the shutdown. Figure 9 shows an example of a very simple ladder program that uses an OFF delay timer to delay the shutdown of an output. As you can see on the left the input is ON and the output starts running with the input at the same time. Let's try to set the input OFF as in figure 10, you can notice the output is still ON and the time counter is incrementing until it reaches the PT value which is set to one minute in our example. Figure 11 reports the moment at which the time counter reached the PT value which is one minute. At that moment the output or the motor is shut down. In a conclusion, the Off delay timer is our tool to delay the shutdown of output or terminate a process.

Figure 9: OFF delay timer example

Figure 10: The input is off while input is still run

Figure 11: the output shutdown delayed one minute

Pulse timer example

In this example, we are going to start and stop the motor in a pulsative operation mode thanks to the pulse timer type. That means the input to the timer will start the output to run for a specific amount of time that is present in the PT value regardless of receiving any other input pulses. In figure 12, the pulse timer example is shown. The very simple ladder logic program is displayed on the left window and the simulation is shown on the left window. You can notice that, once the timer received a high state of the input, it energized the output and started counting the time. However, when the input went OFF the output keep running ON for the designated while represented in PT value which is one minute for this example as shown in figure 13. Let’s test the condition of having another input signal as shown in figure 14. When the input goes again high which the last pulse does not complete, the output continues running and the timer does not reset its timing count. However, when the pulse time is reached as in figure 15, the output is shut down and the timer now is ready to start another pulse by noticing a rising edge of the input.

Figure 12: pulse timer example

Figure 13: the output continue running for its pulse period

Figure 14: another pulse does not reset the timer until complete one pulse period

Figure 15: output shutdown after completing pulse period

Accumulative timer ladder example

In this ladder example, we are going to show you how to continue accumulating the time until reaching the PS value at which the timer energizes its output as shown in figure 16. The example shows a very simple ladder code that has two inputs connected in parallel to OR logic. So any of these two inputs will trigger the counter to count up the time. On the left window, all inputs and outputs including timer operand and outputs are listed in simulating table to show the values while the program is executing.

Figure 16: an accumulative timer ladder example program

Let us start triggering the timer by one of the inputs as shown in figure 17. As you can notice the timer starts counting the time as shown in the ET value on the left window showing the simulation. What if we set the inputs OFF? In the ON Delay timer, the time will be reset. But in this timer, it does not and instead, it waits for another input signal to accumulatively increment the time till reaching the PT value as shown in figure 18. Let’s verify the concept by setting one of the inputs ON as shown in figure 19, the timer accumulates the timing counter until it reached the PT value which is set to one minute in this example. At that moment the output is energized as shown in figure 20. And finally, figure 21 shows how the timer is reset by switching on a reset button. One good practical example for using this type of timer is the maintenance schedule. For example, we can schedule the maintenance to be conducted after one year or after a specific amount of time or number of operating hours. So the timer will keep accumulating the time of operation regardless of the downtime and raise a flag to notify it is the time for performing maintenance.

Figure 17: starting the timer by enabling one of the inputs

Figure 18: setting the inputs off does not reset the timer

Figure 19: timer accumulates the time

Figure 20: the output goes ON after reaching the PT value

Figure 21: timer reset its timing count

What next

I would like to thank you so much for following up with our tutorial that far. So far you are familiar with timers types and how to utilize the suitable one for your task based on the logic you want to perform. Next tutorial we are going to go through counters showing their types and functionalities and for what reasons we need counters how we can use them appropriately.

Latching in Ladder Logic Programming

Hi friends! I hope you are doing well! Today we are going to learn and practice a new topic which is a very crucial technique in plc programming. the topic is called “latching”. We mean by Latching to keep the output running starting from the instance of giving a kick-off command until we hit a command to stop running of the motor. Imagine my friends, operator wants to start a motor by hitting a start push button and want the motor to keep running and leave and go for doing another task or job. And then it keeps running until the operator wants to stop it. The problem here is that, once the operator releases his hand away from the push button, the motor automatically stopped and that is not like what the operator wants to do with the motor. To clear the problem that we are going to solve, and for which we need to use the latching technique to connect a load, Figure 1 has been created for you to show the situation to make a direct connection to a motor by using a simple push-button. In this circuit, the operator needs to keep pressing the push button as long as he needs the motor to keep working. Otherwise, the motor will stop once he releases the push button. So would please think with to figure out what is the solution for that?

Fig. 1: Connecting motor to power by push button directly

Let’s try to connect the motor through a relay as it is typically in the industry. Maybe that helps us to control the way to energize the relay coil and use its contacts to start and stop the motor, Figure 2 shows how we can employ a relay to connect the motor to the power source. However, again In fig. 2, the operator still has to keep pressing the button as long as he wants the motor to keep running. This is not the best practice in real life, the operator has many jobs to do. So, he wants to give the command to commence running the motor and leave it running to perform some other tasks and then has the motor stops after the job has been done. In this case, latching is the best practice to connect the motor or any load we want it to run for a while or until complete some functions.

Fig. 2: relaying motor to DC power by hitting start push button

How does latching work?

Now, I hope you can feel the problem between our hands and sense the meaning of the word “latching”. Again, in a real-life situation, motors or any actuators can be run via relay, by energizing the relay’s coil, the contacts of the relay switches over from off to on and then connects the motor to let it starts spinning. So for running the motor, the rely on coil should be energized. However, the latching technique makes that requirements go away, instead of that, the contact that has been used for connecting the motor to power, is used to be another pathway to connect the rely on the coil to power without needing to keep pressing the start push button. WoW! What amazing solution is that! to just hit a button and then forget about it and use the contact to make like a closed-loop to have the coil connected to power forever and let the motor work forever. Ohhh!! Forever!!! How do we run the motor without stopping? Yes, you are correct. It should be a way to break that loop when we want to do stop it. we need a way to just stop the latching, to break its loop, to enable the operator to stop the motor when they need to do.

Steps to perform latching

Let’s now show you guys how we can establish and construct a complete latching circuit step by step. In the following subsections, three steps by which will be demonstrating how to complete a typical latching circuit including only push-button and relay.

Latching Step one

First of all, in a very simple circuitry which is shown in Fig. 3, the DC power lines positive and negative are connected with a push-button and relay to run a load. The positive wire in red is connected to the push button and then to the coil terminal A1 and A2, and then to the ground black wire. So now, it’s clear that when the push button is pressed it turned on and connects the circuit of the relay coil all the way to be energized. As a result, the contact of the relay is connected and now it is ready to connect the external circuit to run an actuator i.e. motor. But when the push button is released, the coil will be de-energized and the relay coil turns back to the open state and the motor is going to stop. So moving to the next step of building a latching circuit in which we aim at creating another pathway to supply the relay coil with power to forget about the push button and have it continue to run even after releasing the push button.

Fig. 3: the typical push-button and relay circuit

Latching step two

Now Fig. 4 shows the main wiring schematic of a basic latching circuit by which we indeed realize the concept and functionality of the latching technique. in the circuit, you can notice my friends that, the contact upper point and the relay upper point are connected in such a way that, it creates another pathway for energizing the relay coil without any needs to press or even touch the push-button B1. Again, when the push button B1 is pressed, the relay coil will be energized. As a result, the relay contact will be close contacted and in turn bridges point A1 to the positive red wire. Now, when the push button is released, the relay coil still has another pathway to connect to the positive wire so the relay coil will keep energized. I know now what comes out to your mind? if this configuration and schematic can put the relay coil in the loop and energize all the time by the first kick-off by hitting the start button thanks to the latching technique. The question now is, how about stopping the motor?. How to break this loop? Yes, that’s the only thing is remaining to complete a typical latching circuit.

Fig. 4: the second step of latching

Latching step three

We can name this step by ending latching. As shown in fig. 5, a normally close (NC) push-button B2 is added in the way from contact to the positive, red, power wire. Firstly, when the push button B1 is pressed, the relay coil is energized. And the contact of the coil is connected to the positive red wire as the push-button B2 is in a closed state by default. So now, it will be latching as long as the connection to the positive wire does not break. So by hitting push-button B2, it will turn out to open state and the connection to the positive wire is broken. Therefore, the relay coil will be de-energized and the latching gets to stop.

Fig. 5: Ending latching step 3

Latching in ladder logic programming

I know guys you all are waiting to come to this point to go to our lab and simulator and practice our tutorial. So now after we discussed the concept and basics of what latching is and how does it work? We now are all set to start our simulator and practice latching techniques in ladder logic programming as we used to do every tutorial.

Ladder logic without latching

Now we need to connect a simple start push button “input A” to the motor at “output” Q0.0 straight forward as in fig. 6. You can see, by pressing the input push button switch, the output motor starts spinning. But how about after releasing our hands off the start button?

Fig. 6: Before latching

Well done! Yes, exactly like what you expected, as shown in fig. 7, when the start pushbutton has been released, the motor stops immediately.

Fig. 7: the motor stops when we released the start button

Now by adding another pathway to run the motor as shown in Fig. 8, a contact from relay “output” has been used in parallel to form “OR” logic with the start push button. So, in the first place, when the start button is pressed, the output goes high and the closed contact now adds another pathway in “OR” logic.

Fig. 8: the latching effect in ladder logic example

Figure 9 shows how the closed contact that has been taken from the relay plays the role of the alternative path to connect the output to the power. So when the input start push button has been released, the closed contact of the output relay makes the connection and the output continue running. However, there is now one problem that, how to break that connection to stop the output?

Fig. 9: the latching effect after releasing the start button

The solution for having a way to shut down or break the latching connection is that, adding a normally closed (NC) push button “input B” in series as shown in fig. 10. This way enables to break the latching connection and shut down the output.

Fig. 10: adding a stop push button to end latching

So by hitting input B, the connection of latching is broken and the output stops running. But breaking the connection will make an issue if the input B is a switch like an emergency switch. The problem is that it should be returned to its normally closed state to enable the cycle to start by hitting input A or the start push button.

Fig. 11: the usage of adding stop button to end latching

By having the stop button return to the normally closed condition, the cycle can be restarted by pressing the start push button and enabling the latching once again.

Fig. 12: restarting the process by resetting the stop push button

Latching using set and reset

There is another way to perform latching of the output. The set instruction can be used to set the output to run until a reset command is met to reset the output. This is a piece of cake to latch an output by employing set and reset instructions. Let’s practice this way in the simulator. Figure 13 shows a simple ladder logic program that uses set and reset instructions to perform latching of the output. Input push-button input A is used to set the output while input push-button input B is used to reset the latch of the output.

Fig. 13: latching using set and reset technique

By hitting the input at I0.0 which is input A, the output is set to true. The question is what happens when input A becomes false?

Fig. 14: set to enable latching the output

Figure 15 answers our wondering that, even after input becomes false the output keeps energized thanks to using a set instruction. So when will see the output turns out to be false?

Fig. 15: the output keep set true even after input becomes false

After setting the output to true, it won’t become false until a reset command is used like in the example shown in fig. 16. The output is reset by input B and becomes a false state.

Fig. 16: reset to end the latching

What’s next?

I really would like to thank you guys so much to follow our tutorial till this point and I hope you have become well known for latching concepts, and how to use and utilize them to solve a real problem in real industrial life. Now let’s continue our series, learn and enjoy practicing ladder logic programming series. Our next station will be the comparator operators including equal, not equal, greater than, equal, less than, et cetera. And how to master using this operator to compare different data types and control the logic of a ladder logic program based on the results of these comparator operators.

Bottle Filling and Capping Project using PLC Ladder Logic

Hi friends, how are you doing? Today will integrate all of what we have learned so far in this series to build the first project based on ladder logic programming. Because we all are interested in industry, we pick one industrial project, Bottle Filling and Capping Projects, which is very common today. The problem we are going to solve today is bottle filling and capping. We have learned all basics of ladder logic including contacts and coils operation, logic gates, rising and falling edges, timers, and counters. So, today we will utilize all of these components to implement a complete ladder program of filling and capping problems.

Operation and Logic of Bottle Filling and Capping Process

For simplifying the operation of the process of filling and capping, fig. 1 shows the process flow which simply contains the main motor that drives the conveyor belt on which the bottles are running starting by hitting the start button. The conveyor belt starts running driven by motor M1 and the bottles move until sensor S2 detects one bottle, then motor M1 stops and the belt does so. At the same time, valve V1 opens to let water get dropped into the bottle until it reaches specific level thanks to level sensor S1. Then valve V1 closes and motor M1 goes on moving. Then when sensor S3 sees a bottle, the piston P1 is activated for capping the bottle and so on.

Fig. 1. The Filling and Capping Process

Process Inputs and Outputs

As you can see, for every single process in the industry, there are inputs and outputs. The inputs represent the sensors and user requests like starting and stopping the process. While the outputs are represented by actuators like motors, valves, and pistons. Table 1 lists the inputs and outputs of the filling and capping process. It shows the process consists of four inputs and three outputs including the function and description of each item.

Table 1: The list of Inputs and outputs of the Process

Logic Design of the Operation

Before going to ladder programming, we should design the logic of the operation to build guidelines on which we can develop the ladder logic. According to the operation description we stated aforementioned above, we can express the logic in lines as follows:

  • If start is ON, no filling is in progress meaning sensor S2 does not see a bottle, and no stop is requested, then motor M1 is ON.
  • If sensor S2 is ON, that means there is a bottle at a position to be filled so motor M1 will be stopped or OFF.
  • If sensor S2 is ON, that means a filling process is in progress, therefore, Valve V1 will open
  • If S1 is ON, that means the liquid in the bottle that is being filled reached the maximum level, So valve V1 closes and motor M1 now goes on running.
  • If S3 is ON, that means there is a bottle that presents at the capping station, So the piston P1 is retracted to process the capping of the bottle.

As you see in these few lines, we just wrote the philosophy of the filling and capping process’s logic. And the process keeps repeating until user requests stop. So now let’s move to convert this written logic into ladder logic rungs and enjoy for sure simulating the process in our lab to verify the logic we designed is correct or we need to amend.

Ladder Logic of Bottle Filling and Capping System

Before getting starting the filling and capping programming, we need to design the list of inputs and outputs of the program and their initial states. Table 2 shows a list of the inputs and outputs with their addresses and initial states.

Table 2: The Inputs and Outputs list with Addresses and Initial States

Figure 2 shows the first network in the designed ladder program. My friends, do not feel it a complicated because the fact is that, it is really simple. First of all, the start button to run the conveyor belt motor coil and latching is considered for letting the belt resumes running even after releasing the start button. Also, you should ask yourself during design two questions. The first is when the motor of the conveyor belt will be running and when to stop it? The answer to these two questions will end up with completing this network. For instance, the first question which inquiries about when to start the conveyor belt can show that the belt should be running by hitting the start push button to represent the request of the user to run the process. But, while the filling process is in progress marked by the activation of sensor S2, the conveyor should stop waiting for the filling process to complete by closing the valve when reaching the filling level limit noted by sensor S1. So, closing the valve is another signal that starts the conveyor once again. On the other hand, the conveyor belt should stop when the stop is requested by the operator in addition to sensor S2 that indicates a presence of a bottle in the filling station. So, you can notice two parallel branches to run the conveyor belt, one by start push button and one for latching. In addition, another parallel branch is added to run the belt by showing the completion of the filling process thanks to the signals of valve V1 status.

Fig. 2: Ladder Logic Network 1

Now, let’s have a look at the valve and ask ourselves the same question as what we have done with the motor of the conveyor belt (M1). what makes the valve V1 get closed and what causes it to open? For those causes to open the valve are the signal of sensor S1 that tells the bottle that is being filled is already filled and all set to move to cap station in addition to the latching consideration. So, we have two parallel branches, one branch for the sensor S1 and the other one from the valve status contact for latching. Those parrel branches connected in series to show “AND” logic with the sensor S2 to make sure of the presence of a bottle in the filling station. On the other hand, the stop push button represents an ending request received at any time from the user to close the valve.

Fig. 3: Ladder logic network 2

Now, the process goes on and the bottle has just left the filling station and has reached to capping station. That has been recognized thanks to sensor S3 that detects a bottle that has just arrived at the capping station. As a result, the piston should be activated. Firstly, a timer has been utilized to let the piston activated for some amount of time that is enough to let the capping process be comfortably completed. So, in-network 3 shown in fig. 4, a timer which is of off-delay type is utilized to activate the capping piston for plenty of time to let the capping process be completed as shown in fig. 5.

Fig. 4: Ladder Logic Network 3

Fig. 5: Ladder Logic Network 4

And finally, in-network 5 shown in fig.6, the falling edge signal of the piston denotes the completion of the capping process. So, a counter which is of type count-up timer is triggered to count up to determine the number of the processed bottle so far. The preset value has been set to a specific value i.e. 100 which can be used to perform maintenance or end a batch process for 100 bottles to be filled and capped.

Fig. 6: Ladder Logic Network 5

Compiling the Ladder Logic of the Project

After translating the writing logic to a ladder program that is composed of a couple of rungs, the second compulsory step is to verify the syntax of the ladder program and make sure that the program is free of error. So, we show you in fig. 7 the compilation results to show there is no error with the written code so far. By doing this verification, we are all set now to upload the program to the controller and check the logic and operations.

 

Fig. 7: Compiling the Designed Ladder Logic Program

Simulating and Testing

It is time to go to our lab and open the simulator to check the design and written ladder code. Figure 8 shows the initial state of the program before starting the process. It is clear that the conveyor belt is stopped and the status of all sensors, pushbuttons, actuators are as their aforementioned initial states.

Fig. 8: Initial State of the Inputs and Outputs Before Starting the Process

Now, let’s hit the start push button to start the process and watch what is going on. Figure 9 shows good news!!! By hitting the start button, the process correctly started and the motor M1 that drives the conveyor belt starts spinning. But, how about checking to release the start pushbutton by leaving our hand to see what’s going on?

Fig. 9: The status After Hitting Start the Process

WoW!!, well done, latching is working as shown in fig. 10 as the conveyor continues spinning even after releasing the start button thanks to applying the latching technique.

Fig. 10: Conveyor Still Running Even after Release start Push Button Thanks to Latching

Once a bottle is presented at the filling station, sensor S2 is activated. Consequently, the conveyor stops waiting for the filling process to complete. But, when does the filling process ended and how to know it’s done already to go further?

Fig. 11: Conveyor Stops when a Bottle Presents at S2 for Filling

Well! Sensor S1 is there to watch the level to which the liquid reaches in the bottle that is being filled. Once the limit is reached, sensor S1 is activated telling hey here we go, the filling process is over and now we ready to go further to the next step which is the capping station as shown in fig. 12.

Fig. 12: The Valve is Closed by reaching the Limit Level and S1 is ON

Because the valve is closed after the filling limit is reached, the conveyor continues spinning and sensor S2 is deactivated showing the bottle has been filled and left the filling station. However, the conveyor belt keeps running thanks to the latch again as shown in Fig. 12.

Fig. 13: The Conveyor belt Goes Running by Closing The Valve V1

Let’s now my friends check what’s happening by reaching the capping station? Astonishing !!! as we put there our agent to tell us a bottle has arrived for capping which is sensor S3, once that happened, sensor S3 is activated and hence activates the piston to retract and keep retracted for a sufficient amount of time to let the capping process be completed thanks to using a timer of type off-delay timer. So first fig. 14 shows in network number 3, the timer is activated and starts counting the time that is preset to 2 seconds and in the same time activates the piston to keep retracted during that time based on the nature of operation of an off-delay timer.

Fig. 14: The Piston is Activated by Reaching at Capping station When S3 is ON

And finally, the counter is utilized to count the processed bottles which are triggered by the falling edge of the piston denoting completion of a filling and capping process.

Fig. 15: The Counter Counts up Every item After the Capping Process

What’s next

By reaching this line in our tutorial, I would like to congratulate you that you are now all set to think about complete basic problems in the industry and design the logic to solve them and write the ladder code. Is here the end station of our ladder logic tutorial? For sure no, we still have a lot to move forward from the basic level to become experts. So wait for the next tutorial in which we go deeply into details of math and logic functions and data processing.

Signal Edge Detection in Ladder Logic

Hello friends, How are you doing? Today, we have a very interesting topic of PLC ladder programming which is how to detect the transition between true and false and from low to high?. I know you are asking why do we need that? Well! Imagine my friends, we want to start a motor when the input signal state changes from high to low or from false to true. Let us give two examples to highlight the edge detection techniques. Good examples of using edge detection-based logic are timers and counters. In counters, they are energized to count up or down when a signal appears and the same for timers. Figure 1 shows the difference between using the edge to control a motor. In the top part, the motor is controlled by an input switch. the output is ON and OFF based on the status of the input. But, in the second example, the rising edge is used to energize a motor. So, the motor comes to true when the switch state changes from false to true. On the other hand, imagine my friends if you want to activate a protection relay or safety function based on the result of the logic operation (RLO) for output, in that case, we can control the running of the output for one scan cycle to be based on the change in the state of the RLO.

Fig. 1: Rising edge logic

Signal Edge Types

There are two edge types:

  1. Falling edge.
  2. Rising edge.
Figure 2 shows the falling and rising edge signal. It shows the falling edge happens when the signal turned from true to false while the rising edge when it signals changes from false to true.

Fig. 2: The falling and rising edge of a signal

Rising Edge in PLC Ladder Logic

Figure 3 shows the general symbol of a rising edge. The letter “P” denotes a positive edge. while fig. 4. Depicts the rising edge in ladder logic in the TIA portal of siemens software.

Fig. 3: the general symbol of a positive or rising edge

In ladder programming, the rising edge shows a positive rising edge received for the signals. In fig. 4, the rising edge is for the signal tagged as “TagIn_4” and the previously saved value is stored in “Tag_M”. the system can recognize a rising edge by comparing the buffered value stored in “Tag_M” and the current value in “TagIn_4”. For example, if the previous value stored in “Tag_M” is False, and the current value in “TagIn_4” shows high logic, this would mean a rising edge is received.

Fig. 4: the rising edge in a plc ladder program

Falling edge in PLC ladder

Figure 5 shows the general symbol of a falling edge. The letter “N” denotes a negative edge. while fig. 6. Depicts the falling edge in ladder logic in the TIA portal of siemens software.

Fig. 5: the general symbol of a negative or falling edge

In ladder programming, the rising edge shows a negative or falling edge received for the signals. In fig. 6, the falling edge is for the signal tagged as “TagIn_4” and the previously saved value is stored in “Tag_M”. the system can recognize a falling edge by comparing the buffered value stored in “Tag_M” and the current value in “TagIn_4”. For example, if the previous value stored in “Tag_M” is True, and the current value in “TagIn_4” shows low or false logic, this would mean a falling edge is received.

Fig. 6: the falling edge in a plc ladder program

Set Output on a Positive Edge

Now let’s do the same concept on the output side, fig. 7 shows the set output ladder instruction on a rising or positive edge. In this instruction, the result of the logic operation (RLO) which represents the left part before the output is evaluated to check the transition in its state. If the RLO changes from false to true then the output will be set for one scan cycle.

Fig. 7: the set output on positive edge instruction

Figure 8 shows an example of the set output on a positive edge. On the most left, the coil with the letter “P” inside represents the instruction. The instruction works by saving the previous value of RLO into “Tag_M” and verifying the changes in a state with “TagOut”. For example, if the “Tag_M” holds a true state while the previously stored value in “Tag_M” was false. That would show a positive edge and the output will be set to true for the complete scan cycle.

Fig. 8: example of set output on a rising edge

Set Output on a Negative Edge

Figure 9 shows the set output ladder instruction on a falling or negative edge. In this instruction, the result of the logic operation (RLO) which represents the left part before the output is evaluated to check the transition in its state. If the RLO changes from true to false then the output will be set for one scan cycle based on detecting a falling edge of RLO.

Fig. 9: instruction of set output on falling edge

Figure 10 shows an example of the set output on a falling or negative edge. On the most left, the coil with the letter “N” inside represents the instruction. The instruction works by saving the previous value of RLO into “Tag_M” and verifying the changes in a state with “TagOut”. For example, if the “Tag_M” holds a false state while the previously stored value in “Tag_M” was true. That would show a negative or falling edge of the RLO. Consequently, the output will be set to true for the complete scan cycle.

Fig. 10: example of set output instruction base don falling edge

Simulating edge detection

Now let’s go to our lab and open a simulator to enjoy practicing very critical points in ladder logic programming. Yes, my friends, these are very critical points and are used smartly in solving very hard problems to solve. But, by comprehensive these points, you will be superb in your field as a prospective ladder logic programmer. Two points we are going to simulate, the first one is the ringing and falling edge of the inputs and their effects on activating and energizing the output for a complete pulse. And the rising and falling edge cases of the result of logic output (RLO) and its effects on energizing the output for a complete pulse.

Simulating rising edge

Now, let’s assume we have a situation in the factory that, when specific action occurred, the output will be energized. In the example represented by fig. 11, when and only when input A, turned on, we need to start the output. That means the only scenario in which the output is turned on is when input A state changed from false to true. So let us simulate three scenarios, the first one shown in fig. 11, in this scenario the input previous status is saved in input B, while the current or new state is saved in input A. notice when the input does not change and it is false, the output is turned off.

Fig. 11: the rising edge scenario 1

Now let’s turn on input A, so now input changed from false to true as shown in Fig. 12. Ohh, notice the output comes true and that’s the rising edge at when the input changes from false to true.

Fig. 12: the rising edge scenario 2

And in the last scenario, when the input keeps true meaning the previous status was true and the current state is true, then the output is false as shown in Fig. 13.

Fig. 13: the rising edge scenario 3

In a conclusion, in rising edge, the output only gets true when the input changed from false to true.

Falling Edge in PLC Simulator

Now, let’s assume we have another situation in the factory that, when an input or sensor turns off or changed from true to false, the output will be energized. In the example represented by fig. 14, when and only when input A, turned out from ON to off, the output will be energized. That means the only scenario in which the output is turned on is when input A state changed from true to false. So let us simulate three scenarios, the first one shown in fig. 14, in this scenario the input previous status is saved in input B, while the current or new state is saved in input A. notice when the input does not change and it is false, the output is turned off.

Fig. 14: the falling edge scenario 1

Now let’s turn on input A, so now input changed from false to true as shown in Fig. 15. Ohh, notice the output is false because that’s not a falling edge as the input changes from false to true.

Fig. 15: the falling edge scenario 2

And in the last scenario, when the input changed from true to false which is a falling edge. Therefore, the output turned on as in fig. 16.

Fig. 16: the falling edge scenario 3

In a conclusion, in a falling edge, the output only gets true when the input changed from true to false.

Simulating set output on the rising edge

Now, my friends, we need to run the output for one pulse based on the result of logic output (RLO). Figure 17 shows the scenario of having a false state of the RLO, the output is false because there is no falling edge detected for the RLO.

Fig. 17: set output on rising edge scenario 1

Figure 18 shows the case when the RLO is turned from false to true, the output comes true but for one pulse notice the previous status represented by buffer has become false but the output after pulse time returns to false. However, the pulse of the output has been detected thanks to energizing output tag_5.

Fig. 18: set output on rising edge scenario 2

Simulating set output on falling edge

Figure 19 shows the very initial case of set output with a falling edge. To show, the case of the falling edge of RLO, we use another rung that would energize another output at Q0.6 when and only when the falling edge of the RLO occurs. In Fig. 19, the RLO was false. Therefore, there is no cause for a falling edge when RLO changed from true to false. So the output shows a false state.

Fig. 19: set output on falling edge when RLO was initially false

Now let’s turn on the RLO, so the RLO changed from false to true which is still not a case of a falling edge of the RLO. SO the output is still false as shown in Fig. 20 represented by output Q0.6.

Fig. 20: set output on falling edge when RLO turned to on

Figure .21 shows the scenario of the RLO turning from true to false which is a falling edge. In that case, the output will be turned on for one pulse and as a result, latching output at Q0.6 as shown in rung 2 of fig. 21.

Fig. 21: set output on falling edge when the RLO turned back to false (falling edge)

What’s Next

Once more I would like to thank all my friends for continuing with our learning and practicing our PLC ladder logic series. Now we have learned the concept of edge detection, its importance, and how we can utilize the rising and following edge in some critical and accurate cases of logic. The rising and falling edge of the inputs can energize an output in a pulsative way or for only one pulse. This scenario exists in the industry and is very common. For example, when you want to energize a safety device by the occurrence of some conditions like increase of liquid level or temperature or pressure et cetera. Also, the result of logic output (RLO), can be used to set or reset output for one pulse. In the next tutorial, we are going to introduce the latching in more detail showing why we need to latch an output, the ways of latching with examples, and for sure enjoying our practicing with the PLC ladder logic simulator.

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir