Maximizing PLC Scan Rate

Coot

Member
Join Date
Jan 2015
Location
B.C.
Posts
3
Hi: new to plc's. I ran across a question the other day that I would like to find the answer to.
When a plc runs a scan, in order to maximize it's scan rate does it do it
- a single line at a time or can it use multiple lines at a time?
How does a plc obtain maximum scan capabilities?
Thanks,
Coot
 
The PLC executes one line at a time.
Optimizing PLC code is a big topic. Often there is a trade off between speed and simplicity and being able to understand what was done years later.

Machine control applications can often be divided into states. It is possible to make the PLC execute only the code in the current state instead of all states. The Siemens JL instruction is very handy for making efficient state machines.
 
PLCs also differ in how rungs are processed. In an A-B PLC-5 rungs are scanned left to right, top to bottom.

Assume a rung of several series contacts and an output: The first FALSE contact found will make the entire rung FALSE. So, if there are five contacts and the first is found FALSE the remaining contacts become irrelevant and the processor skips to the output element. If only one contact is FALSE and it's the last in the series the same thing happens at the output but the processor spent some time checking the other four elements. In order to save some scan time (µs) you can arrange the elements so that the ones most likely to be FALSE are on the left side of the rung.

Same concept applies to parallel branches. The first TRUE branch makes the rung true.
 
There are MANY things you can do to improve scan time:

BIG GAINS
1) On any PLC that has set cycle times instead of/in addition to a continuous cycle, you can run unimportant stuff slowly so your high speed stuff can run faster. Values for HMI display don't need to update every 10ms and File read/write can take it's time too.

2) Don't run code at all that doesn't need to be running (init code, one time calculations, etc). Properly done state machines are a big help in this department (using CASE in ST or Jumps and Labels in ladder). You can't just check a state variable on each rung to get speed gains.

SMALL GAINS
3) Program using Structured Text or ANSI C (if supported) instead of Ladder. Instruction List is actually the fastest IEC language since it is essentially assembly, but you have to use more instructions to do what you want, so it usually ends up slower than ST. ST is the second fastest and then ANSI C tends to be faster than any IEC language (and is available on a lot of PLCs these days). C++ actually tends to be slower than ANSI C.

4) Avoid type conversions to/from floating point. Modern CPUs can do floating point calculations as fast as integer calculations, but they are completely different parts of the chip, so converting from INT to REAL takes longer than just keeping it all as REAL.

5) Combine/Remove logic checks using BOOLEAN simplification.

6) Use supper optimized bit operations instead of math to squeeze out every last picosecond (this is when code starts getting unreadable, so you better actually need this kind of optimization).

6b) Multiply is faster than divide when it comes to math operations.
 
Last edited:
Thanks for all the replies guys. I guess when I read the question, with my limited knowledge, I figured that there would be a general answer. I should know by now that something as complex as plc's and programming is anything but general.
From the answers provided I have a better understanding of how priorities are allocated within the system and how there may a great degree of variances involved.
This isn't my field but it sure is interesting and I appreciate the knowledge gained.
Take care,
Coot(y)
 
Maximize PLC Scan Rate

Thanks Shooter:
I guess when I read the original question it gave a couple of options. One being scan one line at a time or scan multiple lines t a time. With my limited knowledge of plc's and all the rest I didn't know if you can actually scan more than one line at a time. Therefore I turned to the experts who could give me a better picture of how it works.
Strangely enough the question never mentioned anything about memory allocation as did some of the guys above. I realized that the field of plc's is just a little more complicated than what the question was getting at.
I hate being curious, on one hand you learn a lot of things but on the other you spend a lot of time searching. I guess that's what it's all about.
Thanks for reply and take care,
Coot
 
I watched an impressive presentation on how using single integers are much slower to work with than using double ints because of the conversions that have to be made....I think it would be some serious code before it would make a significant impact. At RAOTM they focused on coms and cycle times.
 
I watched an impressive presentation on how using single integers are much slower to work with than using double ints because of the conversions that have to be made....I think it would be some serious code before it would make a significant impact. At RAOTM they focused on coms and cycle times.

