Sign in to follow this  
Followers 0
Criticore

RsLogix 5 execution times

4 posts in this topic

Hello, all I am writing some logic that gives me the average and standard deviation of some data sets between 200 to 300 points However, I am running into some watchdog timer faults.

The processor is a PLC5/40E rev B.

My first revision used a jump and a counter to iterate through the points and do the math but this caused faults when the set was too big. 

I ended up settling on a looong list of the data points that jump to the top of the ladder file every 10 points. Still not great 

The manual says I cannot use STX files as it requires revision C or greater.

Can anyone make any suggestions for improving the time spent in this routine?

Edited by Criticore

Share this post


Link to post
Share on other sites

I would look at using a FAL instruction for your calculations and setting the mode to the number of iterations you want to perform each scan. If for example you set the mode to 50 your calculations could be completed by the 6th scan.

Share this post


Link to post
Share on other sites

in my opinion the most efficient way is to not move data in array, just overwrite ONE element (ring buffer).

optionally this also allows you to easily get instant average any time (even when averaging just started and has few elements).

but to answer your question... why sum all 200-300 elements again and again every time new sample is obtained?

if your array is 200 element. your current average already contains sum of 199 correct values and we know exactly which value is to be updated (the oldest one)

and since we now know both the new sample value as well as the oldest one that is about to be discarded, we can compute average in just 2-3 simple operations. no need for fancy instructions and processing entire array.

basically average is simply:

Avg = (A1 + A2+ A3 + .... An)/N

but it can also be written as
Avg = (A1/N  + A2/N + A3/N ... An/N)

and you know the value of N

suppose element that is to be updated right now is A2 (index is i=2)

then new average is simply

Avg = (A1/N  + A2/N + A3/N ... An/N) - (A2/N) + (NewValue/N) 

 

or in a program, that would simply be

Avg = Avg + (newValue-A(i))/N

another nice thing about this is that it is platform independent since it only uses basic instructions that every controller has.

Share this post


Link to post
Share on other sites

You would still need to loop through the entire array to calculate the standard deviation each time the average changes. @Criticore how often are you needing to update these values?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0