## Pré-visualização | Página 33 de 50

A pressure transducer is connected to input 0 and we want to read the value in engineering units. The pressure transducer measures pressures from 0–1000 psi and provides a 0–10V signal to the analog module. For a 0–10V signal, the analog module provides a range between 0–32,767. The following program rung places a number between 0–1000 into N7:20 based on the input signal coming from the pressure transducer into the analog module. Rung 2:0| +SCP––––––––––––––––––––+ ||––––––––––––––––––––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS +–|| |Input I:1.0| || | 0| || |Input Min. 0| || | | || |Input Max. 32767| || | | || |Scaled Min. 0| || | | || |Scaled Max. 1000| || | | || |Scaled Output N7:20| || | 0| || +–––––––––––––––––––––––+ | PrefaceInstruction Set Reference Manual 3–16 Example 2 In the second example, an analog I/O combination module (1746-NIO4I) is in slot 1 of the chassis. We want to control the proportional valve connected to output 0. The valve takes a 4–20mA signal to control how far it opens (0–100%). (Assume that additional logic is present in the program that calculates how far to open the valve in percent and places a number between 0–100 into N7:21.) The analog module provides a 4–20mA output signal for a number between 6242–31,208. The following program rung directs an analog output to provide a 4–20 mA signal to the proportional valve (N7:21), based on a number between 0–100. Rung 2:1| +SCP––––––––––––––––––––+ ||––––––––––––––––––––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS +–|| |Input N7:21| || | 0| || |Input Min. 0| || | | || |Input Max. 100| || | | || |Scaled Min. 6242| || | | || |Scaled Max. 31208| || | | || |Scaled Output O:1.0| || | 0| || +–––––––––––––––––––––––+ | Math Instructions 3–17 Scale Data (SCL) When this instruction is true, the value at the source address is multiplied by the rate value. The rounded result is added to the offset value and placed in the destination. Example SCL SCALE Source N7:0 100 Rate [/10000] 25000 Offset 127 Dest N7:1 377 The source 100 is multiplied by 25000 and divided by 10000 and added to 127. The result 377 is placed in the destination. Note Anytime an underflow or overflow occurs in the destination file, minor error bit S:5/0 must be reset by the program. This must occur before the end of the current scan to prevent major error code 0020 from being declared. This instruction can overflow before the offset is added. Note that the term rate is sometimes referred to as slope. The rate function is limited to the range –3.2768 to 3.2767. For example, –32768/10000 to +32767/10000. Entering Parameters The value for the following parameters is between –32,768 to 32,767. • Source can be either a constant or a word address. • Rate (or slope) is the positive or negative value you enter divided by 10,000. It can be either a constant or a word address. • Offset can be either a constant or a word address. 33 333 SCL SCALE Source Rate [/10000] Offset Dest Output Instruction PrefaceInstruction Set Reference Manual 3–18 Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) is reserved. Overflow (V) sets if an overflow is detected; otherwise resets. On overflow, minor error bit S:5/0 is also set and the value –32,768 or 32,767 is placed in the destination. The presence of an overflow is checked before and after the offset value is applied. À Zero (Z) sets when destination value is zero. Sign (S) sets if the destination value is negative; otherwise resets. À If the result of the Source times the Rate, divided by 10000, is greater than 32767, the SCL instruction overflows, causing error 0020 (Minor Error Bit), and places 32767 in the Destination. This occurs regardless of the current offset. Application Example 1 – Converting 4mA–20mA Analog Input Signal to PID Process Variable Scaled Value Input Value 3,277 (Input Min.) 16,384 (Input Max.) 16,383 0 (Scaled Max.) (Scaled Min.) Math Instructions 3–19 Calculating the Linear Relationship Use the following equations to express the linear relationship between the input value and the resulting scaled value: Scaled value = (input value x rate) + offset Rate = (scaled max. – scaled min.) / (input max. – input min.) (16,383 − 0) / (16,384 – 3277) = 1.249 (or 12,490/10000) Offset = scaled min. – (input min. x rate) 0 – (3277 × 1.249) = –4093 Application Example 2 – Scaling an Analog Input to Control an Analog Output Scaled Value Input Value 3,277 4mA 16,384 20mA 32,764 10V 0 0V (Scaled Max.) (Scaled Min.) (Input Min.) (Input Max.) PrefaceInstruction Set Reference Manual 3–20 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.) (32,764 – 0) / (16,384 – 3277) = 2.4997 (or 24,997/10000) Offset = scaled min. – (input min. x rate) 0 − (3277 × 2.4997) = – 8192 The above offset and rate values are correct for the SCL instruction. However, if the input exceeds 13,107, the instruction overflows. For example: 17mA = 13,926 × 2.4997 = 34,810 (actual overflow) 34,810 – 8192 = 26,618 Notice that an overflow occurred even though the final value was correct. This happens because the overflow condition occurred during the rate calculation. To avoid an overflow, we recommend shifting the linear relationship along the input value axis and reduce the values. The following graph shows the shifted linear relationship. The input minimum value of 3,277 is subtracted from the input maximum value of 16,384, resulting in the value of 13,107. Math Instructions 3–21 Scaled Value Input Value 0 4mA 13,107