# AB RSLogix500 averaging values

S

#### S2

Is there a quick way to determine the average of multiple points (integers)? During a flagged condition, I am jumping to a subroutine and determining minimum, maximum, and average values of data from analog inputs (scaled). I need some way of determining the average value of the input channel, and moving the value into a Integer or Floating point value. Does anyone know of an easy way to do this, as I would have to count the number of times the inputs are sampled, the way I was thinking....

A

#### Alan Rimmington

Depends on your application, are you just trying to smooth a varying signal, or are you looking for a pure average over a number of timed samples?

S

#### S2

I would like to calculate the average of a number of values (force) between a range of travel. i.e. When a Ram is between user set positions, I would like to average the force values from a load cell. In my existing software, I am jumping to a data acquisition subroutine only when the position of a ram is between these setpoints. (The values are then displayed on an HMI; not used for closed loop control)

A

#### Alan Rimmington

I think you need to be looking at using FIFO to load your values into a datatable, and compute to calculate the average of the recorded data. The use of these instructions is dependant on the processor being used. If however all you require is to display a stable value (average) on the LOI updated at say ten second intervals, then I could give you a simple way of achieving this. If I can have more information on your requirements I will try to help. [email protected]

H

#### Hakan Ozevin

Regardless of the PLC model, you can calculate the average of an analog input by the following formula: A= (I + (n-1) * A(n-1))/n where A is the average value of I at any sampling moment n. The advantage of this method is you need to store just the previous average value A(n-1), not all of the input values. Example: n: 1 2 3 4 5 I: 10 20 30 40 50 A: 10 15 20 25 30 You can either use the last result (30 in the above example) as the overall average value for the period, or use momentary average values (10,15,20…) as they are, depending on the needs of your process. You can make the sampling by time controlled interrupt and use an appropiate sampling period depending on your process. For example, by taking time controlled interrupt time as 20 ms and n=100, you get an average value of the input for a period of 2 secs. When n=101, set it to 1 and start the calculation for another 2 seconds period. I hope this will help. Hakan Ozevin

S

#### S2

I have already programmed (but not yet tested) a way of calculating the average (of multiple) scaled analog inputs. I am using a Timed Interupt subroutine to be enabled when I wish to begin data collection. When the subroutine is enabled (e.g. every 10mS), I am starting a timer for total time elapsed. In the subroutine, I am adding the analog input value to an interger (originally zero; reset when the subroutine is disabled) and dividing the result by the result of the accumulated value of the timer by the interrupt time: [(Scaled Analog Input + Integer)/(Acc Time/Interrupt time)] The average is displayed on an operator interface, and updated when the PLC updates the communications. I hope that this works and that there is nothing I have overlooked... Thanks.

S

#### S2

I have already programmed (but not yet tested) a way of calculating the average (of multiple) scaled analog inputs. I am using a Timed Interupt subroutine to be enabled when I wish to begin data collection. When the subroutine is enabled (e.g. every 10mS), I am starting a timer for total time elapsed. In the subroutine, I am adding the analog input value to an interger (originally zero; reset when the subroutine is disabled) and dividing the result by the result of the accumulated value of the timer by the interrupt time: [(Scaled Analog Input + Integer)/(Acc Time/Interrupt time)] The average is displayed on an operator interface, and updated when the PLC updates the communications. I hope that this works and that there is nothing I have overlooked... Thanks.

B