🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Manufacturing & Marine › Robotics / Mechatronics › Programmable Logic Controllers for Mechatronics › Lesson 6
MFG-MECH15-02 · Lesson 6 · 14 clock hours · lab

Comparison, Math, and Data-Handling Instructions

Objective. Students will use comparison (EQU, GRT, LES, GEQ) and math (ADD, SUB, MUL, DIV, MOV, CPT) instructions to implement a tank-level control program that calculates fill rate and triggers alarms at setpoint thresholds.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by a licensed engineer or certified journey-level tradesperson or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Comparison, Math, and Data-Handling Instructions in PLC Programs

PLC programs do more than switch outputs on and off. In mechatronics applications — filling tanks, mixing materials, controlling conveyors — the controller must perform arithmetic, compare values to setpoints, and move data between memory locations. This lesson covers the comparison and math instructions defined in IEC 61131-3 and implemented in common industrial PLCs (such as Allen-Bradley Logix platforms, where the instruction names below apply).

Safety Before You Touch the Trainer

Before energizing any PLC trainer, review the hazards present:

Comparison Instructions

Comparison instructions examine two values and pass power (logic continuity) when the condition is true. The most common are:

| Mnemonic | Condition that passes power |

|----------|-----------------------------|

| EQU | Source A equals Source B |

| NEQ | Source A does not equal Source B |

| GRT | Source A greater than Source B |

| LES | Source A less than Source B |

| GEQ | Source A greater than or equal to Source B |

| LEQ | Source A less than or equal to Source B |

In a tank-level program, you might use GEQ to turn on a high-level alarm when the accumulated count reaches or exceeds a setpoint, and a second GEQ at a higher setpoint to close the inlet valve. The setpoint can be stored in a data tag, so the operator can change it at the HMI without editing the ladder logic — this is the concept of an indirect data reference.

Math Instructions

Math instructions read one or two source values, perform an operation, and write the result to a destination tag.

All math instructions are output instructions placed on the right side of a rung. They execute every scan when the rung is true (or unconditionally if there are no conditions on the rung).

Data Types and Overflow

Choose your tag data type carefully:

In this lab, level counts are DINT tags to prevent overflow at high accumulated values.

The Tank-Level Program Logic

The simulated tank uses a CTU (count-up counter) accumulator tag as a proxy for tank level, where each count represents one gallon. The program logic works as follows:

1. When the inlet valve output (`Inlet_Valve`) is ON, an ADD instruction increments the level tag each scan — or more realistically, the CTU increments on a timed pulse so the count rate represents a fill rate.

2. A GEQ comparison checks `Level_Tag >= High_Alarm_SP`. When true, it sets a `High_Alarm_Bit` output.

3. A second GEQ checks `Level_Tag >= Shutoff_SP`. When true, it opens (de-energizes) the inlet valve by resetting the valve output coil.

4. A drain pushbutton resets the level counter to simulate emptying the tank.

The instructor can change the setpoint values in the data table during a live run. The comparison instruction reads the setpoint tag every scan, so the program responds to the new value immediately without any change to the ladder logic. This is the power of storing setpoints in data tags rather than hard-coding constants in the instruction.

Manual Forcing

Forcing allows you to override the state of an input or output bit in software for testing. Use it carefully:

CPT Expression Syntax

A CPT expression uses standard arithmetic operators (`+`, `-`, `*`, `/`) and may include parentheses for order of operations. The PLC follows standard mathematical precedence (multiplication and division before addition and subtraction). Always verify your expression result in the online data monitor before relying on it in the program.

Connecting to PMMI and Siemens Credentials

The PLC 1 and PLC 2 knowledge areas of the PMMI Mechatronics certification include comparison and math instruction usage. The Siemens SMSCP Level 1 covers digital fundamentals and PLCs, including data handling. Mastering these instructions prepares you for both credentials.

Key terms8

EQU (Equal)A comparison instruction that passes logic continuity when Source A equals Source B; used to trigger actions at an exact setpoint value.
GEQ (Greater Than or Equal To)A comparison instruction that passes logic continuity when Source A is greater than or equal to Source B; commonly used for high-level alarms and shutoff setpoints.
CPT (Compute)A math output instruction that evaluates a complete arithmetic expression written as a formula and stores the result in a destination tag, reducing the number of rungs needed for multi-step calculations.
MOV (Move)A data-handling instruction that copies the value of a source tag into a destination tag without performing arithmetic; used to transfer or initialize data.
DINT (Double Integer)A 32-bit signed integer data type with a range of approximately ±2.1 billion; preferred for PLC counter accumulators and level tags to prevent overflow.
Indirect data referenceA programming technique in which a setpoint or parameter is stored in a named data tag rather than hard-coded as a constant, allowing operators or technicians to change the value at the HMI without editing ladder logic.
Manual forcingA software function that overrides the actual state of a PLC input or output bit for diagnostic or testing purposes; must be removed before returning the system to automatic operation.
CTU (Count-Up Counter)A PLC instruction that increments an accumulator value each time the rung transitions from false to true; used in this lab as a proxy for tank level in gallons.

