PLC Programming Debugging: Breakpoints in CODESYS

Discover the power of breakpoints in PLC programming.
Breakpoints in CODESYS - thumbnail
Listen to this article

Hello and welcome back to another article from RealPars, the world's largest online learning platform for cutting-edge industrial technologies.

In today’s article, we are going to learn about Breakpoints in CODESYS.

Breakpoints are a powerful but underutilized tool for debugging PLC programs. In this article, I will show you how you can use breakpoints in CODESYS to debug difficult problems.

This article covers the process of debugging an existing CODESYS application, if you want to learn more about developing applications with CODESYS, then I suggest you check out our course, CODESYS 1: Introduction to PLC Programming which explains how to write and test your first PLC program with CODESYS.

Before we dive into how we use breakpoints, I will quickly explain what breakpoints are.

In programming, a breakpoint is a defined point in a program where the code will halt execution.

Breakpoints in CODESYS

In CODESYS, a breakpoint can be set on any box, rung, or line of code in a project.

When the breakpoint is activated, the application is halted. This gives you the chance to inspect the value of variables and the call stack at a particular moment of application execution.

After a breakpoint has been activated, you can resume the execution of your application as normal or you can single step through the application to continue debugging.

Now that we know what a breakpoint is, let’s see how we can use breakpoints in CODESYS.

Use a Breakpoint

Throughout this article, I will show you how to work with breakpoints using an example CODESYS project. In this project, we scale an analog input to a temperature in degrees Celsius and then convert that value to a temperature in Fahrenheit using the formula shown here.

Convert degrees Celsius to Fahrenheit

Let’s start by adding a breakpoint to the first Network in the program.

To add a breakpoint, you can right-click on the left edge of the network and select Toggle Breakpoint or select the network and use the keyboard shortcut F9 while logged in to the PLC.

Adding a breakpoint in CODESYS

All of the breakpoints that have been added to a CODESYS project can be viewed in the Breakpoint Window. The Breakpoint Window can be opened from the View menu as shown here.

In the Breakpoint Window, you can see all of the Breakpoints that have been added to the project.

 CODESYS Breakpoint Window

You can double-click on any of the Breakpoints listed here to go to the location in the project where the breakpoint is installed.

Now that we have installed a breakpoint, let’s run our application and see how it behaves.

Breakpoints in action

When you start running the application from the Debug menu, the breakpoint is immediately activated and execution is halted.

You can see that the breakpoint is active because there is a Yellow Arrow inside the breakpoint symbol and the application status has been updated to HALT ON BP in the status bar at the bottom of the window.

HALT ON BP

Note that this network hasn’t been executed yet - the yellow arrow indicates that it is the next line to execute.

I modify the value of rTempInput to 10 and execute the rung using the Step Over command in the Debug menu or the keyboard shortcut F10 as shown here.

Step Over command in CODESYS

As I continue to step through the application, I see that the value of the variable rConversionFactor is 1. This is not correct - the result of 9 divided by five should be 1.8.

Step through the application in CODESYS

Single-stepping through the application like this makes it easy to spot where the application’s logic is not working as expected and correct it.

In this case, I correct the logic by updating the inputs of the DIV block to 9.0 and 5.0 so that the result is a REAL value.

Updating the inputs of the DIV block

After downloading this change, I can step through the application again and verify that the calculation is working correctly.

Verifying the program

Wrap-Up

In this article, you got a quick introduction to Breakpoints in CODESYS. Breakpoints are powerful debugging tools that every PLC programmer should leverage to verify PLC logic and calculations.

In this article, we barely scratched the surface of the power of Breakpoints in CODESYS.

CODESYS offers many advanced options to configure breakpoints such as conditional breakpoints which only activate when certain conditions are met, and execution points which allow you to write messages to a log file without halting the application when certain conditions are met.

Keep an eye out for our course, CODESYS Debugging Techniques for Controls Engineers which will be launched soon and will be available to all of our Pro members.

If you are interested in becoming a Pro member, check out this link to learn more about all of the great benefits that you can get from a RealPars Pro membership.

Do you use breakpoints in your CODESYS applications? Let us know in the comments what you use them for.

Join the Top 1% of Automation Engineers

Start Your 7-day Free Trial

Learn from Industry Experts

Start your learning journey today!
With a 7-day trial, then 25/month
Start Learning For Free