Download Prospectus


How do we test and debug our PLC code?

In our previous articles, we dived into PLC systems, how they work, and how we can program them to carry out tasks.  Now let’s find out how we can test and debug this programming to make sure everything runs correctly.

PLC start-up

Before we turn on our PLC system, we need to carry out some start-up and checking procedures.  

, How do we test and debug our PLC code?

These procedures are:

  1. PLC pre-start up procedures – a visual check that we should carry out before the system is switched on.  It can prevent electric shocks from loose wiring or incorrect connections causing problems.  Each PLC will have its own set of steps to go through
  2. Static input wiring check – we need to perform this with power applied to the controller and input devices.  It will verify that each input device is connected to the right input terminal and that they are working properly.
  3. Static output wiring check – now we apply power to the controller and output devices.  This check will verify that each output device is connected correctly and functioning as they should.
  4. Control program review – this is a final review of the control program, and should be done before loading the program into memory.  It verifies that the final hardcopy of the program is error free, or at least meets the original design documents.
  5. Dynamic system checkout – this will verify the logic of the control program.  It makes sure the outputs operate correctly.  It’s worth noting that this step assumes the previous 4 steps have been carried out.
, How do we test and debug our PLC code?

Preventative Maintenance

We can also carry out preventive maintenance of PLC systems.  It only includes a few basic procedures, but will greatly reduce the failure rate of system components.  It should be scheduled alongside regular machine or equipment maintenance so things are down for a minimum amount of time.  The harsher the environment the PLC system is in, the more frequently we should carry out this maintenance.

This preventative maintenance includes things such as:

  • cleaning or replacing filters installed to ensure air circulation.
  • Preventing dust and dirt build up on the PLC’s components.
  • Checking the connections to the I/O modules to ensure everything has good connections.
  • Making sure heavy, noise-generating equipment isn’t too close to the PLC.
  • Keeping any unnecessary items away from the PLC equipment.
  • Install a vibration detector where necessary to monitor high levels of vibration that could lead to loosened connections.

Debugging

Imagine we’re programming a PLC we’re not used to.  All of the functions, tools and syntax are new and different to what we normally use.  We’ll normally find errors showing up as we go through getting used to this new PLC.  So, how can we debug and correct these errors?

, How do we test and debug our PLC code?

Compile as you go

This allows us to identify errors as we go.  It can also help us build up our expertise on the new system more quickly. We should compile or build the program often, then decipher the error messages and fix the issues.

, How do we test and debug our PLC code?

Check the messages

Checking and decoding the error messages correctly relies on the environment.  We should see if there are root cause messages affecting other error conditions.  For example, in CODESYS, if we address the errors at the top of the list, this can often solve other errors lower in the list.

Check the help files and any example programs available

Some environments have a manual or help section.  Being familiar with the contents of these can help when a problem comes up.  It’s also a good reference to have an example program.  It can show us how to go about putting in a read operation that’s performed over a communications network or a simple CASE structure sequence.  Often, a vendor can provide some example code and programs.

Test the suspect function separately

This will pick up if we are using a function incorrectly.  We can break down the function, what’s input to it and if any of them are incorrect.  Ideally, the compiler will tell us what is wrong but this isn’t always the case.

Comment out sections of code and check if the error persists

If we comment out sections of code and compile systematically, we can see which section might be the root cause.  We can keep doing this until we find the exact place the error is stemming from, and fix it more easily.

Build a go to resource list

Documenting findings somewhere searchable, will save us time if we get the same types of error again.  It also can help colleagues if they come across the same issue.

Interested in our courses?

You can read more about our selection of accredited online electrical and electronic engineering courses here.

Check out individual courses pages below:

Diploma in Electrical and Electronic Engineering

Higher International Certificate in Electrical and Electronic Engineering

Diploma in Electrical Technology

Diploma in Electronics

Diploma in Renewable Energy (Electrical)

Higher International Diploma in Electrical and Electronic Engineering

Alternatively, you can view all our online engineering courses here.

Recent Posts

How can we select engineering materials?

How can we select engineering materials? In our previous article, we looked at elastic and magnetic hysteresis. In this article, we’re going to look at how we can select engineering materials.  In other articles, we have previously looked at the different materials and their properties.  However, it’s important that engineers understand how we can go […]

What is hysteresis?

What is hysteresis? In our previous article, we looked at the material modes of failure we need to be aware of in engineering. In this article we’re going to dive into elastic and magnetic hysteresis. Elastic Hysteresis Elastic hysteresis is the difference in strain of a material during loading of stress or strain, versus during […]

What are material modes of failure?

What are material modes of failure? In our previous article we looked at the properties of engineering materials. In this article,  we’re going to dive into material modes of failure and what they are. What is failure? The definition of failure is that the component is no longer fit for use or its designed purpose.  […]