How to Use the SUM Instruction in Mitsubishi PLCs
18 Mar


Mitsubishi's SUM instruction, also known as the (D)SUM(P) instruction, is utilized for counting the number of 1s in specified components within a PLC (Programmable Logic Controller). When the input X0 is active, the SUM instruction is executed, sending the count of 1s from the source operand D0 to the destination operand D2. If there are no 1s in D0, the zero flag M8020 is set to 1.

Here are some considerations when using the SUM instruction:
The source operand can be of any data type, while the destination operand can be KnY, KnM, KnS, T, C, D, V, or Z.
For 16-bit operations, it takes up 5 program steps, whereas for 32-bit operations, it occupies 9 program steps.
It's important to note that the count of 1s is transmitted, not the actual 1s themselves. Beginners might mistakenly assume that the number of 1s in the source operand corresponds directly to the number of 1s in the destination operand. However, what is transmitted is the count of 1s in the source operand. For instance, if the source operand k1x0 has three bits (x0, x1, x2) set to 1, then the value "3" is transmitted to the destination operand K1M0. As a result, M0 and M1 are set to ON, indicating that the destination operand now contains two 1s.