JasonSelf, How long ago was this presentation and do you recall which PLC was used? RA tech support mentioned to me recently that this was no longer an issue with newer (L7x series) processors, but I'm still skeptical. Thanks in advance.
 
In my opinion, there are essentially two ways to optimize code speed:

1) Make individual pieces of code faster

This typically requires details of how the CPU itself thinks, and that tends to vary between different vendors, as others have said. You need to consider exactly what you are doing, and what the requirements are, and if there is perhaps another way to accomplish the same task. Something that optimizes code in one situation may make things worse in another.

2) change how often your code is called

Essentially, the principle here is only execute code as often as you need to. Only call your startup routine once. update your HMI only as fast as required. Realistically, 2s or more is fine for most things. Only update your inputs/outputs as often as your process can realistically handle. If you are sorting a list, you can often sort one item each scan, instead of running the whole thing at once. In general, Execute high priority sections of code more often than low priority sections of code. Many PLC's have built-in ways to help you prioritize different sections of code or equipment.


However, something to keep in mind is that there are many things you can optimize code for, depending on what you need. You can optimize for minimum memory usage, optimize for process performance. I think something that many people in this forum would advocate is to optimize for code readability.

Something else to keep in mind is that PLC hardware on the market these days have orders of magnitude more memory and speed than older generations (and at a lower price), so optimizing for speed is often far less important than it could be. It will usually take considerably more engineering time to optimize code than it would take in HW cost to just buy a faster PLC. I don't want to imply that HW cost is negligible, but I often see projects where rounding the CPU up to the next bigger one would have cost a small amount up front, and would have saved considerable money down the road.
 
I watched an impressive presentation on how using single integers are much slower to work with than using double ints because of the conversions that have to be made....

That is very platform specific (might only be a Rockwell thing). This is not a thing on the vast majority of platforms.
 
A lot depends on the operands and the destination. If the operands and destination are all the same type then there is no need for conversion.
Converting an INT to a DINT takes one clock cycle on a modern CPU. That is not a big delay in relative terms. Fetching and storing data is the current bottleneck.
 
A lot depends on the operands and the destination. If the operands and destination are all the same type then there is no need for conversion.
Converting an INT to a DINT takes one clock cycle on a modern CPU. That is not a big delay in relative terms. Fetching and storing data is the current bottleneck.

The Allen-Bradley Logix5000 series of processors have 32-bit architecture CPUs, and the O/S has been optimised for 32-bit manipulation. They will convert everything to 32-bit integers to perform any operation, even if all the operands of the instruction are all of the same non-32 "type". This conversion is of course unnecessary if the operands are all 32-bit DINTs.

There is nothing to be gained, and a lot to be lost, by using SINT or INT data-types in Logix5000. The only reason they are there is for compatibility with older or other processors (eg. data exchange by messaging), i.e. use DINTs for everything, unless you absolutely have to manipulate another data-type..
 
Last edited:
That is true and it is a very odd way for Rockwell to have done things. They are running VxWorks which doesn't do this inherently, and I'm wondering how forcing up conversion to 32bit optimizes 32bit operations. I'm guessing it is because of the CPU they are using, and by forcing up conversion they can get better performance from it, but I'd need a Rockwell designer to weigh in to know for sure.
 
CapinWinky - Logix5000 cpu's are 32-bit machines, and the macro code was written specifically to work with 32-bit integers.

VxWorks, as I read it, is a 32-bit (or later a 64-bit) O/S kernal, so I don't see the need for any "up-conversion" if using 32-bit integers exclusively in the application.

Conversely, using anything other than 32-bit integers imposes a conversion process....
 

Similar Topics

The project I'm currently working on has a GUI running on a PC taking input from a pair of joysticks, along with some touchscreen functionality...
Replies
1
Views
1,914
the conveyor can stop because of a safety sensor or safety switch. And also it can stop because of an object jam detector sensor. If the conveyor...
Replies
4
Views
77
Good Day to all of you, this is my first post, i will try to explain as best as possible, english is not my natural language. I am performing an...
Replies
0
Views
28
Hi All, Someone at work has put a PLC system on my desk, that's just been taken off an idle production line. He said "It's an S7 PLC. We don't...
Replies
10
Views
175
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
52
Back
Top Bottom