Week 6 - PLC Arithmetic Instructions (PDF)

Document Details

EncouragingSimile

Uploaded by EncouragingSimile

Centennial College

Tags

PLC programming PLC arithmetic PLC instructions automation

Summary

This document covers PLC (Programmable Logic Controller) arithmetic instructions including comparison and math functions.  It describes different arithmetic operations such as addition, subtraction, multiplication, and division, along with the influence of different status bits. The document is part of a course for students studying energy system engineering.

Full Transcript

ESET 225 PLC/Pneumatic Interfacing Agenda WEEK # 6 PLC Arithmetic Instructions 1 Manipulating Numbers Many modern PLC applications require capabilities biliti b beyond d mere contact t t logic, l i timers and counters. Process control, in particular, deals with many analog variables. Even with c...

ESET 225 PLC/Pneumatic Interfacing Agenda WEEK # 6 PLC Arithmetic Instructions 1 Manipulating Numbers Many modern PLC applications require capabilities biliti b beyond d mere contact t t logic, l i timers and counters. Process control, in particular, deals with many analog variables. Even with counters, counters it may be necessary to compare current value with a fixed value. 2 Energy System Engineering 1 Comparison Instructions  These instructions compare the data stored in two or more words and make decisions based on the program instructions. instructions  Used to test pairs of values for logical conditions.  In each case, source A Source B can be an address or a constant. EQU NEQ LES LEQ GRT GEQ A equal to B? A not equal to B? A less than B? A less than or equal to B? A greater than B? A greater than or equal to B? 3 Comparison Instructions Where to find EQU When source A is equal to source B,, the instruction is logically true and PL1 is switched ON. When source A is not equal to source B, the instruction is logically false and PL1 is switched OFF. Energy System Engineering 4 2 Comparison Instructions NEQ Use the NEQ Q instruction to test whether two values are not equal. If source A and source B are not equal, the instruction is logically true. If the two values are equal, the instruction is logically false. 5 Comparison Instructions LES Use the LES instruction to test whether one value (source A) is less than another (source B). If source A is i less l th than th value the l att source B, B the th instruction is logically true. If the value at source A is greater than or equal to the value at source B, the instruction is logically false. 6 Energy System Engineering 3 2/16/2012 Comparison Instructions LEQ Use the LEQ instruction to test whether one value (source A)) is less than or equal q to another ((source B). ) If the value at source A is less than or equal to the value at source B, the instruction is logically true. If the value at source A is greater than the value at source B, the instruction is logically false. 7 Comparison Instructions GRT Use the GRT instruction to test whether one value (source A) is greater than another (source B). If the value at source A is greater than the value at source B, the instruction is logically true. If the value at source A is less than or equal to the value at source B, the instruction is logically false. 8 Energy System Engineering 4 Comparison Instructions GEQ Use the GEQ instruction to test whether one value (source A) is greater than or equal to another (source B). If the value at source A is greater than or equal to the value at source B, the instruction is logically true. If the value at source A is less than the value at source B, the instruction is logically false. 9 Comparison Instructions LIM Use the LIM instruction to test for values within or outside a specified range, depending on how you set the limits. Range is –32,768 to 32,767 Energy System Engineering 10 5 Math Instructions Math instructions are used to compute an arithmetic function on two values. Integer and Floating point values can be used, but usually integer values returned. May cause changes to Arithmetic Status Bits. Some instructions affect Math Register, S:13 and S:14 11 Arithmetic Status bit Bit Name Action S:0/0 Carry (C) Set if carry is generated, otherwise Clear. S:0/1 Overflow (V) Indicates result doesn't fit in destination S:0/2 Zero (Z) Indicates a 0 value after instruction executes S:0/3 Sign g ((S)) Indicates a negative g value results from instruction 12 Energy System Engineering 6 Math Functions  Performs the function using data in Source A and Source B. Result stored in Destination Either A or B can be a constant, constant but not both. both Destination must be an address ADD A+B SUB MUL DIV SQR XPY A-B AxB A/B A2 (No B value) AB 13 Math Instructions ADD Use the ADD instruction to add one value (source A) to another th value l ( (source B) and d place l th resultlt in the i the th destination. 14 Energy System Engineering 7 Math Instructions SUB Use the SUB instruction to subtract one value (source B) from another (source A) and place the result in the destination. 15 Math Instructions MUL Use the MUL instruction to multiply one value (source A) by b another th (source ( B) and d place l th resultlt in the i the th destination. 16 Energy System Engineering 8 Math Instructions DIV Use the DIV instruction to divide one value (source A) b another by th (source ( B) B). 17 DIV and the Arithmetic Registers The rounded quotient is placed in the destination. The unrounded quotient is placed in S:14 The remainder is placed in S:13 The overflow bit (S:0/1) will be Set if division by 0 is attempted. 18 Energy System Engineering 9 Other Math Functions CLR – Set destination Word (16 bits) to 0 ABS –Calculate absolute value of source CPT –Calculate result of mathematical instruction – may have long execution time. Trigonometry and log functions are also available. 19 Other Math Functions CLR Use the CLR instruction to set the destination value of a word d to t zero. 20 Energy System Engineering 10 Other Math Functions CPT The CPT instruction performs copy, arithmetic, logical, and conversion operations. operations You define the operation in the Expression and the result is written in the Destination. 21 Data Handling Instructions These instructions are used to convert information manipulate information, manip late data and perform logic operations. Conversions include to and from BCD, degrees to or from radians, and encode or decode 16 bit to 4 bit (binary to hex) 22 Energy System Engineering 11 Moving Data The move (MOV) instruction is used to store a copy of a source word or constant into a destination address. 23 Sample - MOV When I:1/5 comes true,, the current value of N7:1 is replaced with 123 24 Energy System Engineering 12 Logic Instructions AND OR XOR NOT NEG bit-by-bit logical AND bit-by-bit bit by bit logical OR bit-by-bit logical exclusive OR bit-by-bit logical NOT change sign of source and place in destination in two two's s complement form 25 Summary Compare instructions can be very useful with A l sensors. Analog Math and data instructions provide a powerful tool for programmers. Using an OSR in front of a Math or Data instruction can prevent multiple executions of the same instruction. 26 Energy System Engineering 13

Use Quizgecko on...
Browser
Browser