Hourly PLC Data Average for Each Scan

mfeby

Member
Join Date
May 2002
Location
Sharjah
Posts
6
Dear Group:

I am looking to calculate average for a point for each hour and use this data from some of my reports. I have similarly 10 points to be averaged. I am looking for the best sample of each scan. If expeirnce says that we should not use each scan then at least 1 sec scan should be fine. Please help me out to get some idea or examples of how to do this in Allen Bradley RS Logix. I am having PLC 5/40E.

Appreciate suggestions from the group
 
Gretings Feby Mohammed,

Here's the idea:
Do the following each scan sycle (or each one sec)
1- Copy the value of your Point to word_A (Mov instruction).
2- Add Word_A to Word_B (Add istruction).
3- Increment an up counter by one.
4- Divide Word_B by the counts held by the counter (Div instruction)and put the result in Word_C.(Mov instruction)

Now:
Word_A: Holds the instantenous value of your point.
Word_B: Acts as a totalizer ! (the sum value)
Word_C: Holds the average value.

You should notice that you must monitor the time some how and after each hour elapsed you should:
1- Copy Word_C to Word_D ( Your SCADA/HMI software will use the value in this word for your reports)
2- Reset the counter
3- Reset Word_A, Word_B and Word_c (Simply put Zero on each of them).

Hope this helps.
 
Last edited:
Thanks for the idea, but how can i manage the counters. counter has a mx of 32767, and i assume that hourly scan well exceeds the counter max, also how can i move 10 points with the same instruction, i mean some kind of indirect addressing...
 
If you want a running average, there's a better way. You can store as many samples as PLC memory will allow using indexed addressing. You add the current sample and subtract the oldest to/from an accumulator. Use a floating point address for greatest range. You could use the FIFO instructions, which take a lot of scan time if you are shifting a lot of data, or use the attached code instead of FFU, FFL pairs. This method does not move the data, just a couple of pointers. It is still limited by file boundaries (1000 samples), but could be modified to overcome that. The biggest problem you'll have with a simple moving average is overflow on the accumulator register. You will have to limit your sampling to stay within the range of the accumulator.

To get a higher sample rate, you could use a method in which you start out with a simple moving average (sum_of_all_samples/no_of_samples) and when you reach a certain number of samples, you subtract the last calculated average instead of the oldest data, and then add the newest data before dividing. I have not tested this and do not know what all the ramifications might be, but it should behave similarly to exponential averaging.

What ever you do, you'll need to do ten times. I would avoid FFU/FFL for this application. My example uses a timer (T4:0) to control the sample rate. You can set its preset to zero or delete it to sample every scan. When first started, the number of samples will increment until it reaches the total number of samples to be averaged. There's a trend chart that you can use to view the average vs. the raw data. I tested this on a PLC5/30 using the included trend plot to view the results. I edited the raw value N7:0 manually to simulate a changing input, and toggled the reset bit from within RSLogix.

Hope this helps.
 
Last edited:
mfeby said:
Thanks for the idea, but how can i manage the counters. counter has a mx of 32767, and i assume that hourly scan well exceeds the counter max,
I'm sure there are many ideas to overcome this problem, Here is what came to my mind:
You 'll use another word (or another counter) which will hold this piece of information: "how many counters reached the maximum value" ?
How? (Using two counters)
When the counter reaches the max value, Two things should happen:
1- Let the counter resets it self.
2- Add one to our new counter. (say Counter_aux)

Now your formula will be as following:
Average = Word_B / (Counter_aux * 32767 + original Counter)

also how can i move 10 points with the same instruction, i mean some kind of indirect addressing...
I'm not sure of what are trying to do !
Are these 10 points of the same types (Temperature readings for examble)?
To make it simple, Write the formula required to average for only one scan or seconed ..
Is it like this: (Point_1 + Point_2 + .... + Point_10)/10 ?
I'll be back after "Eltraweeh".
 
since i was trying out the option based on scan cycles, it was overflowing. i developed a logic as above and found working with 1 sec scan. i will post the logic by tomorrow evening.. may be then we will discuss the modification and problems on those. Thanks for your valuable suggestions... ayman.
 
You might be better of using the AVE (Average) function to compute your average. I believe there is example of this somewhere on this forum. Just search AVE for some examples.
 
AVE instruction workaround for SLC500

It doesn't pertain to this specific situation, but, for the sake of thread completeness, the SLC500 processor doesn't support AVE instructions.

An example of one of the possible work-arounds is available at the Rockwell Knowledgebase, article
"A19637318 - Computing the average of up to 128 integer words".
 

Similar Topics

This has been a very touchy subject at my workplace for awhile, so I'm curious what your companies do for pay hourly guys? Travel to customer? Do...
Replies
20
Views
8,018
I've been using 5000 primarily. I've been able to based on prerequisite bits firing make an hourly production tag looking something like...
Replies
2
Views
1,578
Hi, I was wondering if some of you could share the average hourly cost you would pay for a control engineer's onsite support. Relevant states in...
Replies
6
Views
2,524
Ok, so here's one that's been giving me a headache all day. I'm one of those guys that thinks about stuff until I get it...even off the clock...
Replies
24
Views
10,516
hi all i am from india and we have AB Controllogix plc installed. We want to implement hourly totaliser values for few flow tags. is it possible...
Replies
1
Views
2,472
Back
Top Bottom