You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old August 17th, 2007, 10:25 AM   #1
RMA
Member
Scotland

RMA is offline
 
RMA's Avatar
 
Join Date: Sep 2004
Location: North of Hamburg, Germany
Posts: 2,052
Step7 - creating a running average of 256 values

I want to monitor the cycle times of some of our stations (the process, not the CPU cycle time). We had a case recently where throughput was down and nobody new why and we discovered that a station which normally completes its work cycle in about 35 secs had drifted up to about 42 secs over the last three months.

I intend to save the cycle times in a 256 Byte array in a DB and compare the average with a Target time and issue a warning on the OP if this time is exceeded.

Does anybody know if there is a Siemens FC or SFC which will do this for me, I can't find any likely candidates in the Standard Library.

I know can do this in a loop, but I'm a bit nervous about cycle time contraints if I do it all in one fell swoop and I don't like loops that only perform one step per cycle, because I find people sometimes have problem figuring out what's going on with them.

If anybody's got a boxed function which does something similar, I be interested to see it.

Cheers

Roy
  Reply With Quote
Old August 17th, 2007, 10:55 AM   #2
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,761
Why 256 points? Why not use a simple low pass filter.
http://www.plctalk.net/qanda/showthr...ghlight=Filter
Now you can change the amount of filtering by changing a constant instead of the size of the array.

If you must use a 256 point array you need to keep a sum that is initialized to 0. The array must be initialize to 0 too.

Now for each NewTime

I = I + 1
if I >= 256 Then I = 0
SumTime = SumTime - Array[i]
SumTime = SumTime + NewTime
Array[i] = NewTime
AvgTime=SumTime / 256 // I would shift right by 8 or multiply by (1/256) to avoid the divide.

This should be easy and fast enough.
  Reply With Quote
Old August 17th, 2007, 11:03 AM   #3
PeterW
Member
Canada

PeterW is offline
 
Join Date: Jun 2006
Location: Edmonton
Posts: 2,517
I would put into a table 256 long and use like a FIFO.

As a value goes in I would ADD it to a running total and add 1 to the total number of values. Then divide the total by the number of values.

If the FIFO is full, then I would unload and subtract that value from the running total before loading in the new value.

So the Logic

Is FIFO Full?
If NO - Goto Load FIFO

UNLOAD FIFO
Running Total = Running Total - FIFO Value Unloaded
No. of Values = No. of Values - 1


Load FIFO:

Running Total = Running Total + New Value
No. of Values = No. of Values + 1
LOAD FIFO

Average = Running Total / No. of values

END




Ensure if the FIFO is empty, then zero everything.


There are two ways, use the FIFO in the S5 converstion blocks or move values using two SFC20 calls, two are needed as you cannot overlap data, so you would have to move the data to a temp and then back again, but offset by 1, zero the first and see if anything came out of the end.
  Reply With Quote
Old August 17th, 2007, 11:06 AM   #4
PeterW
Member
Canada

PeterW is offline
 
Join Date: Jun 2006
Location: Edmonton
Posts: 2,517
With Peter's suggestion you would start again after every 256, my suggestion would always give you the last 256, depends on what you want.
  Reply With Quote
Old August 17th, 2007, 11:15 AM   #5
TConnolly
Lifetime Supporting Member
United States

TConnolly is offline
 
TConnolly's Avatar
 
Join Date: Apr 2005
Location: Salt Lake City
Posts: 6,149
One simple way to do a running average without a lot of data shifting is:



((Average - (Average/N)) + C)/N

Where N is the number of data points and C is the value of the newest data point.

Left alone, this is an infinite sum average, which may not be desirable. But nothing keeps you from resetting it.

The longer it runs the stronger it becomes as an indicator of what an average run time is if you are using if for comparison.
__________________
True craftsmanship is only one more power tool away.

That's the beauty of processors, they don't have emotions they just run code - The PLC Kid.
  Reply With Quote
Old August 17th, 2007, 11:22 AM   #6
RMA
Member
Scotland

RMA is offline
 
RMA's Avatar
 
Join Date: Sep 2004
Location: North of Hamburg, Germany
Posts: 2,052
I've had a look at the basic performance figures for the 315 and have come to the conclusion that I'm worrying unnecessarily about the effect on cycle time. (I wish I could find the Siemens manual which has the exact operation times for all the operations under all conditions!)

Peter N's example is exactly what I had in mind, apart from the fact I'll be doing it in STL. I don't like the idea of using a filter, because I think that's unnecessarily complicated for anyone following me.

I want to reinitialise the DB to zero after an alarm anyway, although the rest of the time I'll just be wrapping the index round as in a FIFO. 256 values represents a bit more than half a shift's production, so I want them to have enough time to do something without having a alarm coming up once a minute, but I don't want to let them forget it altogether either.

Cheers

Roy

Edit: I was busy typing as Alaric posted. That takes me a long way back, I'd forgotten that formula. I still think the simpler loop is adequate and more easily understood though.

By the way Peter, I'm old enough that using SLW and SRW etc. to multiply and divide by a factor of 2, is automatic, I do it without thinking. So much for keeping things simple for those coming behind me!

Last edited by RMA; August 17th, 2007 at 11:31 AM.
  Reply With Quote
Old December 4th, 2007, 11:15 AM   #7
garyesmith2000
Member
United Kingdom

garyesmith2000 is offline
 
Join Date: Jul 2007
Location: west yorkshire
Posts: 19
Do you mean using the LPF block on the logix5000 ?
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Need Advice - Running Average Calculation sbman LIVE PLC Questions And Answers 24 March 30th, 2010 09:18 PM
STEP7 Array initial values. JesperMP LIVE PLC Questions And Answers 9 April 17th, 2007 07:32 AM
Step7 - Is it possible to store Actual Values from a DB in a normal (Text?) file RMA LIVE PLC Questions And Answers 15 December 13th, 2006 11:11 AM
Simple Running Average Implementation with Ladder Logic? blw2k1 LIVE PLC Questions And Answers 5 December 1st, 2005 01:21 PM
STEP7 UDTs and initial values. JesperMP LIVE PLC Questions And Answers 44 April 13th, 2005 03:34 AM


All times are GMT -5. The time now is 05:01 AM.


.