Hi,
I have an analog signal to be filtered and shown on a MP377, but it is not enough to do it by changing the polling time, it should take the average value of, let's say, the last 10 readings.
I can not find any Siemens block in the libraries, do you know anyone?
Thanks
[?]: FC for average value
-
- Posts: 104
- Joined: Sat Jun 13, 2009 12:25 pm
- Location: Europe
Re: [?]: FC for average value
Hi,
Try this code (i am not the writer of this code below):
You can also go http://www.oscat.de/ and upload a complete Siemens S7 library.
Best regard
Try this code (i am not the writer of this code below):
Code: Select all
FUNCTION_BLOCK FB401
VAR_INPUT
Data_in : REAL;
Number_of_read : INT;
END_VAR
VAR_OUTPUT
Average_result : REAL;
END_VAR
VAR
array_of_read : ARRAY [0..100] OF REAL;
i : INT;
y : INT;
z : INT;
add_result : REAL;
END_VAR
IF Number_of_read = i THEN
FOR y := 0 TO Number_of_read BY 1 DO
add_result := add_result + array_of_read[y];
END_FOR ;
Average_result := add_result/Number_of_read;
i := 0;
add_result := 0.0;
FOR z := 0 TO Number_of_read BY 1 DO
array_of_read[z] := 0.0;
END_FOR ;
END_IF;
array_of_read[i] := Data_in;
i := i+1;
END_FUNCTION_BLOCK
Best regard
-
- Posts: 103
- Joined: Fri Aug 31, 2007 8:17 pm
- Location: Europe
Re: [?]: FC for average value
Cant compile it, there is 3 mistakes
-
- Site Admin
- Posts: 1122
- Joined: Wed Sep 06, 2006 12:03 pm
- Location: CIS
Re: [?]: FC for average value
What are the errors? Tried to compile it with SCL 5.3 SP6, 0 Errors 0 Warnings.Scarch wrote:Cant compile it, there is 3 mistakes
-
- Posts: 103
- Joined: Fri Aug 31, 2007 8:17 pm
- Location: Europe
Re: [?]: FC for average value
Sorry, the mistakes were on my head
Thank you
Thank you