Now, that we know what hardware is inside the PLC, the next step will be to take a look at the software inside the PLC and how it runs. Every PLC has a scan time and a scan cycle. This is how the PLC and the software inside the PLC works. The scan cycle is the cycle of which the PLC gathers the inputs, runs your PLC program and then updates the outputs. This will take some amount of time often measured in milliseconds or ms. The amount of time it takes for the PLC to make one scan cycle is called the scan time of the PLC.

It is crucial to know about the PLC scan time and even to know how long the scan cycle is. Especially if you are working with plc timers and delays. The accuracy of the timers will often depend on the length of the scan cycle.

Beside the PLC hardware, the PLC contains some software. Some of it are pre-installed, and some of it will be your software.

PLC Firmware

First, let us divide the software inside the PLC into two parts. A little piece of software called the firmware and another piece of software called the program. The firmware is the operating system in the PLC. The firmware is responsible for running your program commands, managing communications and some other tasks. Some of the functions of the firmware is to make the microprocessor and the RAM communicate, and to make the PLC compatible with the PLC programming software. Many other tasks are handled by the firmware, and you will almost never have to worry about it. The firmware is installed by the manufacturer of the PLC.

Your PLC program

The other piece of software is actually the software that we develop for the PLC. It is the program of logic that we put inside the PLC. The program of logic that reads the inputs and sets the outputs. Before learning more about the program of logic we need to know is where in the PLC the program is placed.

Normally the program is saved in the RAM of the PLC, but as we know from the previous chapter the RAM can be a risky place to save your program. It can be risky because the RAM will be cleared when the power is off. Most PLC’s have a backup battery, that prevents the RAM from being deleted, but there is a better place to save your program more permanently – the EEPROM. The data in the EEPROM will still be there even after the power has been removed. So, the EEPROM is in most cases the optimal place for the program.

The scan time is how the PLC program works

The program of logic that we save into the PLC is the main function of the PLC. Your PLC program will decide what outputs to set with the inputs as decisions. When the PLC is powered up it will run as following:

First thing the PLC will do is to check the status of all the inputs. To be more precise, the PLC will take an image of all the inputs and save it in the RAM. Where taking an image means that the PLC will save a binary value representing the inputs. Let me explain that in detail with an example:

Let’s say we have a PLC with 8 digital inputs. When the PLC checks the input status of all the inputs when they are all low, the binary number will be 00000000. Each 0 is a representation of a digital input. If the input is low the value will be 0, and if the input is high the value will be 1. So if we connected the last input (input 8) to a power source the PLC would save the number 00000001, when checking the input status.

After the PLC has checked the status of all its inputs, the PLC will then execute the program. The logic program that we program the PLC with will now run, and as it runs the program will collect some numbers and save them temporary. You might already have guessed what these numbers are. These numbers are the output status as the logic of the program have decided. When the program has ended the PLC will update the output status. The same thing now happens as with the inputs only in reverse. The number representing the output status will now be saved as the output status in the PLC, and the status of all the outputs will be updated.

What really happens is that the temporary number decided by the PLC program representing the output status will be a binary number just like the inputs. So let’s take an example of 8 digital outputs. The number saved by the program will be 00000000 if all outputs are to be updated to low or off. If the PLC program sets the first output to high the number saved will be 10000000. So with 0 as off and 1 as on.

So, how does the PLC update the outputs? The answer to that is a special place in the memory. At a special place in the memory the microprocessor will have a number that will always represent the status of the outputs. If we save the number 10000000 in this place the first output of the PLC will be on. When the PLC program ends the temporary number will just be saved in this special location of the memory and the outputs will be updated.

These three steps are all called a scan cycle. One scan cycle is when the PLC has checked the input status, executed the program and updated the output status.

If you want some further explanation of the PLC scan time, check out this great video from Ron Beaufort:

The PLC is a fast thinker and this cycle happens within milliseconds. But it will be relevant to know about the scan cycle and especially the scan time, which is the time one scan cycle takes. When we are working with timers and other advanced functions in the PLC the scan time can be crucial. The same happens with large projects with thousands of lines of code or ladder the scan time might become an issue.

Brand specific settings – More on scan times

As a comment on this post on reddit says, the PLC scan time are completely brand and setting specific. In many cases you can set different times for the I/O cycle time and the task cycle time.

The task cycle time is equal to the second step in this article – Execute PLC program.

All these brand specific settings and further information about the different PLC scan times will be in future articles. If you are starting out, learning PLC programming, you should just care about the scan time. Reading the I/O, then executing your program and at last updating the I/O is a good fundamental understanding of how a PLC works. When you are starting out learning PLC programming, knowing about the concept of the scan cycle is a huge advantage. In the beginning, this concept will help you understand the basic concepts of PLC programming.

If you have experience with PLC programming you may know of some scan cycle settings.

Have you ever used custom scan cycle settings?

Feel free to tell me about it in the comment section below.