Calculate percentage of last 500 parts.

Well I would create a FIFO that contains 500 data points. Each Data point will be a value of 1 if the part is good or 0 if the part is bad.

Each time you check a part as good or bad you would then take your 500 data point FIFO sum its data and divide by 500.

Now you have a rolling average.

One warning, when you do your divide function you should put a greater than zero condition. PLC's do not like to devide into zero, this usually causes a math error.
 
A SLC will only allow 128 elements in a FIFO. Extending the FIFO across files could get hairy. You could use a 500 bit shift register (BSL instruction) where a set bit represents bad parts. Then keep a running sum of the bits. Don't count bits. When a 1 is shifted in then increment a counter and decrement it when a 1 is shifted out.

See attached. It needs some spit and polish but hopefully it will get you started.

A10042011-1.JPG
 
Last edited:
A SLC will only allow 128 elements in a FIFO. Extending the FIFO across files could get hairy. quote]

Forgot about that... but I have an answer. You can roll your own FIFO. I hve attached a program where I built one a few years back. If you look in ladder 10 the FIFO starts on rung 16 and goes thru rung 25.

The GRT that starts the FIFO is only true for 1 scan. This is important to prevent double coping of data.

Since I am doing a copy function 10 words in length I use 1000 words in my data table. Since you can only put 250 intergers to a data file I had to use 4 data files.

The only limitation to this roll your own FIFO is memory space.

Note: this is just another option. I believe Alaric's solution is easier to do and does not require near as much code. (I have it in my sample library now :geek: ).
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,083
Good morning, I have a question. I don't know much about ST yet I would like to calculate the average number of products per hour. how do I do...
Replies
22
Views
2,995
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,127
I want to calculate the energy consumed from instantaneous power. Can this be done using the TOT block with timebase set to Hour?
Replies
2
Views
707
Hi everyone, I have to calculate the length in millimeters of a glass that enters a transport (I don't know the speed yet) through a barrier...
Replies
15
Views
3,483
Back
Top Bottom