siemens S7 -average of analog input

panthripu

Member
Join Date
Mar 2004
Posts
228
Hi
I am trying to find out , how to get an average of an analog input for 24 hours. I am interest to know the average of analog input value for the previous one day. How can i do it ?o_O
 
Hi
I am trying to find out , how to get an average of an analog input for 24 hours. I am interest to know the average of analog input value for the previous one day. How can i do it ?o_O

1.first convert input into real value
2. add A(input value)+B(output value) and store it in B(output value)
3.put timer for 24 hours, when timer output enables divide the B(output value) with 24
the output value of the divide is the avg value for a day
 
Depending on your process how often would you need to sample the analog value to get a good result? The previous posters example just sample the analog value once an hour.. If you need to sample each second to get a good reading then I would do it a little bit different.. Will post an example soon..
 
Use this in for example ob100 once every 10scans (if ob100 is set to 100ms)

This samples a analog value each second and the output is a rolling 24h average..

The code is just an example there can be some errors..

Code:
FUNCTION_BLOCK fbAnalogSample_24h

VAR_INPUT
    rAnalog_value : REAL;
END_VAR

VAR
    rAnalog_values_seconds : ARRAY [1..60] OF REAL;
    rAnalog_values_minutes : ARRAY [1..60] OF REAL;
    rAnalog_values_hours : ARRAY [1..24] OF REAL;
END_VAR

VAR_TEMP
    seconds : INT;
    minutes : INT;
    hours : INT;
    sum : REAL;
    i : INT;
END_VAR


VAR_OUTPUT
    rAnalog_roll_avg_24h : REAL;
END_VAR

BEGIN

//This function block needs to be called once every second preferably in a timed interrupt (for example call it in ob100 but only once per 10scans)

seconds := seconds + 1;
rAnalog_values_seconds[seconds] := rAnalog_Value;
IF seconds >= 60 THEN
    seconds := 0;
    minutes := minutes + 1;
    sum:=0.0;
    FOR i:=1 TO 60 BY 1 DO
        sum:=sum + rAnalog_values_seconds[i];
    END_FOR;
    rAnalog_values_minutes[minutes] := sum/60.0;
        IF minutes >= 60 THEN 
            minutes := 0;
            hours := hours + 1;
            sum:=0.0;
                FOR i:=1 TO 60 BY 1 DO
                    sum:=sum + rAnalog_values_minutes[i];
                END_FOR;
            rAnalog_values_hours[hours] := sum/60.0;
            sum:=0.0;
                FOR i:=1 TO 24 BY 1 DO
                    sum:=sum + rAnalog_values_hours[i];
                END_FOR;
            rAnalog_roll_avg_24h:=sum/24.0;
                IF hours >= 24 THEN 
                    hours := 0;
                END_IF;
        END_IF;
END_IF;

END_FUNCTION_BLOCK
 
1.first convert input into real value
2. add A(input value)+B(output value) and store it in B(output value)
3.put timer for 24 hours, when timer output enables divide the B(output value) with 24
the output value of the divide is the avg value for a day

I don't see how this would work. When are you doing (1) and (2) ?
Like I read this it's undetermined so it happens every scan. The value of B is going sky high in no time, if not hitting the limits.
And like bara_hence said.. evaluating every hour is not really a good average...
 
I hate threads like this. Not enough info

1.first convert input into real value
Why, why not simply add up the counts and average and then convert to float?
Adding counts to a 32 bit unsigned integer means you don't lose resolution as the sum gets bigger like what happens with REALs.

Nothing is said about what 24 hour period is being covered. It it is from midnight to midnight then simply add up all the counts and convert to float as the total is divided by the number of samples. A 32 bit unsigned integer can handle this if the same interval is a second.

If this number needs to be updated every 1 hour then use 24 counters where on counter is reset every hour. This is brute force and stupid simple.
 
Peter is right even if a worst scenario with a raw analog value of 27648 * 60s * 60min *24h the value is small enough to fit in a DINT the code would be dead easy to..

Just sample each second and after 24h divide the value and put the result in a register then clear the DINT and start the next 24h period..
 

Similar Topics

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...
Replies
5
Views
8,971
I want to take a sample every minute from the analogue value, and after 24h calculate the average value. Does Siemens has a standard SFB for this...
Replies
4
Views
4,833
Hi everyone, I am an omron plc tec , lately I came across a siemens s7 200 cn plc . Can someone help me regarding the software required and...
Replies
26
Views
439
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
106
Hi, I have PLC S7-1200 and switch XC-208 and Iam trying to implement this SNMP library: SIOS I am not sure, what I am doing wrong, but there is...
Replies
3
Views
113
Back
Top Bottom