AH500 Motion Control Module Manual Explanation D : Device in which the two’s complement of the value in the device is stored The instructions can be used to convert a negative binary value into an absolute value. Generally, the pulse instructions NEGP and DNEGP are used. Example 1 When X0.0 is turned from OFF to ON, all the bits in D0 are inverted (0 becomes 1, and 1 becomes 0), 1 is added to the result, and the final value is stored in the original register D10. X0.0 Getting the aboluste value of a negative number 1. When bit 15 in D0 is 1, M0 is ON. (The value in D0 is a negative value.) 2.
When M0 is ON, the instruction NEG is used to take the two’s complement of the negative value in D0. (The corresponding positive value is gotten.) M1000 Example 2 M0 Getting the absolute value of the difference between two values Suppose X0.0 is ON. 1. When the value in D0 is greater than that in D2, M0 is ON. 2. When the value in D0 is equal to that in D2, M1 is ON. 3. When the value in D0 is less than that in D2, M2 is ON. 4. The value in D4 is a positive value.
Example 3 5-48 API Instruction code Operand Function Taking the two’s 29 D NEG P D complement of a number Device Xn.n Yn.n M S K 16# F KnM KnS D W T C V Z D Pulse instruction 16-bit instruction (3 steps) 32-bit instruction ( 3 steps) .0 NEGP D10 00 BON D0 M0 K15 NEGP D0 CMP D0 D2 M0 M0 SUB D0 D2 D4 M1 M2 SUB D2 D0 D4 CMP D0 D2 M0 SUB D0 D2 D4 SUB D2 D0 D4