[?]: FC for average value

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Scarch
Posts: 103
Joined: Fri Aug 31, 2007 8:17 pm
Location: Europe

[?]: FC for average value

Post by Scarch »

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
dehell
Posts: 104
Joined: Sat Jun 13, 2009 12:25 pm
Location: Europe

Re: [?]: FC for average value

Post by dehell »

Hi,
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
You can also go http://www.oscat.de/ and upload a complete Siemens S7 library.
Best regard
Scarch
Posts: 103
Joined: Fri Aug 31, 2007 8:17 pm
Location: Europe

Re: [?]: FC for average value

Post by Scarch »

Cant compile it, there is 3 mistakes
Schtiel
Site Admin
Posts: 1122
Joined: Wed Sep 06, 2006 12:03 pm
Location: CIS

Re: [?]: FC for average value

Post by Schtiel »

Scarch wrote:Cant compile it, there is 3 mistakes
What are the errors? Tried to compile it with SCL 5.3 SP6, 0 Errors 0 Warnings.
Scarch
Posts: 103
Joined: Fri Aug 31, 2007 8:17 pm
Location: Europe

Re: [?]: FC for average value

Post by Scarch »

Sorry, the mistakes were on my head

Thank you