The text of a manual · part 10 of 16
SLC 500 4-Channel Analog I/O Modules User Manual: 6 - Programming Examples, pages 63 to 71
Pages 63 to 71 of 113, from SLC 500 4-Channel Analog I/O Modules User Manual
The original document is the PDF (1.2 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1746-NI4
Page 63
Chapter
6
Programming Examples
This chapter shows several programming examples that provide additional capabilities such as: • Addressing, Out-of-Range Detection, and Scaling of Analog Inputs • Addressing and Scaling of Analog Outputs • Scaling Offsets when > 32,767 or < -32,768 • Scaling and Range Checking of Analog Inputs and Outputs IMPORTANT
The programming examples in this chapter are for informational purposes only. Because of the many variables and requirements associated with any application, the Allen–Bradley Company cannot assume responsibility or liability for actual use based on these examples.
The following example uses an NI4 analog input module to show input addressing, range checking and scaling of analog inputs into engineering units.
Addressing, Out-of-Range Detection, and Scaling of Analog Inputs
1
The following assumptions are being made: • The NI4 is located in slot 3 of a modular system. • A temperature transducer with a 0 to 10V dc output is wired to the second input channel on the analog module. • The transducer voltage signal is proportional to a range of 100° C to 500° C (212° F to 932° F). • The process temperature must stay between 275° and 300° C (527° F to 572° F). If the temperature deviates from this range, a flag is set and this out-of-range value is not processed. The data is presented in degrees C for monitoring and display purposes.
Publication 1746-UM005B-EN-P - June 2004
Page 64
6-2
Programming Examples
The scaling operation is displayed in the following graph. It displays the linear relationship between the input and the resulting scaled values.
500°C (Scaled max.)
Scaled Value 300°C Process operating range
275°C
100°C (Scaled min.) 0=0V dc (input min.)
Low Limit
High Limit
32767 = 10V dc – 1 LSB (input max.)
Input Value
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 slope) + offset Slope = (scaled max. - scaled min.) / (input max. - input min.) (500 - 100) / (32,767 - 0) = 400/32,767 Offset = scaled min. - (input min. x slope) 100 - (0 x (400/32,767)) = 100 Scaled value = (input value x (400 / 32767)) + 100
Publication 1746-UM005B-EN-P - June 2004
Page 65
Programming Examples
6-3
Calculating the Out-of-Range Flag Using the Scale Instruction Use the following equation to calculate the low and high limit input values which determine the out-of-range flag. Input value = (scaled value - offset) / slope low limit (275 - 100) / (400/32,767) = 14,344 high limit (300 - 100) / (400/32,767) = 16,393
Once you have calculated the linear relationship and the out-of-range flag value, this example allows you to: • Turn on a heater or fan to maintain the process temperature between 275° and 300° C by using the out-of-range flags. • Monitor the process temperature using a Data Table Access Module (DTAM) or Hand-Held Terminal (HHT). • Output the process temperature for operation interface purposes by: – MOVing the scaled value to an output module as variable data to a Dataliner – Converting the scaled value to BCD (using TOD instruction) and MOVing it to an LED display The following ladder diagrams show how to program the processor. The first example uses standard math instructions available in any SLC 500 processor. The ladder diagram prevents a processor fault by unlatching the mathematical overflow bit S2:5/0 before the end of the scan. The second example uses the scaling instruction (SCL)➀ available in the 5/02 and higher processors. The rate parameter is calculated by multiplying the slope by 10,000. rate = (400/32767) x 10,000 = 122
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. The third example uses the SCP (scale with parameters) instruction available in the SLC 5/03 (OS302 or later), SLC 5/04 (OS401 or later), and SLC 5/05 only.
Publication 1746-UM005B-EN-P - June 2004
Page 66
6-4
Programming Examples
Using Standard Math
Rung 2:0 Check for below allowable range | Below | | range flag | | +LES–––––––––––––––+ B3 | |–+LESS THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 0 | | | | | | |Source B 14344| | | | | | | +––––––––––––––––––+ | Rung 2:1 Check for above allowable range | Above | | range flag | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 1 | | | | | | |Source B 16383| | | | | | | +––––––––––––––––––+ | Rung 2:2 Turn on the below range alarm output when analog input is below acceptible range | Below | Below | | range flag| range alarm | | B3 O:2 | |––––] [–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | 0 0 | Rung 2:3 Turn on the above range alarm output when analog input is above acceptible range | Above | Above | | range flag| range alarm | | | | | B3 O:2 | |––––] [–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | 1 1 |
Ladder logic continued on the next page.
Publication 1746-UM005B-EN-P - June 2004
Page 67
Programming Examples
6-5
Rung 2:4 Scale the analog input value and process the result only when it is within the acceptible range | Below |Above Multiply | | range flag|range flag by the | | scaled range | | | | B3 B3 +MUL–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––+–+MULTIPLY +–+–| | 0 1 | |Source A I:1.1| | | | | | | | | | | |Source B 400| | | | | | | | | | | |Dest N7:0| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | | | Divide | | | | result by | | | | input | | | | range | | | | +DDV–––––––––––––––+ | | | +–+DOUBLE DIVIDE +–+ | | | |Source 32767| | | | | | | | | | | |Dest N7:0| | | | | | 0| | | | | +––––––––––––––––––+ | | | | Add offset | | | | (N7:0 cont | | | | ains proce | | | | ss tempera | | | | ture) | | | | +ADD–––––––––––––––+ | | | +–+ADD +–+ | | | |Source A N7:0| | | | | | 0| | | | | |Source B 100| | | | | | | | | | | |Dest N7:0| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | Clear flt | | | | bit from | | | | overflow | | | | S:5 | | | +––––(U)–––––––––––––––+ | | 0 | Rung 2:5 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |
Publication 1746-UM005B-EN-P - June 2004
Page 68
6-6
Programming Examples
Using the Scale (SCL) Instruction
Rung 2:0 Check for below allowable range. | Below | | range flag | | +LES–––––––––––––––+ B3 | |–+LESS THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 0 | | | 0| | | |Source B 14344| | | | | | | +––––––––––––––––––+ | Rung 2:1 Check for above allowable range. | Above | | range flag | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 1 | | | 0| | | |Source B 16383| | | | | | | +––––––––––––––––––+ | Rung 2:2 Turn on the below range alarm output when the analog input is below the acceptible range. | Below Below | | range flag range alarm | | B3 O:2 | |––––] [––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )––| | 0 0 | Rung 2:3 Turn on the above range alarm output when the analog input is above the acceptible range. | Above Above | | range flag range alarm | | B3 O:2 | |––––] [––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )––| | 1 1 | Rung 2:4 Scale analog input value and process the result only when it is within acceptible range. | Below |Above Scale | | range flag |range flag analog input | | B3 B3 +SCL–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––––––+SCALE +–| | 0 1 |Source I:1.1| | | (2:0) (2:1) | 0| | | |Rate [/10000] 122| | | | | | | |Offset 100| | | | | | | |Dest N7:0| | | | 0| | | +––––––––––––––––––+ | | | Rung 2:5 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |
Publication 1746-UM005B-EN-P - June 2004
Page 69
Programming Examples
6-7
Using Scale with Parameters (SCP) Instruction
Rung 2:0 Check for below allowable range. | Below | | range flag | | +LES–––––––––––––––+ B3 | |–+LESS THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 0 | | | 0| | | |Source B 14344| | | | | | | +––––––––––––––––––+ | Rung 2:1 Check for above allowable range. | Above | | range flag | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +–––––––––––––––––––––––––––––––––––––––––––––––––( )–––––| | |Source A I:1.1| 1 | | | 0| | | |Source B 16383| | | | | | | +––––––––––––––––––+ | Rung 2:2 Turn on the below range alarm output when the analog input is below the acceptible range. | Below Below | | range flag range alarm | | B3 O:2 | |––––] [––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )––| | 0 0 | Rung 2:3 Turn on the above range alarm output when the analog input is above the acceptible range. | Above Above | | range flag range alarm | | B3 O:2 | |––––] [––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––( )––| | 1 1 | Rung 2:4 | Below |Above Scale | | range flag |range flag analog input | | B3 B3 +SCP–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS+–| | 0 1 |Input I:1.1| | | 0| |Input Min. 0| | | |Input Max. 32767| | | |Scaled Min. 100| | | |Scaled Max. 500| | | |Scaled Output N7:0| | 0| +––––––––––––––––––+ Rung 2:5 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––|
Publication 1746-UM005B-EN-P - June 2004
Page 70
6-8
Programming Examples
Addressing and Scaling Outputs
We are making the following assumptions: • The NIO4I is located in slot 2 of a SLC 500 system. • An actuator from a flow control valve is wired to output channel 0. • The actuator accepts a 4 mA to 20 mA signal proportional to 0 to 100% of the valve’s opening. For this example the signal actuator can not receive a signal out of the 4 mA to 20 mA range. • The percentage of valve opening is manually input to the SLC. The following graph displays the linear relationship.
20 mA = 31208 (scaled max.)
Scaled Value
4 mA = 624 2 (scaled min. ) 100% (input max.)
0% (input min.) Input Value
Calculating the Linear Relationship Use the following equations to calculate the scaled output value: Scaled value = (input value x slope) + offset Slope = (scaled max. - scaled min.) / (input max. - input min.) (31,208 - 6,242) / (100-0) = 24,966/100 Offset = scaled min. - (input min. x slope) 6,242 - (0 x (24,966/100)) = 6,242 Scaled value = (input value x (24,966/100)) + 6,242
Publication 1746-UM005B-EN-P - June 2004
Page 71
Programming Examples
6-9
The out-of-range limits are predetermined because any value less than 0% is 6,242 and any value greater than 100% is 31,208. The ladder logic checks for the out-of-range flag to verify that not less than 4 mA and not more than 20 mA is provided out of the analog output channel. The percentage of valve opening may be input to the processor by: • entering the data through a DTAM or HHT • MOVing the data from thumb wheels or a keypad (possibly converting the data from BCD using FRD instruction) The percentage of valve opening may be output for operator interface by: • monitoring the data using a DTAM or HHT • MOVing the data to an output module as variable data to a Dataliner • converting the data to BCD (using TOD instruction) and MOVing it to an LED display Since the slope is greater than 3.2767 only standard math can be used for the ladder diagram with SLC 500 fixed, SLC 5/01, 5/02, 5/03 (OS300 or OS301), and 5/04 (OS400) processors. The ladder diagram prevents a processor fault by unlatching the mathematical overflow bit S2:5/0 before the end of the scan. Refer to the example ladder diagram on the next page. Following the standard math example is a ladder diagram using the SCP instruction, available only in the SLC 5/03 (OS302 or later), SLC 5/04 (OS401 or later), and SLC 5/05.
Publication 1746-UM005B-EN-P - June 2004