Most PLCs have arithmetic function capabilities. Math
Instructions, like data manipulation instructions, enable the programmable controller to take on more of the qualities of a conventional computer. The basic four mathematical functions performed by PLCs are: Addition – the capability to add one piece of data to another. Subtraction – the capability to subtract one piece of data from another. Multiplication – the capability to multiply one piece of data by another. Division – the capability to divide one piece of data by another. Math Instruction commands: CPT (Compute) – evaluates an expression and stores the result in the destination. ADD (Add) – adds source A to source B and stores the result in the destination. SUB (Subtract) – subtracts source B from source A and stores the result in the destination. MUL (Multiply) – multiplies source A by source B and stores the result in the destination. (Divide) – divides source A by source B and stores the result in the DIV math register. SQR (Square Root) – calculates the square root of the source and places the integer result in the destination. NEG (Negate) – changes the sign of the source and places it in the destination. TOD (To BCD) – converts a 16-bit integer source value to BCD and stores it in the math register or the destination. FRD (From BCD) – converts a BCD value in the math register or the source to an integer and stores it in the destination. ADDITION INSTRUCTION (Add) Most math instructions take two input values, perform the specified arithmetic function and output the result to an assigned memory location. The ADD Instruction performs the addition of two values stored in the referenced memory locations. Example: • The value stored at the source A address, N7:0 (25), is added to the value stored at the source B address, N7:1 (50). • The answer (75) is stored at the destination address N7:2. • Source A and Source B can be either values or addresses that contain values, but A and B cannot both be constants. Make a PLC Ladder Diagram • Source A of the ADD Instruction is addressed to store the accumulated value of counter C:0. • Source B of the ADD Instruction is addressed to store the accumulated value of counter C:1. • The value at Source A is added to the value at Source B and the result (answer) is stored at destination address N:0. SUBTRACTION INSTRUCTION (Subtract) The SUB (subtract) instruction is an output instruction that subtracts one value from another and stores the result in the destination address. Example: • The value stored at the Source B address, N7:05 (322), is subtracted form the value stored at the Source A address, N7:10 (520). • The answer (198) is stored at the destination address, N7:20. MULTIPLICATION INSTRUCTION (Multiply) The multiply (MUL) instruction is an output instruction that multiplies two values and stores the result in the destination address. Example: • The value stored in Source A, address N7:1 (123), is then multiplied by the value stored in Source B, address N7:2 (61). • The product (7503) is placed into destination word N7:3. DIVISION INSTRUCTION (Divide) The divide (DIV) instruction divides the value in Source A by the value in Source B and stores the result in the destination and math register. Example • The value stored in Source A, address N7:0 (120), is then divided by the value stored in Source B, address N7:1 (4) • The answer, 30, is placed in the destination address N7:5. OTHER WORD-LEVEL MATH INSTRUCTIONS SQUARE ROOT INSTRUCTION (SQR) NEGATE (NEG) EQUAL (EQU) NOT EQUAL (NEQ) LESS THAN (LES) LESS THAN OR EQUAL (LEQ) GREATER THAN (GRT) GREATER THAN OR EQUAL (GEQ) Make a PLC Ladder Diagram • Source A of the ADD Instruction is addressed to store the accumulated value of counter C:0. • Source B of the ADD Instruction is addressed to store the accumulated value of counter C:1. • The value at Source A is added to the value at Source B and the result (answer) is stored at destination address N:0. • Source A of the GEQ (greater than or equal) instruction is addressed to store the value of the destination address N:0 • Source B of the GEQ instruction contains the constant value of 150. Activity A classroom has a capacity of maximum 150 students. There are two doors, one for Entry and the other for Exit. When number of students in the classroom is less than 150, Entry door has a Green light on it which remains ON. When number of students in the classroom is 150 or more than that, Red light goes ON turning OFF the Green light which indicates that the classroom has reached its maximum capacity and is full. SAMARTMEYT