5 Quick Tips to Reduce Memory Usage in Allen-Bradley PLCs

Jon Stopple
February 2, 2024

There are many ways to write PLC (programmable logic controller) code and accomplish the same task, but not all of them are ideal. In some instances, memory limitations can be a deciding factor for bumping up processor size and requiring a larger budget for the PLC. Assuming the first principle of keeping the code simple is being followed, here are a few tips that could lean out the memory requirements even more.

Safety PLC with wiring connections and Input and Output cards.
Allen-Bradley Compact GuardLogix Safety PLC.

1. Use Intermediate Tags

Each instruction takes up memory, and each instruction uses a different amount of memory. An Examine On instruction takes up 4 bytes of memory while a Copy instruction takes up 100 bytes. Sometimes, it makes sense to add an intermediate tag to represent the result of a complex set of conditions.

For example, if a complex comparison of equipment positions is needed in multiple places, it makes sense to create a Boolean bit to represent the state of the comparison. Not only does it improve readability and adaptability, but it also saves memory in the process. This concept can be applied wherever complex conditions or multiple conditions are checked for more than one instance.

2. Use Add-On Instructions

Add-On Instructions not only improve the consistency, readability, and efficiency of your code, they also reduce memory usage as more instances are used. An AOI is basically a class in programming terms. Adding an instance only requires the space needed for the tag itself. The logic memory required is basically a one-time cost created with the AOI. So, as more instances are created, memory saving continues to increase.

3. Use Subroutines

Another possibility to reduce memory usage is to utilize subroutines and call them like functions. These can drop memory usage even more than utilizing Add-On Instructions because the logic and tags are only used once. Simply pass in different parameters to the subroutine to customize the result. This saves memory if the tag instance being used is relatively large. One caveat is the added memory requirement for the instruction to call the subroutine. Overall, this can be a great way to reduce the overall amount of code in applications where an AOI doesn’t make sense.

A potential downside of subroutines is increasing troubleshooting difficulty as there is no assigned instance of the logic. It can be tricky to trace tag values within the subroutine. An upside over an AOI is online edits can be made to the subroutine. Modifying an AOI requires download to the processor.

4. Use Arrays

Arrays allow reduction in the overall amount of code required. Instead of requiring 10 instances of the same logic rungs, an array can be looped through 10 times within one instance of the rung. Savings increase as the scale or size of the array increases.

Additionally, code creation can be expedited in cases where multiple instances of the logic are still desired. Simply copy the code utilizing an array and change a number at the beginning of the routine to determine the array index.

5. Use Boolean Arrays

This isn’t a groundbreaking idea by any means and is likely common practice but is worth repeating. Each Boolean tag takes up 4 bytes. But an array of 32 Boolean tags also takes up 4 bytes. Simply use Boolean arrays instead of separate Boolean tags. This won’t save a huge amount of space but is still a tactic that can be used to reduce memory requirements. Fun fact: AOIs treat Boolean tags as an array as far as memory is concerned. This way, you can still include descriptive tag names like Start, In Progress, Complete, Error, and so on without increasing memory usage.

These are a few of the recommendations for reducing memory usage within PLC ladder logic. Obviously, the best overall tactic is to clearly identify the goal of the program and keep the code as simple as possible while maintaining complete functionality. Memory savings won’t matter if there is extra junk in the code to begin with.