D AT A C O M PA R I S O N S

D AT A C O M PA R I S O N S

Data comparison (CMP) instructions, as the name implies, compare the values stored in two registers. These instructions are useful when checking for a proper range of values in the control or data entry section of the application program. In some controllers, data compariso instructions are expressed in the basic ladder format, while in other controllers, they are block instructions. In both formats, they provide three basic data comparisons: compare equal to, compare greater than, and compare less than. Based on the results of these comparisons, the processor can turn outputs ON or OFF and perform other operations.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

( P u r p o s e : T o p r o v i d e m u l it b ti , m u l it r e g i s t e r o p e r a it o n s i n a P L C )

b i t i n a m e m o r y l o c a t i o n Table 9-8. Data manipulation instructions.

Comparison instructions that use the basic ladder format operate in a manner similar to arithmetic instructions (see Figure 9-77). If the rung has continuity, the instruction performs a comparison; if the comparison is TRUE, the instruction passes continuity to the output coil. Typical comparison instruc-

CMP> Reg 502

If contact 10 closes, the contents of register 600 are compared to the contents of register 501; if they are equal, coil 100 is turned ON. If contact 11 closes, the contents of register 601 are compared to the contents of register 502; if they are greater than or equal to register 502, output 101 is turned ON.

Figure 9-77. Ladder format comparisons.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

tions are greater than (>), less than (<), and equal to (=), along with combinations of these such as less than or equal to ( ≤ ), greater than or equal to ( ≥ ), and not equal to ( ≠ ). A GET instruction accesses the first register to be compared to the comparison (CMP) register. Note that all ladder conditions are programmed before the GET and CMP instructions.

The compare functional block, shown in Figure 9-78a, compares the contents of two registers, register 2000 and register 2001, for a specific comparison, in this case, equal to. The block instruction energizes output coil 100 when the comparison occurs, and it energizes output coil 101 if the comparison has been satisfied. As shown in Figure 9-78b, some PLCs may also have one comparison block, which has several outputs, that performs multiple compare functions at the same time. This type of comparison block compares the data in the registers and then turns ON the output corresponding to the outcome of the comparison (i.e., less than, greater than, equal to).

Reg 1000 CMP=

Note: Other comparision functional

block instructions include

CMP<

CMP>, CMP ≥ , CMP<, CMP ≤ , and CMP ≠ .

(a)

(b)

Figure 9-78. (a) Single-comparison and (b) multicomparison functional blocks.

Some controllers offer another comparison option that uses another register to perform a limit (LIM) instruction. This instruction compares the values in

three registers to determine if the value in the middle register is between the other two register values. For example, the limit functional block shown in Figure 9-79 compares the contents of registers 1100, 1200, and 1300 to determine whether register 1200 is less than or equal to register 10 and

Done/Enable

Ouput is ON if condition is satisfied (Reg 10 ≥ Reg 1200 ≥ Reg 1300)

Figure 9-79. Comparison block using a limit instruction.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

whether register 1200 is greater than or equal to register 1300 (i.e., R1100 ≥ R1200 ≥ R1300). If the comparison is TRUE, the limit instruction energizes the comparison-satisfied output. The done/enable output is ON whenever the instruction is enabled.

Some controllers that do not have compare block capabilities can perform a comparison of two registers using a subtraction block (see Section 9-10). In this case, three output coils signal whether the result of the subtraction is positive (greater than), equal (equal to), or negative (less than).

E X AM PLE 9 -9

Figure 9-80 shows a section of the program from Example 9-8 in which an ADD instruction was used to keep track of the two ingredients being poured into a reactor tank. The first two ladder rungs open the valves for ingredients A and B, allowing them to be poured into the tank once the Start Adding Ingredients command is ON (input 10). Imple- ment an instruction block that ensures that the valves close when ingredient A reaches 500 gallons and ingredient B reaches 750 gallons.

Start Adding

Ingredient 1

Ingredient 2

Ingredients Valve A 10 200

Flow A

Flow B

Reg 1000

Reg 1001

Start Adding Ingredients

Valve B 10 201

ADD Reg 1000

Reg 1001 = Reg 2000

Figure 9-80. Mixing application and its corresponding ladder program.

S OLU T I ON

Figure 9-81 illustrates the use of two compare instructions that detect the target ingredient amounts. The outputs of these compare instruc- tions are used to interlock and break continuity to each of the valve’s circuits. Note that the values of the ingredient flows (the contents of registers 1000 and 1001) are compared with two constants (K). Also, note that the comparison made is greater than or equal to ( ≥ ) to avoid missing the compare (equal) because of a minuscule movement in the analog input reading.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

Start Adding

Ingredients

Stop A

Valve A

Start Adding

Ingredients

Stop B

Valve B

Start Adding

CMP Satisfied

Start Adding

(Ingredient A)

CMP Satisfied (Ingredient B)

Figure 9-81. Solution to Example 9-9.