BITS N BYTES

LOVE THE AVG[195] FUNCTION - BUT!?

7 posts in this topic

The AVG[195] function is a really useful BUT it seems that it only works with cycles of the PLC. In other words if I specify the maximum number of cycles as N=64=0040hex the average data becomes valid [R+1 bit 15 turn ON] after 64 cycles of te PLC. If the PLC cycle was 5 mSec I would expect to get a valid average after 320mSeconds. This does indeed work correctly. The data that I am averaging changes about every 3 to 4 seconds and when I try to apply the AVG instruction all data in the AVG data area R+2 to R+[2+64] is the same as the most recent Source value. In other words the S [source Word] always equals the R [Result Word]. I cannot find a way to have the average instruction update with a different timebase other than the PLC scan. Instead I am using a word shift register and averaging the contents, seems crude and more complex than AVG. Any words of wisdom/ideas how to use AVG with a user applied timebase for cycles?

Share this post


Link to post
Share on other sites
If I understand correctly you connected the AVG instruction unconditionally (as through always on bit). But you would like to take one sample every 3- 4 seconds I am relatively new to OMRON PLCs, but here is what I would try: I would setup a timer at 4 seconds and then every time the timer is done execute the AVG instruction and reset the timer. Hope this works

Share this post


Link to post
Share on other sites
atanats The AVG instruction will not work with a rising edge input it only works if the input is on. The first work area R+1 uses a Previous Value Pointer [bits 0 thru 7] to fill the data array. This pointer increments with each program scan if the instruction is ON. Once N cycles are complete the average value is determined when bit 15 of R+1 turns ON. I am trying to find a way to increment the pointer independently of program scan cycles!

Share this post


Link to post
Share on other sites
I have encountered the same problem with AVG. It would be far more useful if it would execute once on a rising edge. We could then use it for a running average at user defined sample rates. I suggest writing a function block. (and then post it here) Nibroc

Share this post


Link to post
Share on other sites
I'm current using an AVG instruction in an interrupt and this appears to work. I need to know the size of an ever decreasing roll so I sample 16 times a revolution the length of stock unwound. Each sample I multiply by 16 to give me the circumference. This was fine but I found occasionaly I had a spurious figure which knocked the whole equation out. So now I average it over the 16 cycles in which samples are being taken. Seeing that the AVG command performs every scan that passes it, I figured I'd take it out of regular scan. You could put this into a cyclic task that you could call each time you need it. Use a one shot connected to TKON to call it and on the last rung of this sampling/averaging task put a P_On contact connected to TKOF. This way you call the task once with the one shot and the moment that it has done what it has to you turn it off. Hope this helps Ben

Share this post


Link to post
Share on other sites

Hi,

I need to average values from analog input and I wanted have parameter with quantity of samples and set cycle time for data collecting.

I realized that AVG counts only every cycle.

Maybe you already made some FB - average function with parameters indicate above and you can public here?

Share this post


Link to post
Share on other sites

Posted (edited)

Hi

I wrote some code to calculate AVG value - what I needed. It can be useful for others. I attached FB for AVG calculation.

trigger is just a flag when calculation should be processing.

If last parameter - "work_without_timer" is OFF, "trigger" starts values counting with interval parametrized in parameter "TimeH_value" - BCD #1 = 10ms.

parameter "work_without_timer" =1 makes calculation when "trigger" changes values from 0 to 1 ( DIFU)

Parameter 'Samples Quantity" indicates how many samples are used for average value calculation

"D-Stack_memory" - indicates memory area used for store previous samples. &120 means that samples are in D120, D121, D122...D129 ("Samples quantity" =10) 

"Analog value"  is a value used for AVG calculation. Attached FB uses samples in WORDS WITHOUT SIGN

Output AVG_value is a average value from last 10 ( in this example) samples

AVG.jpg.67d6490e5951fd3eed066b0f21365d55

 

regards

AVG_calculation.cxf

Edited by pszczepan

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