Back to tutorials
PLC Instructions

PLC Programming Computational Mathematical Instructions – ADD | Addition

By
Vladimir Romanov
Table of Contents

Introduction

The ADD, also known as the Addition, is an instruction which will perform a mathematical addition of two integers or floats. Performing an addition has a lot of uses in PLC programming. In addition to the obvious, it can be creatively used to create advanced functions such as step counters, average calculations and so on. The instruction takes three operands: two which will be added and one into which the result will be stored as the instruction executes.

The ADD instruction is used all the time and is one of the most fundamental instructions of the Computational / Mathematical set. It’s something every programmer should be familiar with.

In this tutorial, we will be also looking into an example of how you can implement a step counter which will increment based on a set value when it is triggered. For the purposes of the tutorial, we will be using a timer to continuously trigger the said counter. This simple piece of logic comes up on interviews and can easily stumble an unseasoned PLC programmer.

Example & Usage of ADD

Here’s a real-world scenario of an ADD instruction:

  1. A Micrologix 1100 Allen Bradley PLC is used to control a process.
  2. In rung 0000, an ADD  instruction is used to add an integer N7:0 to a constant value and store the result in the integer N7:1.
  3. Since the value of the integer is currently 100 and the value of the constant is 56, the result is evaluated to 156.
  4. In rung 0001, an ADD  instruction is used to add an integer N7:2 to an integer N7:3 and store the result in the integer N7:4.
  5. Since the value of the integer is currently 100 and the value of the second integer is 56, the result is evaluated to 156.
  6. In rung 0002, an ADD  instruction is used to add a float F8:0 to a float F8:1 and store the result in the float F8:1.
  7. The ADD instruction is preceded by an XIC tied to B3:0/0 which will prevent the ADD to execute until it’s set to HIGH.
  8. Since the value of the float is currently 242.45 and the value of the second float is 123.123, the result is evaluated to 365.573.

Programming example in RSLogix 500:

ADDAditionPLCLadderLogicProgrammingRSLogix500Instruction
  1. In rung 0003, a TON Instruction is used to run Timer T4:0. The timer is set to a base of 1.0 and a “Preset” value of 5. Therefore, it will complete in 5 seconds total.
  2. The ADD instruction is preceded by an XIC tied to B3:0/0 which will prevent the ADD to execute until it’s set to HIGH.
  3. Once the timer is completed, as indicated by the .DN bit, an ADD instruction, as well as a RES instruction, are executed.
  4. The ADD instruction is incrementing the Integer N7:5 by the value in the integer N7:6. It’s an increment since the final value is stored in the initial one which is N7:5.

Programming example in RSLogix 500:

ADDTimerInstructionIncrementLadderLogicRSLogix5000

Outcome:

The ADD instruction is used in multiple ways in order to demonstrate its versatility. In the first three rungs, we’re exploring a basic application by using operands such as integers, floats, and constants. In every situation, the ADD instruction takes two operands, stored in “Source A” and “Source B” and stores the resulting sum in the “Dest” operand.

The final rung illustrates a simple way to create a non-binary counter. This ADD instruction will increment an operand by the value specified in the second operand. This is possible due to the fact that the “Dest” operand is the same one as the “Source A” operand.

Data Types Allowed for ADD

The ADD can be used to compare two values of identical types or mismatching types such as float and integer. These value can be INTs or FLOATs.

  • Integer – You may specify each operand to be of “Integer” type.
  • Float – You may specify each operand to be of “Float” type.

Video Tutorial

Back to tutorials

Related Tutorials

Advanced

PowerFlex 525 Parameter, Input and Output Programming Tutorial in RSLogix Studio 5000

The PowerFlex 525 series of Variable Frequency Drives from Allen Bradley is highly utilized and respected within the automation field. The drives are compact, versatile and easy to use. We’ve written an extensive tutorial on how to get started with these drives in a previous tutorial; it covers how to initialize the drive, connect it to an EtherNet/IP based PLC and how to set the right parameters. In this tutorial, we’re looking to expand on the concepts and demonstrate a way to access and utilize the multiple Input and Output options available on the drive. The reason you may want to utilize the IO is to save money on purchasing external components, integrate instrumentation into your drive and save floor space, wiring and cost. We’ve seen the need to integrate closely related sensors into a PowerFlex 525 application; this would be the right way to do it.

By
Vladimir Romanov
Advanced

Publishing MQTT Data Using Opto 22 groov EPIC PAC

MQTT is a communication protocol that has taken off in the IIoT community. It’s a light-weight, efficient protocol that works through a publisher / broker / subscriber model. It creates an easy way for field devices to communicate and retrieve data from a single location. In this article, we’ll go over MQTT and dive into an example of how you can publish data using a groov EPIC PAC and retrieve the data using a MQTT client.

By
Vladimir Romanov
Intermediate

HMI Design - Best Practices for Effective HMI Screens

HMI Design is the practice of building HMI screens that are intuitive to the end user, pleasing to the eye and are efficient to operate. As control systems within manufacturing are migrated from traditional push button designs to primarily operated from HMI displays, HMI Design has become trivial to any new installation.Although there is a wide range of HMI based systems, the basic principles of good design remain the same. Different industries may dictate different patterns of layout for their systems, but the good practices remain.

By
Vladimir Romanov