Tia Portal – OB121 Programming Errors Interrupt Organization Block

In this article, we continue our discussion about different types of organization blocks in Siemens PLC. This time we will take about the OB121 or the programming errors interrupt in the Tia portal.

Contents:

  • What are programming errors interrupt OB121?
  • Examples of programming errors.
  • What will happen if a programming error is detected?
  • Simulating a programming error in TIA Portal.
  • How can the OB121 be useful against programming errors?
  • Conclusions.

What are Programming Errors Interrupt (OB121)?

OB121 is an organization block that will get called by the PLC’s operating system if a programming error occurs while running your logic. Note that we are not talking about a programming error that will be caught by the compiler when trying to download your logic into your PLC. See picture 1.

OB121 Programming Errors Interrupt Organization Block
Picture 1 – Some programming errors will get caught by the compiler

As you see from the last picture, there is a programming error in my PLC logic; some operands are missing in the input and output of Network 1. But, this error was caught by the compiler before even downloading the logic into the PLC. The error in picture 1 is not the programming error type that can trigger the need to call OB121.

Errors in your PLC program that can’t be found by the compiler, but still can cause troubles in your logic while PLC is running are the programming errors we mean. These errors will trigger a call to the OB121 by the operating system.

Examples of Programming Errors

Here are some examples of mistakes in your PLC logic that can cause programming errors:

  • Maximum nesting depth of block calls exceeded.
  • You have used a NULL pointer to address an operand.
  • Unknown instruction.
  • The addressed string has incorrect length information.
  • Area length error when reading.
  • Area length error when writing.
  • Error in timer no.
  • Access to a DB that is not loaded; the DB number is located in the permitted area.
  • DB does not exist.

These errors and many more can cause programming errors in your PLC. You can check the Help section of the TIA Portal to find out what other reasons can cause PLC programming errors.

What will happen if a Programming Error is Detected?

When your PLC detects a programming error, one of three events can occur.

  1. Your PLC will show an error and go to STOP mode.
  2. Your PLC will show an error but keep running your logic.
  3. Your PLC will show an error then try to solve this error.

These three events will depend basically on your PLC programming. Meaning your code will decide how the operating system will behave when detecting a programming error.

 Simulating a programming error in TIA Portal

To better understand how the PLC will behave, we will create a simple program where we cause a programming error, and then we will see what will happen. See picture 2.

OB121
Picture 2 – Simple program logic

The logic we created is very simple, when the InitiateProgError has been enabled the value of 126 will be moved into DB52.DBW16 area. Note that we haven’t created DB52. so, that will be our programming error. Note that this error will not be caught during compiling or downloading into the PLC. See pictures 3 and 4.

PLC Error not caught by the compiler
Picture 3 – Error not caught by the compiler

See how the block was successfully compiled, while including a programming error.

Block downloaded into PLC
Picture 4 – Block downloaded into PLC

Again, the block was downloaded into PLC with a programming error.

Now, let’s simulate our PLC program and see what will happen. See animation 1 for the simulation of the PLC code.

PLC Programming Error OB121
Animation 1

As you see from the above animation, the PLC ERROR LED will flash red for a few seconds then the PLC will go into STOP mode.

Go to PLC online diagnostics to see what happened. See picture 5.

Online and diagnostics of the PLC
Picture 5 – Online and diagnostics of the PLC

What you saw in the animation is exactly what you see in the previous picture. They can be mentioned into 3 steps:

  1. The PLC detects the programming error which is OB52 not loaded.
  2. The operating system will trigger the call for the OB121, but there is no OB121 created in our logic.
  3. When the PLC finds out that there is no OB121 created in our logic, the operating system will initiate a request STOP. And the PLC will go into STOP mode.

How can the OB121 be useful against Programming Errors?

Let’s add an OB121 to our PLC code and see how things will change. See picture 6.

TIA Portal OB121
Picture 6 – Adding an OB121

After creating and adding the OB121 into our PLC logic, let’s see what will happen in the simulation.

Keep in mind that we haven’t written any PLC logic inside the OB121. See animation 2.

Programming Error Handling in Siemens PLC
Animation 2

As you see from animation 2, when InitiateProgError is triggered, the PLC ERROR led will flash red but the PLC will keep running.

Meaning that the PLC will not go into STOP mode. Let’s check the online diagnostics to see what actually happened. See picture 7.

Siemens PLC Organization Blocks used For Troubleshooting
Picture 7 – Error didn’t cause PLC stop

You see from the picture that the PLC detects the error but doesn’t go into STOP mode. It will skip this error, continue the cycle and start all over again from the beginning.

When it arrives at the error again, it will detect the error again, giving an alarm in the diagnostics. Skip the error and continue. That means the PLC will give the same alarm every scan cycle. And that is why in the picture you see the event keeps triggered and the alarm is repeating each scan cycle.

So, just having an empty OB121 will give you the benefit of keeping the PLC running and y extension, keeping your process running.

But, there is more we can do, we can try to catch this error and eliminate it. Also, we can try to show the type of programming error detected.

Determine the Error Type

The OB121 has an internal fault ID identifier that we can use to show the type of fault, maybe as an alarm on an HMI. Inside the OB121 we will create a simple MOVE instruction, where we will push the Fault_ID input of the OB121 to a defined memory area inside our global DB. See picture 8.

Identifying the error type in PLC
Picture 8 – Identifying the error type

As you see from the previous picture, when the programming error occurs, the Fault_ID will be pushed into the Data.ProgErrorID. See picture 9.

Siemens PLC Programming Error Fault
Picture 9 – Programming Error Fault_ID

You can see the fault ID is 3A. if you check the TIA Portal help you can find the meaning of this fault. 

3A: Access to a DB that is not loaded; the DB number is located in the permitted area.

Catching the Error

This simply means, trying to solve the PLC programming error after you have identified the reason. This will depend mainly on what is the error and how you want to handle it. We will just simulate a solution to the error, to see how the PLC will behave.

The actual solution for the error we created will be to just create the DB52 or use a data block that is already created.

But for the sake of simulation, we will just add a simple contact that will open when the programming error occurs to catch this error. See pictures 10 and 11.

Catching the Siemens PLC error
Picture 10 – Catching the error

Whenever OB121 is called, the CatchError will be set.

Eliminate the PLC error
Picture 11 – Eliminate the error

Whenever OB121 is called, the CatchError will be set, and it will be used to catch the programming error in Network 1. See animation 3 for the PLC simulation.

Siemens PLC organization blocks fault
Animation 3

From the above animation, you can see that when the InitiateProgError is triggered, the PLC will go into error for a moment then the error will be cleared and the PLC is in RUN mode all the time.

Downloads:

Conclusion

Just having an empty OB121 in your logic will ensure that your PLC will not go into STOP mode if there was a programming error in your code. You can later use the OB121 to also identify the error and solve it.

If you liked this article, then please subscribe to our YouTube Channel for Instrumentation, Electrical, PLC, and SCADA video tutorials.

You can also follow us on Facebook and Twitter to receive daily updates.

Read Next:

Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address

Leave a Comment