The text of a manual · part 11 of 16
SLC 500 4-Channel Analog I/O Modules User Manual: 6 - Programming Examples, pages 72 to 80
Pages 72 to 80 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 72
6-10
Programming Examples
Using Standard Math
Rung 2:0 N7:0 contains percentage of valve open. If this value is less than 0, move the minimum value to the analog output (6242 decimal = 4 mA at the analog output). | Check for Below | | below range flag | | range | | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 0 | | | | 0| | | | | |Source B 0| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 6242| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 N7:0 contains percentage of valve open. If this value is greater than 100, move the maximum value to the analog output (31208 decimal = 20 mA at the analog output). | Check for Above | | above range flag | | range | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 1 | | | | 0| | | | | |Source B 100| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 31208| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ |
Ladder logic continued on the next page.
Publication 1746-UM005B-EN-P - June 2004
Page 73
Programming Examples
6-11
Rung 2:2 Scale values in the 0 to 100% range to the decimal range for the 4–20 mA analog output. | Below |Above Mulitply | | range flag|range flag by scaled | | range | | B3 B3 +MUL–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––+–+MULTIPLY +–+–| | 0 1 | |Source A N7:0| | | | | | 0| | | | | |Source B 24966| | | | | | | | | | | |Dest N7:1| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | | | Divide by | | | | input | | | | range | | | | +DDV–––––––––––––––+ | | | +–+DOUBLE DIVIDE +–+ | | | |Source 100| | | | | | | | | | | |Dest N7:1| | | | | | 0| | | | | +––––––––––––––––––+ | | | | Add offset | | | | +ADD–––––––––––––––+ | | | +–+ADD +–+ | | | |Source A N7:1| | | | | | 0| | | | | |Source B 6242| | | | | | | | | | | |Dest O:2.0| | | | | | | | | | | +––––––––––––––––––+ | | | | Clear math | | | | overflow | | | | bit | | | | S:5 | | | +––––(U)–––––––––––––––+ | | 0 | Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––|
Publication 1746-UM005B-EN-P - June 2004
Page 74
6-12
Programming Examples
Using the Scale with Parameters (SCP) Instruction
Rung 2:0 N7:0 contains percentage of valve open. If this value is less than 0, move the minimum value to the analog output (6242 decimal = 4 mA at the analog output). | Check for Below | | below range flag | | range | | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 0 | | | | 0| | | | | |Source B 0| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 6242| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 N7:0 contains percentage of valve open. If this value is greater than 100, move the maximum value to the analog output (31208 decimal = 20 mA at the analog output). | Check for Above | | above range flag | | range | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 1 | | | | 0| | | | | |Source B 100| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 31208| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ |
Ladder logic continued on the next page.
Publication 1746-UM005B-EN-P - June 2004
Page 75
Programming Examples
6-13
Rung 2:2 Scale values in the 0 to 100% range to the decimal range for the 4–20 mA analog output. | Below |Above | | range flag|range flag | | B3 B3 +SCP––––––––––––––––––––+ | |––––]/[––––––––]/[––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS +–| | 0 1 |Input N7:0| | | | 0| | | |Input Min. 0| | | | | | | |Input Max. 100| | | | | | | |Scaled Min. 6242| | | | | | | |Scaled Max. 31208| | | | | | | |Scaled Output O:2.0| | | | | | | +–––––––––––––––––––––––+ | | | Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––|
Publication 1746-UM005B-EN-P - June 2004
Page 76
6-14
Programming Examples
Scaling Offset when > 32,767 or < -32,768
There may be applications when the offset value put into standard math instructions is greater than 32,767 or less than -32,768. In these cases, it is easier to shift the linear relationship along the input value axis and reduce the values. This example is similar to the situation described in Example 2, except the 4 mA to 20 mA signal is scaled to a value between 90-100%. The NIO4I is located in slot 2 and the output device is wired to channel 0. The following graph displays the linear relationship.
20 mA = 31208 (scaled max.)
Scaled Value
4 mA = 6242 (scaled min. ) 90% (input min.)
100% (input max.)
Input Value
Calculating the Linear Relationship Use the following equations to calculate the scaled units: Scaled value = (input value x slope)+ offset Slope = (scaled max. - scaled min.) / (input max. - input min.) (31,208 - 6,242) / (100 - 90) = 24,966/10 Offset = scaled min. - (input min. x slope) 6242 - (90 x (24,966/10)) = -218,452 Scaled value = (input value) x (24,966/10) - 218,452
Notice the offset value is less than -32,768. Publication 1746-UM005B-EN-P - June 2004
Page 77
Programming Examples
6-15
The following graph shows the shifted linear relationship. Notice that the resulting offset value is reduced.
20 mA = 31208 (scaled max.)
Scaled Value
4 mA = 6242 (scaled min.) 90% (input min.)
100% (input max.) Input Value
Calculating the Shifted Linear Relationship Use the following equations to recalculate the linear relationship: Scaled value = ((input value - input min.) x slope)) + offset Slope = (scaled max. - scaled min.) / (input max. - input min.) (31,208 - 6,242) / (100-90) = 24,966/10 Offset = scaled min. 6,242 Scaled value = ((input value - 90) x (24,966/10)) + 6242
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 and 301) and 5/04 (OS400). The following 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 this example is another ladder diagram performing the same function, but using the SCP (scale with parameters) instruction available only in the SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05. Publication 1746-UM005B-EN-P - June 2004
Page 78
6-16
Programming Examples
Using Standard Math
Rung 2:0 N7:0 contains the percentage of the valve open. | Check for | | below range | | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A N7:0| | 0 | | | | 0| | | | | |Source B 90| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 6242| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 | Check for | | above range | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A N7:0| | 1 | | | | 0| | | | | |Source B 100| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 31208| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ |
Ladder logic continued on the next page.
Publication 1746-UM005B-EN-P - June 2004
Page 79
Programming Examples
6-17
Rung 2:2 Scale values in the 90–100% range to the decimal range for the 4–20 mA analog output. | Subtract | | the input | | min. | | B3 B3 +SUB–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––+–+SUBTRACT +–+–| | 0 0 | |Source A N7:0| | | | | | 0| | | | | |Source B 90| | | | | | | | | | | |Dest N7:1| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | | | Multiply | | | | by the | | | | scaled | | | | range | | | | +MUL–––––––––––––––+ | | | +–+MULTIPLY +–+ | | | |Source A N7:1| | | | | | 0| | | | | |Source B 24966| | | | | | | | | | | |Dest N7:1| | | | | | 0| | | | | +––––––––––––––––––+ | | | | Divide | | | | result by | | | | input | | | | range | | | | +DDV–––––––––––––––+ | | | +–+DOUBLE DIVIDE +–+ | | | |Source 10| | | | | | | | | | | |Dest N7:1| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | | | | | | | | | | | | |
| Add offset | | | +ADD–––––––––––––––+ | | +–+ADD +–+ | | |Source A N7:1| | | | | 0| | | | |Source B 6242| | | | | | | | | |Dest O:2.0| | | | | | | | | +––––––––––––––––––+ | | | Clear flt | | | bit from | | | overflow | | | S:5 | | +––––(U)–––––––––––––––+ | 0 |
Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |
Publication 1746-UM005B-EN-P - June 2004
Page 80
6-18
Programming Examples
Using the Scale with Parameters (SCP) Instruction
Rung 2:0 N7:0 contains percentage of valve open. If this value is less than 90, move the minimum value to the analog output (6242 decimal = 4 mA at the analog output). | Check for Below | | below range flag | | range | | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 0 | | | | 0| | | | | |Source B 90| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 6242| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 N7:0 contains percentage of valve open. If this value is greater than 100, move the maximum value to the analog output (31208 decimal = 20 mA at the analog output). | Check for Above | | above range flag | | range | | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––––( )–––––––––––––––+–| | |Source A N7:0| | 1 | | | | 0| | | | | |Source B 100| | | | | | | | | | | +––––––––––––––––––+ | | | | | Minimum | | | | analog | | | | output | | | | value | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 31208| | | | | | | |Dest O:2.0| | | | | | | +––––––––––––––––––+ |
Ladder logic continued on the next page.
Publication 1746-UM005B-EN-P - June 2004