Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

Hello everyone, I received a submission from a fan who mentioned seeing the RETURN instruction used in someone else’s program and asked me to explain its usage.

As the name suggests, RETURN means to return. In a program, it is used to control the execution flow, returning to the point of the higher-level call. When used appropriately, it can improve the efficiency of program execution and reduce the scan cycle of the PLC..

RETURN is a program control instruction. In the TIA Portal instruction bar, you can see that program control instructions also include JMP and SWITCH type instructions.

So, what are program control instructions?

Let’s take a look at this ladder diagram. We know that the PLC executes the ladder diagram in a top-to-bottom, left-to-right order, executing one line at a time, which is usually the case.

Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

Is it necessary to execute every part of the program each time? Actually, it is not. For example, in this automatic program, if it is in manual mode, there is no need to execute it at all. In automatic mode, if it has not started running, the process step part also does not need to be executed. After starting the run, it only needs to execute the current step of the program. For instance, if we are at process step 2, we only need to execute the program segment for process step 2; there is no need to execute process step 1 and process step 3.

OK, so how do we control which parts of the program are executed each time and which are not? This is the role of program control instructions.

Program control instructions disrupt the sequential execution of the ladder diagram by the PLC, allowing it to skip or ignore certain parts of the ladder diagram.

For example, let’s modify this automatic program.

The first requirement is that in manual mode, this segment of the program should not be executed, which can be achieved using the RETURN instruction.

Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

By adding this line to the ladder diagram, the effect is that when in manual mode, after the program reaches program segment 1, it will directly return and will not execute program segment 2 and the subsequent programs. Where does the program return to? It returns to the place that called the current block. For example, here we are in the Auto program block OB124, so it will return to the place that called OB124 and continue executing downwards. Since this program only contains OB124 and OB1, it will continue executing the OB1 Main program block.

If the RETURN instruction is used within an FC function or FB function block, it will return to the place that called this FC function or FB function block to continue executing.

This is the function of the RETURN instruction: to immediately return the program to the upper-level call point and continue execution.

Similarly, when in automatic mode and not started, the RETURN instruction can also be used to return immediately.

Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

When in automatic mode and already running, the JMP jump instruction can be used to jump based on the current step information, directly jumping from program segment 4 to the location of the label. For example, if the current step is 2, after executing program segment 4, it will skip program segment 5 and jump to the location of program segment 6 to continue execution.

Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

Using RETURN in PLC Programming to Improve Efficiency and Reduce Scan Cycles

This is the role of program control instructions like RETURN and JMP, which allow you to skip executing the current block’s program directly or skip a portion of the program to continue executing non-adjacent program segments.

I suggest that unless the scan time is too long and there is a strong need to optimize the program, use program control instructions with caution, as excessive use can complicate debugging and maintenance.

For complex functions, you can use IF ELSE, FOR, SWITCH, etc., in SCL language to accomplish them.

That’s it for this issue. If you found it helpful, please like and follow.

If you have any questions or want to submit, feel free to leave a comment or send a private message.

Leave a Comment