AB RSLogix500 averaging values

S

Thread Starter

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?
 
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(n)= (I(n) + (n-1) * A(n-1))/n where A(n) is the average value of I(n) 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
 
M
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.
 
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.
 
A

Alan Rimmington

I would be inclined to count the number of samples to use as the divider, the easy way to do this would be to use an ADD eg N7:0 + 1 = N7:0 , possibly using a OSR in series if necessary. Eg every time an addition is made to the value to be averaged 1 is added to N7:0. You would then zero N7:0 at the same time as zeroing the value for averaging (when subroutine not required).
 
Top