Anyone pls help with Siemens Step 7 analogue signal Rolling average code/FB

matt_sd

Member
Join Date
Jan 2007
Location
Australia
Posts
96
Hello, I a would like to create a rolling average for a flowmeter signal.

I'm quite new to Siemens Step 7 - does anyone have a FB or can paste in some code for me that they have used before?

All I would like:-
INPUTS
analogue in,
no of samples,
scan time,

OUTPUTS
Analogue averaged out

I assume that the block will fill up an array (the array size will vary depending on the no of samples size, the
Analogue averaged out will be the samples added together divided by no of samples.

I have looked on Siemens site and they have an average function but not rolling average so will always average all samples..

Thank you

Matt


ps this code exists for S2 plc but dont have the software/know if it is locked.

This Siemens 200 PLCs's file is going to create a rolling average for the last 100 scans worth of an analog input.


http://plc2u.com/index.php/plc-code/s7200/average-of-analog-input


can anyone open the file and paste contents?
 
Last edited:
Network 1 // Divide the calculation result (VD0) by 99, store it in AC0 .
// This routine produces a rolling average of the last 100 scans worth of an analog input.
//
// VD0 holds the average of the last 100 scans of the analog input AIW0. VD0 is multiplied by 99 in preparation
// to be added to the new analog value.
//
//
LD SM0.0
MOVR 0.0, AC0
MOVR VD0, AC0
*R 99.0, AC0
Network 2 // Convert the raw analog value (AIW0) to a real number, add it to the calculation result (AC0), divide by 100, move to VD0.
// The analog input AIW0 is converted to a real number, added to the calculation result in the rung above,
// divided by 100 and moved to VD0.
//
LD SM0.0
MOVD +0, AC1
MOVW AIW0, AC1
DTR AC1, AC1
+R AC0, AC1
/R 100.0, AC1
MOVR AC1, VD0
Network 3 // Truncate the calculation result, move it to VD4, move the higher order word (VW6) to VW8.
// The result VD0 which is a 32 bit real number is truncated to extract the 16 bit integer value
// which is held in VW6 and is moved to VW8. Use VW8 in any other part of your program as the
// analog average.
//
// the response time of the value is dependant upon the scan time.
//
LD SM0.0
TRUNC VD0, VD4
MOVW VW6, VW8


Hope this helps.
I pasted the STL code from the attached project.
 
We really like this one. It takes x samples, throws out the high & low and averages the rest. I trigger it with a timed pulse which allows me to control the sampling rate. Or you could call it every scan and let the scan time control the number of samples. I also like the fact that it uses one FC and one DB for all of the analog samples. This code is very portable and we use it for all analog inputs.

The attached library will run as is. Just copy this program into a working hardware configuration & download to your PLC.

Thanks to Bob Harris for the "sample" code, and permission to share. :geek:
 

Similar Topics

im only starting learning plc... its just been a week that my class started... my prof gave this assignment. can someone help me answer this.. im...
Replies
6
Views
2,441
Hi, Does anyone here heard of SMC DP/YD from allen bradley, cat # is 150-DP-A360-NBD-T. I tried to browse thru` the internet & AB website but...
Replies
4
Views
3,439
we want to develop machine that could send error/monitoring message to our cellphone. does anyone ever try PLC to this kind of application and...
Replies
10
Views
4,353
I received an email from a student with the following code attached. This is supposed to control a floodgate system, and supposed to be written...
Replies
23
Views
779
does anyone have an install or know if/where i can download it for the following "ABB PS501 Control Builder Plus V2.3 " the software was a free...
Replies
2
Views
88
Back
Top Bottom