Worked examples4

1. A CPT instruction contains the expression (InletFlow * ScanTime) + CurrentLevel, where InletFlow = 15, ScanTime = 2, and CurrentLevel = 340. What value is written to the destination tag?
  1. Step 1 — Multiply inside parentheses first: 15 × 2 = 30.
  2. Step 2 — Add CurrentLevel: 30 + 340 = 370.
  3. Step 3 — The destination tag receives 370.
Answer: 370
2. A GEQ comparison has Source A = Level_Tag (current value: 480) and Source B = High_Alarm_SP (value: 500). Does the rung pass power and energize the alarm output?
  1. Step 1 — Evaluate the condition: Is 480 ≥ 500?
  2. Step 2 — 480 is less than 500, so the condition is FALSE.
  3. Step 3 — The rung does not pass power; the alarm output remains OFF.
Answer: No — the rung is false and the alarm output stays OFF because 480 is less than 500.
3. A tank-level program uses an ADD instruction each scan to increment Level_Tag by an InletRate of 3 counts per scan. Starting at Level_Tag = 0, how many scans must execute before a GEQ instruction with setpoint 75 triggers the high-alarm output?
  1. Step 1 — The GEQ passes when Level_Tag ≥ 75.
  2. Step 2 — Each scan adds 3: after N scans, Level_Tag = 3 × N.
  3. Step 3 — Solve 3N ≥ 75: N ≥ 25.
  4. Step 4 — On the 25th scan, Level_Tag = 75, so the GEQ condition becomes true and the alarm energizes.
Answer: 25 scans
4. A CPT expression calculates fill rate in gallons per minute: (Counts_Per_Second * 60). If the CTU accumulates 4 counts each second (each count = 1 gallon), what is the calculated fill rate written to the destination tag?
  1. Step 1 — Identify the values: Counts_Per_Second = 4, multiplier = 60.
  2. Step 2 — Apply the expression: 4 × 60 = 240.
  3. Step 3 — The destination tag receives 240, representing 240 gallons per minute.
Answer: 240 gallons per minute
In class: Math instruction drill: students complete a worksheet of five CPT (compute) expressions using integer tags; verify each result using the PLC's online data monitor and record values in the lab log. · Tank-level simulation: students program a simulated tank using a CTU accumulator as a proxy for level (counts = gallons); ADD instruction increments level when an inlet valve output is ON; comparison instructions trigger a high-level alarm bit at a setpoint and close the inlet valve at a second setpoint; tested with manual forcing. · Alarm setpoint modification exercise: instructor changes the high-level setpoint mid-run by entering a new value in a data table; students observe the program response and document in the lab log how the comparison instruction responded, reinforcing the concept of indirect data references.
Materials: PLC programming software, PLC trainer, math worksheet, lab log, projector for instructor demo
Check: Worksheet results 100% correct (or corrected and explained); tank-level program triggers both setpoints at correct accumulated values verified by instructor during live demo; lab log complete.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Programmable Logic Controllers
1. Which comparison instruction passes logic continuity when Source A is greater than or equal to Source B?
Programmable Logic Controllers
2. A CPT instruction contains the expression (A - B) * C with A = 50, B = 10, and C = 4. What is the result written to the destination tag?
Programmable Logic Controllers
3. In the tank-level simulation, the inlet valve must close when the level reaches 600 counts. A technician hard-codes the number 600 directly into the GEQ instruction instead of using a data tag. What is the primary operational disadvantage?
Safety
4. Before using the force/override function in PLC software during a lab exercise, what must the student confirm first?
Safety
5. Which OSHA standard governs lockout/tagout procedures for the control of hazardous energy?
Programmable Logic Controllers
6. A DINT tag is preferred over an INT tag for a tank-level accumulator because:
Programmable Logic Controllers
7. The instructor changes the High_Alarm_SP tag value from 500 to 450 while the program is running. On the very next scan, the GEQ instruction comparing Level_Tag to High_Alarm_SP will:
Programmable Logic Controllers
8. Which IEC 61131-3 instruction would a technician use to copy a preset value into a timer's preset tag without performing any arithmetic?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.