running average length

plcnewbie

Member
Join Date
Jan 2005
Location
Missouri
Posts
220
This is with 500
I use an eye to see when a product is in front of it which triggers a RTO and then when the eye is uncovered moves the value into and integer file. Thereby getting its length based on time.
What I would like to do is get the average of the last 10 products.

Does anyone have any code for doing this in 500? I am not very good with arrays and shift registers but I assume I need something similar here, correct?

Thanks a lot
 
The simple thing would be use a counter with the RTO, count to 10 then MOV the RTO ACC to another register and then reset both, you can then divide the time by 10 to get an average value and use that to get appropriate average length.

Example: RTO is 1200 seconds after 10 counts, that would be an average of 120 seconds...if 1 sec equals 1 inch then average length would be 12 inches.
 
I agree that would be the easiest and I had that and was resetting at 10 counts but then I would have to start a new average again. I really would rather have a running average. I think I? have to make an array and shift in and the oldest one out but have not quite figured it out yet.


I thought for sure someone had something like this canned.
 
One of the easiest ways to do something like this is to first allocate 10 integers (ie N7:0-N7:9). I would then use a counter that counts 0-9. Every time you get a new length, increment the counter and move to an integer at the count offset.

In other words, when count starts at 0, move the value to N7:0, when count is 1 move to N7:1 etc....

Now make sure that when count goes over 9, you reset it to 0.

You are now free to do any math with the allocated integers, but remember, any averages may be off for the first 10 cycles unless you pre-populate the integers.

Make sence?
 
one more thing. How do I adress int he mov instruction to move to the correct place. I tried n+ct.acc but that wont work. How owuld I address for this?

Thanks
 
plcnewbie said:
one more thing. How do I adress int he mov instruction to move to the correct place. I tried n+ct.acc but that wont work. How owuld I address for this?

Thanks

One way would be to have a compare that says if "c5:1.acc = 0"
the next line would be c5:1.acc=1....

get it?
 
yes I get it I thought that would be long. I guess it will be, but that was my original idea and I will use it if that is the easiest and shortest. I was just trying to do it in few rungs as possible. Thanks again
 
The most straight-forward way is using indirect addressing. Assuming you are using N7:0 - N7:9 for your averaging array and N7:10 for the new measured value the syntax would be:


MOV N7:10 #N7:[C5:1.ACC]

You may not need the #. It's been a while since I've had to do any SLC stuff and the SLC and PLC5 tend to blend on me.

Keith
 

Similar Topics

I am working on a program in Cscape to take a pulse input from a flow meter and output an average of the last 5 minutes of flow and total flow to...
Replies
1
Views
581
I need to keep a running pass/fail yield of the previous 5,000 parts produced. I have used this formula before to calculate average: AvgValue =...
Replies
6
Views
2,188
Just updated my customer from 984 to Quantum. We have an analogue I/P which jumps around somewhat and I need to do a running average on it. I seem...
Replies
15
Views
4,621
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...
Replies
6
Views
4,091
I am trying to implement a running average function using ladder logic in an AB PLC5. I have a digital input that pulses. Every minute I need to...
Replies
5
Views
21,478
Back
Top Bottom