Pré-visualização | Página 34 de 50
20mA 32,764 10V 0 0V (Scaled Max.) (Scaled Min.) (Shifted Input Min.) (Shifted Input Max.) Calculating the Shifted Linear Relationship Use the following equations to calculate the scaled units: Scaled value = (input value x rate) + offset Rate = (scaled max. – scaled min.) / (input max. – input min.) (32,764 − 0) / (13,107 − 0) = 2.4997 (or 24,997/10000) Offset = scaled min. – (input min. x rate) 0 – (0 × 2.4997) = 0 PrefaceInstruction Set Reference Manual 3–22 In this example, the SCL instruction is entered in the ladder logic program as follows: SCALE Source N7:0 Rate [/10000] 24997 Offset 0 Dest O:2.0 SUBTRACT Source A I:1.0 Source B 3277 Dest N7:0 Analog Input Analog Output Apply the Shift Scale Shifted Analog Value SUB SCL Math Instructions 3–23 Application Example 3 – Convert Voltage Input to Percent (MicroLogix) The following example takes a 0V to 10V analog input from a MicroLogix 1000 analog controller and scales the raw input data to a value between 0 and 100%. The input value range is 0V to 10V which corresponds to 0 to 31,207 counts. The scaled value range is 0 to 100%. Scaled Value (percent) Input Value 0V 31,207 10V 100 0 (Scaled Max.) (Scaled Min.) (Input Min.) (Input Max.) 0 Calculating the Linear Relationship Use the following equations to calculate the scaled units: Scaled value = (input value x rate) + offset Rate = (scaled max. – scaled min.) / (input max. – input min.) = (100 – 0) / (31,207 – 0) = .00320 (or 320/10000) Offset = scaled min. – (input min. x rate) = 0 − (0 × .00320) = 0 PrefaceInstruction Set Reference Manual 3–24 Absolute (ABS) Use the ABS instruction to calculate the absolute value of the Source and place the result in the Destination. This instruction supports integer and floating point values. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors. Entering Parameters Enter the following parameters when programming this instruction: • Source can be a word address, an integer constant, floating point data element, or a floating point constant. • Destination can only be a word address or a floating point data element. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) always resets with a floating point value; sets if the input is –32,768 (integer value). Zero (Z) sets when destination value is zero; otherwise resets. Sign (S) always resets. 333 ABSOLUTE VALUE Source Dest ABS Output Instruction Math Instructions 3–25 Compute (CPT) The CPT instruction performs copy, arithmetic, logical, and conversion operations. You define the operation in the Expression and the result is written in the Destination. The CPT uses functions to operate on one or more values in the Expression to perform operations such as: • converting from one number format to another • manipulating numbers • performing trigonometric functions Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors. Instructions that can be used in the Expression include: +, –, *, | (DIV), SQR, – (NEG), NOT, XOR, OR, AND, TOD, FRD, LN, TAN, ABS, DEG, RAD, SIN, COS, ATN, ASN, ACS, LOG, and ** (XPY). Note The execution time of a CPT instruction is longer than a single arithmetic operation and uses more instruction words. Entering Parameters Enter the following parameters when programming this instruction: • Destination can be a word address or the address of a floating-point data element. • Expression is zero or more lines, with up to 28 characters per line, up to 255 characters. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) sets based on the result of the last instruction in the Expression. Overflow (V) sets any time an overflow occurs during the evaluation of the Expression. Zero (Z) sets based on the result of the last instruction in the Expression. Sign (S) sets based on the result of the last instruction in the Expression. The above bits are cleared at the start of the CPT instruction. See S:34/2 for special handling of the math status bits when using floating point. 333 COMPUTE Dest Expression CPT Output Instruction PrefaceInstruction Set Reference Manual 3–26 Application Example This application example uses Pythagorean’s theorem to find the length of the long leg of a triangle, knowing the two other leg lengths. Use the following equation: c2 = a2 + b2 Rung 2:0 uses standard math instructions to implement Pythagorean’s theorem. Rung 2:1 uses the CPT instruction to obtain the same calculation. | Rung 2:0 +XPY–––––––––––––––+ ||–––––––––––––––––––––––––––––––––––––––––––––––––––––+–+X TO POWER OF Y +–+–|| | |Source A N7:1| | || | | 3| | || | |Source B 2| | || | | | | || | |Dest N7:3| | || | | 0| | || | +––––––––––––––––––+ | || | +XPY–––––––––––––––+ | || +–+X TO POWER OF Y +–+ || | |Source A N7:2| | || | | 4| | || | |Source B 2| | || | | | | || | |Dest N7:4| | || | | 0| | || | +––––––––––––––––––+ | || | +ADD–––––––––––––––+ | || +–+ADD +–+ || | |Source A N7:3| | || | | 0| | || | |Source B N7:4| | || | | 0| | || | |Dest N7:5| | || | | 0| | || | +––––––––––––––––––+ | || | +SQR–––––––––––––––+ | || +–+SQUARE ROOT +–+ || |Source N7:5| || | 0| || |Dest N7:0| || | 0| || +––––––––––––––––––+ || Rung 2:1 +CPT––––––––––––––––––––––––+ ||––––––––––––––––––––––––––––––––––––––––––––––––+COMPUTE +–|| |Dest