Subtract Instruction in Ladder Logic

KronoTech

PLC

Ladder Logic

Basic

Counters

Timer

Arithmetic

ADD

SUB

MUL

DIV

DDV

Comparison

Functions

Trig Functions

RSLogix 5000

Structured Text

HMI

Instruments

>

SUB - Subtract

When rung conditions are true, the SUB output instruction subtracts Source B from Source A and stores the result in the destination. Source A and Source B can either be values or addresses that contain values, however Source A and Source B cannot both be constants.

Example 1

Equation: N7:10 = N7:10 - 5

Ladder Logic Solution

Source A = n7:10 = 23276, Source B = 5, Destination = N7:10 = 23271.

SUB - SLC 500 Beginners Guide

Example 2

Equation: N7:13 = N7:11 - N7:12

Ladder Logic Solution

Source A = N7:11 = 32700, Source B = N7:12 = 69 , Destination = 32767 (why..). The result is invalid since the maximum negative value in a register is -32768, therfore the result is invalid and the overflow bit is on.

SUB - SLC 500 Beginners Guide

Clearing minor error that might be generated if we have an underflow.

SUB - SLC 500 Beginners Guide

Note

  • If the destination value is < -32768 then the underflow bit S:0/1 bit will be set hence setting the minor bit error S:5/0. If this error is not cleared then it will case major error.
  • Can not program Source A and Source B as constant, at least one of them should be a variable.

Quick Links

PLC Languages

Ladder Logic
Function Block
Structure Text
SFC
Mnemonic

Ladder Logic

Basic
Counters
Timer
Arithmetic
Comparison
Functions
Trig Functions

Instruments

Switches

HMI

Advantages
Alarms
Trends

Other

Bottle Application