Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 12 of 16

SLC 500 4-Channel Analog I/O Modules User Manual: 6 - Programming Examples, pages 81 to 88

Pages 81 to 88 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 81

Programming Examples

6-19

Rung 2:2 Scale values in the 90 to 100% range to the decimal range for the 4–20 mA analog output. | Below |Above Scale for the | | analog output | | range flag|range flag | | B3 B3 +SCP––––––––––––––––––––+ | |––––]/[––––––––]/[––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS +–| | 0 1 |Input N7:0| | | | 0| | | |Input Min. 90| | | | | | | |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 82

6-20

Programming Examples

Scaling and Range Checking and Analog Inputs and Outputs

This example demonstrates the addressing of analog I/O and the scaling and range checking of analog input and output values. An NIO4V is placed in slot 1 of an SLC 500 system. A 0 to 200 psi pressure sensor is input as a 4 mA to 20 mA signal to input channel 0. The input value is checked to ensure it remains within the 4 mA to 20 mA range. It is then scaled and output as a 0 to 2.5 volt signal to a panel meter pressure display connected to output channel 0. If an out–of–range condition is detected a flag bit will be set. The scaling operation is shown below. The graph displays the linear relationship between the input value and the resulting scaled value.

8192 (scaled max.)

Scaled Value

0 (scaled min.)

3277 (input min.) Input Value

Publication 1746-UM005B-EN-P - June 2004

16384 (input max.)

Page 83

Programming Examples

6-21

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.) (8192 - 0) / (16384 - 3277) = 8192/13107 Offset = scaled min. - (input min. x slope) 0-3277 (8192/13,107) = -2048 Scaled value = (input value x (8192/13017)) - 2048

This equation can be implemented using integer math capabilities of the SLC 500 system. Three example programs are shown. The first runs on any SLC 500 processor and the second uses the scaling instruction available on the SLC 5/02 and later processors. The third program uses the SCP (scale with parameters) instruction available only with SLC 5/03 (OS302 or later), SLC 5/04 (OS401 or later), and SLC 5/05. In the first example program the analog input value is checked against the minimum and maximum allowable input values. If the input is out-of-range, the output value is set to its minimum or maximum value. If the input value is in range the output value is determined by scaling the input. To scale an analog input, follow these steps: 1. Multiply the input by the scaled range Scale range=(scaled max. - scaled min.). 2. Divide the 32 bit result by the input range Input range=(input max. - input min.). 3. Add in the offset value (in this case negative). The final value is then moved to the analog output channel 0. The multiply operation will generate an overflow bit and minor error flag whenever the results exceed 16 bits. Since the divide is carried out on the 32 bit result in the math register, the overflow does not present a problem. The minor error flag has to be cleared before the end of the program scan to avoid a system error.

Publication 1746-UM005B-EN-P - June 2004

Page 84

6-22

Programming Examples

Using Standard Math Instructions

Rung 2:0 Check for below range. | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 0 | | | | | | | | | |Source B 3277| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 0| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ |

Ladder logic continued on the next page.

Publication 1746-UM005B-EN-P - June 2004

Page 85

Programming Examples

6-23

Rung 2:1 Check for above range. | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 1 | | | | | | | | | |Source B 16384| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 8192| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | Rung 2:2 Scale the analog input for the analog output. | Multiply | | by the scaled | | range | | | | B3 B3 +MUL–––––––––––––––+ | |––––]/[––––––––]/[–––––––––––––––––––––––––––––––––––+–+MULTIPLY +–+–| | 0 1 | |Source A I:1.0| | | | | | | | | | | |Source B 8192| | | | | | | | | | | |Dest N7:0| | | | | | 0| | | | | +––––––––––––––––––+ | | | | | | | | Divide | | | | result by | | | | the input | | | | range | | | | +DDV–––––––––––––––+ | | | +–+DOUBLE DIVIDE +–+ | | | |Source 13107| | | | | | | | | | | |Dest N7:0| | | | | | 0| | | | | +––––––––––––––––––+ | | | | Add offset | | | | +ADD–––––––––––––––+ | | | +–+ADD +–+ | | | |Source A N7:0| | | | | | 0| | | | | |Source B –2048| | | | | | | | | | | |Dest O:1.0| | | | | | | | | | | +––––––––––––––––––+ | | | | Clear flt | | | | bit from | | | | overflow | | | | S:5 | | | +––––(U)–––––––––––––––+ | | 0 | Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |

Publication 1746-UM005B-EN-P - June 2004

Page 86

6-24

Programming Examples

Scaling and Range Checking of Analog Inputs and Outputs

The scaling instruction available in the SLC 5/02 processor is used to realize a more efficient program. The scaling instruction uses the same multiply, divide and add algorithm but it does so with a single rate instead of the scaled range and input range values. The rate is determined by: Rate = (scaled range / input range) x 10,000 For the programming example the rate = 6250

Publication 1746-UM005B-EN-P - June 2004

Page 87

Programming Examples

6-25

Using SCL Instruction

Rung 2:0 Check for below range. | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 0 | | | | | | | | | |Source B 3277| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 0| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 Check for above range. | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 1 | | | | | | | | | |Source B 16384| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 8192| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | Rung 2:2 Scale the analog input for the analog output. | B3 B3 +SCL–––––––––––––––+ | |––––]/[––––––––] [–––––––––––––––––––––––––––––––––––––––+SCALE +–| | 0 1 |Source I:1.0| | | | | | | |Rate [/10000] 6250| | | | | | | |Offset –2048| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | | | Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––|

Publication 1746-UM005B-EN-P - June 2004

Page 88

6-26

Programming Examples

Using the Scale with Parameters (SCP) Instruction

Rung 2:0 Check for below range. | +LES–––––––––––––––+ B3 | |–+LESS THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 0 | | | | | | | | | |Source B 3277| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 0| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | Rung 2:1 Check for above range. | +GRT–––––––––––––––+ B3 | |–+GREATER THAN +––––––––––––––––––––––––––––––––+––( )–––––––––––––––––+–| | |Source A I:1.0| | 1 | | | | | | | | | |Source B 16384| | | | | | | | | | | +––––––––––––––––––+ | | | | | +MOV–––––––––––––––+ | | | +–+MOVE +–+ | | |Source 8192| | | | | | | |Dest O:1.0| | | | | | | +––––––––––––––––––+ | Rung 2:2 Scale the analog input for the analog output. | B3 B3 +SCP––––––––––––––––––––+ | |––––]/[––––––––] [––––––––––––––––––––––––––––––––––+SCALE W/PARAMETERS +–| | 0 1 |Input I:1.0| | | | | | | |Input Min. 3277| | | | | | | |Input Max. 16384| | | | | | | |Scaled Min. 0| | | | | | | |Scaled Max. 8192| | | | | | | |Scaled Output O:1.0| | | | | | | +–––––––––––––––––––––––+ | | | Rung 2:3 | | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |

Publication 1746-UM005B-EN-P - June 2004