9 -1 0 A RITHMETIC I NSTRUCTIONS

9 -1 0 A RITHMETIC I NSTRUCTIONS

Arithmetic instructions in a PLC include the basic four operations of addition, subtraction, multiplication, and division. In addition to these four math functions, large PLCs may also include square root operations. Table 9-7 lists these typical arithmetic instructions and their symbols.

Table 9-7. Arithmetic instructions.

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

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

Like other instructions, arithmetic instructions may be in either the basic ladder format or the functional block format; however, operation in either format is essentially the same. Figure 9-58 illustrates these formats. Most arithmetic instructions require three reference registers, which define the two operand registers and the destination register of the operation. Some instruc- tions, such as multiplication and division, may use four registers. Most arithmetic operations in a PLC require only single-precision arithmetic, meaning that the values of the operands and the result can be held in one register each. If operations dealing with larger numbers are required, a PLC may offer double-precision arithmetic instructions. Double precision means that the system uses double the number of registers to hold the operands and result, because it must store larger numbers. For example, a double-precision addition instruction would use a total of six registers, two for each operand and two for the result.

Figure 9-58. (a) Coil, (b) contact, and (c) block format arithmetic instructions.

As discussed earlier, a register can hold a maximum value of 65,535 in 16 bits (all 1s) if there is no sign bit. If the most significant bit is used as the sign bit, then a register may hold a maximum value of +32,767 and a minimum value of –37,767. If the result value of the operation is larger than the value

a register can hold, an overflow condition will exist, and the instruction will turn ON an overflow bit or output. The numerical format used in math operations will vary depending on the PLC but is usually three, four, or five digits (BCD or binary). Note that in single-precision BCD, the maximum register value is 9999 (unsigned) or ± 999 (signed).

In the following discussion, we will present arithmetic instructions in both ladder and block formats to familiarize you with the differences between them. Note that the ladder format may require other ladder data transfer

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

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

instructions to obtain the arithmetic operands. In functional block format, some manufacturers offer the ability to “cascade” block functions (see Figure 9-59). Cascading is very useful when dealing with multiple arithmetic operations, since one instruction will activate the next one when finished. Other manufacturers allow arithmetic operations to be performed in block form (see Figure 9-60); that is, using blocks of several contiguous registers as the operands and storing the results in another block of registers.

Note: K33 in the division block indicates a constant of 33. Figure 9-59. “Cascading” allows several functional block arithmetic operations to be

performed sequentially.

ADD

Length = 4 Reg 1000

+ Reg 1200 = Reg 1400

Note: The contents of registers 1000, 1001, 1002, and 1003 will be added to registers 1200, 1201, 1202, and 1203. The results will be stored in registers 1400, 1401, 1402, and 1403.

Figure 9-60. Arithmetic operations performed in block form.

ADD