Back to tutorials
PLC Instructions

PLC Programming Computational Mathematical Instructions – MOD | Modulo

Vladimir Romanov
Table of Contents


The MOD, also known as the modulo, is an instruction which allows the user to calculate the remainder produced by a division of two integers. This instruction is not frequently used in ladder logic programming but is very useful for calculating the remainder of a ratio, production excess, and several other parameters. The instruction takes three registers as operands. The first two are the dividend and the divisor. The result is stored in this third register which is labeled as the destination.

This instruction can be found in situations which require one to find the leftovers of a batch, how the performance of a piece of machinery is or any other situation which relies on a notion of a remainder.

Example & Usage of MOD

Here’s a real-world scenario of a MOD instruction:

  1. A CompactLogix L24ER Allen Bradley PLC is used to control a process.
  2. In rung 0, a MOD  instruction is used to compute the modulo of an integer System_DINT[0] and System_DINT[1] and store the result in the integer System_DINT[2].
  3. Since the value of the first double integer is set to 200 and the second one to 43, the modulo evaluates to 26. In other words, 200 / 43 = 4 with a remainder of 26.
  4. In rung 1, a MOD  instruction is used to compute the modulo of an integer System_REAL and System_REAL and store the result in the float System_REAL[2].
  5. Since the value of the first double integer is set to 200.22 and the second one to 10, the modulo evaluates to 0.22. In other words, 200.22 / 10 = 20 with a remainder of 0.22.
  6. In rung 2, a MOD  instruction is used to compute the modulo of a system which calculates the remainder of a production run. “Source A” is set to the total number of cases produced while “Source B” has the count of products per case. By calculating the modulo, we can figure out if we’ve filled all cases or we have leftover product.

Programming example in Studio 5000:

MOD Modulo Instruction RSLogix 500 5000 Studio Tutorial Ladder Logix Programming


The MOD instruction will compute the remainder of a division of two integers or floats. In the first two examples, we’re calculating two remainders which evaluate to 28 and 0.22 respectively. These calculations can be confirmed through a simple calculator. The last rung is used to figure out if we have any leftover product. A simple example would be the production if 1023 bottle of beer while each case holds 25 bottles. Simple math allows us to evaluate a modulo of 23 which should be utilized to complete the run.

The MOD instruction is not something you’d see on a regular basis in ladder logic but can be very useful in niche situations.

Data Types Allowed for MOD

The MOD 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


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.

Vladimir Romanov

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.

Vladimir Romanov

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.

Vladimir Romanov