SCL Array Indexing in Step-7

cbattles

Member
Join Date
Dec 2008
Location
Ellenton, FL
Posts
8
Help!! From reading previous threads, I know that the best way to index an array is using SCL. I have the SCL editor, I'm just not sure where to start. Here is the task I need to accomplish...

Using an array of 180 Real values, I need to move a flow rate into an incremental array value every 5 seconds. The array values will be checked to determine what the "max" flow rate is for a given 24-hr period, resetting all values to zero at midnight and re-starting the process.

If someone could get me started, I should be able to figure it out. Any help from you SCL experts would be greatly appreciated.
 
Here's a short example that calculates the average value of an array.

Code:
FUNCTION_BLOCK FB10
VAR
Range:INT;	
Index:INT;
Sum:REAL;	
Average:REAL;
Data :ARRAY[1..50] OF REAL;	
END_VAR
BEGIN
Range:=10;
Sum:=0.0;
FOR Index:=1 TO Range DO
Sum:=Sum+Data[Index];
END_FOR;
Average:=Sum/Range;
END_FUNCTION_BLOCK
 
I think you made a slight miscalculation on the size of array needed...

One value every 5 seconds =
12/minute
720/hour
17280/day

Of course, you don't need an array at all to capture a peak value. If NewValue > PeakValue then PeakValue = NewValue

But you're probably doing something else entirely that just isn't mentioned in the post...
 
Update - I think I almost got it (thanks to your help)!

See code below... it compiles OK. Taking a flowrate reading every 5 seconds for 15 minutes. Then finding the max. and average of those values. I'm not sure how to "zero" out the array after the 15 minutes. Any ideas??


FUNCTION_BLOCK FB3
TITLE = 'MAX RECHARGE PRESSURE'
VAR_INPUT
COUNT_UP: BOOL;
MIDNIGHT_RESET: BOOL;
FLOWRATE: REAL;
END_VAR
VAR_OUTPUT
MAXFLOW: REAL;
AVERAGE: REAL;
END_VAR
VAR_TEMP
// Temporary Variables
END_VAR
VAR
COUNT: INT;
RANGE: INT;
FLOWTEMP: REAL;
TIME1: TIME_OF_DAY;
INDEX: INT;
SUM: REAL;
DATA: ARRAY[0..179] OF REAL;
END_VAR
BEGIN
IF COUNT_UP THEN
DATA[COUNT]:=FLOWRATE;
IF DATA[COUNT]<FLOWTEMP THEN
FLOWTEMP:=DATA[COUNT];
END_IF;
IF FLOWTEMP>MAXFLOW AND FLOWTEMP <> 10000 THEN
MAXFLOW:=FLOWTEMP;
END_IF;
COUNT:=COUNT+1;
END_IF;
IF COUNT>179 THEN
COUNT:=0;
END_IF;
IF COUNT=0 THEN
FLOWTEMP:=10000.0;
END_IF;
IF MIDNIGHT_RESET THEN
MAXFLOW:=0.0;
END_IF;
RANGE:=180;
SUM:=0.0;
FOR INDEX:=1 TO RANGE DO
SUM:=SUM+DATA[INDEX];
END_FOR;
AVERAGE:=SUM/RANGE;
END_FUNCTION_BLOCK
 

Similar Topics

Hello I wanna know if are some function to check what is the max value from an array or if I have to loop the array to compare all numbers to get...
Replies
4
Views
1,891
Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,071
Hi guys. I have a challenge that I'm struggling with and I can't help thinking there's a really easy solution. I want to move a series of...
Replies
18
Views
5,845
Hi, I just can't wrap my head around this one so all ideas and comments are more than welcome. My SCL programming skills are beginner level. What...
Replies
3
Views
1,936
Hello I am writing a small code, I have two problems populating the arrays? I am getting an error Non-existing identifier. I also need help to...
Replies
12
Views
5,927
Back
Top Bottom