Check the analog values to see if they have varied more than 1V in the last 5 min?

bharathchari1

Member
Join Date
May 2015
Location
canada
Posts
7
I have an AB PLC where I am trying to read analog values to see if the values vary more than 1V in 5 minutes? I have 10 sets of values I need to read. What would the easiest way to implement this? I can think of creating arrays to save the values each time I read them but the part I am having trouble with is, how to keep a running average of the values and compare against each time I read them.


Any help with this would be greatly appreciated!!
 
I’m not very familiar with them but the CPT lets you create a math expression so you could move the data into separate integers, add them together (N10:0 + N10:1 + N10:2 + N10:3) with the sum being moved to the selected destination. Then take the integer in the destination and divide that by the number of integers being added together. That would give you the average which you could then compare to the current value.
https://www.courses.psu.edu/e_met/e_met430_jar14/math/cpt.html
 
Ah I get it. I should have been more clear but I need to monitor each of the 10 analog values separately and compare each one against it's previous value to see if it has drifted by more than 1V in the last 5 minutes. So I would not be able to do an average for all of them.

Is there any other way I can do this?
 
You will need the FFL and FFU instruction. Have a look at the help files for these and you should get a bit of a feel for how to do it.

You will need to determine how often you need to sample. Let's say that you sample every 10 seconds; that means to store 5 minutes' worth of data you will need an array of 30 readings.

So you'll create an array of 30 DINT's, and every 10 seconds you'll:
- Unload the oldest value out of the array using the FFU instruction
- Compare it against the current value and see if it's within your allowable limits
- Load the current value into the array using the FFL instruction

Here's a thread I posted in recently which was a somewhat similar application, and gave a little more detail on setting up the FFL/FFU instruction. Between that and the help file, you should be able to mangle something together :)
 
I did something similar in an application where I was already doing a Moving Average.
If your AB plc is a CLGX or CompactLGX, look at the MAVE function.

Using ASFs example, you'd set the MAVE storage array to 31, the FB routine as a periodic task every 10 secs, and compare the first and last elements of the storage array.

Not sure i'd do it this way if I didn't need the moving average as well, but it didn't take much work.
 
Are you really needing to average the readings? And if so, what is the frequency of your readings?
It would appear to me that if you wanted to see if your value has varied more than 1V, you would simply store the initial reading, then have a MAX and MIN for each reading such that if the reading is less than the MIN then the MIN = the new reading. If the reading is greater than the MAX then the MAX = the new reading.
At the end of your 5 minutes, see if the MIN - stored value > 1V, same with the MAX.
 
Also, to be clear on the application, is it:

A) One analog input that you have 10 samples of and need to find the min/max to find total variance

B) 10 analog inputs that you are just looking to compare each one with its previous value

EDIT: Dan beat me to it. :)
 
You didn't say which PLC.

Here is an example for Logix500: http://www.plctalk.net/qanda/showpost.php?p=260919&postcount=5

Here is one for Logix5: http://www.plctalk.net/qanda/showpost.php?p=607711&postcount=15

If it is a control logix then use either FFL/FFU pairs or, even easier, use a ten element array, and copy down the array to shift everything down one word, then put the newest sample into array[9]. See attached. You must copy down, copying up will overwrite all the stored values in the array with the newest value. Then use the ControlLogix AVE instruction to find the average. If you copy the array to a new array, then sort the new array, now you have the minimum and maximum values at each end of the sorted array, and you can compare just those two values.

tc1208151.jpg
 
Last edited:
I wasn’t thinking you’d take all ten values and combine them but rather for each analog input you would have a routine involving a CPT. The nice thing about the CPT instruction is it lets you do math that you can’t otherwise do without a lot of logic. For each input you could collect ten samples inside the five minutes, use the CPT average them together and divide by 10 in one instruction and then use that value to compare with the current value.
I also like the idea to use the FFL instruction. It makes it a lot easier to move the collected data into an array.
P.S. It’s worth noting that when using the CPT instruction if you want to divide you have to use “|” which is not a capital “I” or lower case “l” but the character above “\”.
 
P.S. It’s worth noting that when using the CPT instruction if you want to divide you have to use “|” which is not a capital “I” or lower case “l” but the character above “\”.


The | character to which you refer is called the pipe character. (So called because in computing the character was used in command lines and scripts to pipe output from a process to another process.) In PLC5 and SLC500 processors it is used as the division operator.

However, in a ControlLogix PLC you use the conventional division character, /, for divide, not the pipe character.
 

Similar Topics

Hi, i've write this AOI to send a ControlValue comes from pid and control a valve. this valve is controlled through analog output. the rang of...
Replies
0
Views
1,021
Hey guys, I recently visited an existing water plant that's running a Scadapack32 with ClearScada for the HMI. I've been looking through the...
Replies
0
Views
1,468
Hello everyone, I have a question about IFIX. there is a analog tag, its value changes every 1 sec and I need to check its value every 5 sec, if...
Replies
0
Views
1,740
Hello all, I have a Controllogix 1756-L61 with some RIO. There are a couple of 1734-OB4E's that have gone bad. (no output voltage) My boss found...
Replies
10
Views
1,056
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
0
Views
402
Back
Top Bottom