OR Loop? - Structured Text

eeng

Member
Join Date
Sep 2016
Location
New York
Posts
21
Hi guys,

I have a basic problem...when the start relay is activated...I want my derived function block to load a set of values to an array "InitialArray"....the values of that array will then be sent through a process and come out different on the other side and then they would be loaded to a new array...lets call it "FreshArray".

My problem is this...I want the values from that "FreshArray" to be loaded back into the "InitialArray" to eventually optimize the values.

This is what I've tried so far.

If (NextRound) THEN
InitialArray:= FreshArray;

ELSIF

InitialArray:=InitialParamters;
END_IF;

Problem is...while this does work..a second later the new values are overwritten by the initializing values..

So how do I make it OR? A OR B?

This is on a M340 Schneider PLC.

Thanks in advance.
 
I'm only a recent user of M340 so this may or may not work

If (NextRound) THEN
InitialArray:= FreshArray;
NextRound := 0;
ELSIF

InitialArray:=InitialParamters;
END_IF;

To initiate the loop again change the state of NextRound to true.

Steve
 
If (NextRound) THEN
InitialArray:= FreshArray;
NextRound := 0;
END_IF

IF init THEN

InitialArray:=InitialParamters;
init:=0;
END_IF;


it would be easier code with FBD language
 
Thanks for the replies guys, I see how that would work. Although I forgot to mention, that the "START" relay...or in Lares case "INIT" flicks on and off 6 times to write THEN mutate each set for the 6 arrays, and once a counter hits 6. It does the rest of the process with the parameter sets. This is my actual code for initialization.

Code:
IF RE(Start) THEN

FOR p:=3 TO 9 DO
Population[p][1]:=25.0;
Population[p][2]:=10.0;
Population[p][3]:=0.0;
Population[p][4]:=-10.0;
Population[p][5]:=-25.0;
Population[p][6]:=INT_TO_REAL(p);
Population[p][7]:=ABS(CV-SP);
END_FOR;

I guess I'll have to modify that overall process.
 
Seems to me it should be Else, not ElsIf, as there is no question for the ElsIF, thus making it happen...?
 
I think I did give that a shot too. Will confirm when I get home from work.

What confuses me though is for this code:
Code:
IF RE(Start) THEN

FOR p:=3 TO 9 DO
Population[p][1]:=25.0;
Population[p][2]:=10.0;
Population[p][3]:=0.0;
Population[p][4]:=-10.0;
Population[p][5]:=-25.0;
Population[p][6]:=INT_TO_REAL(p);
Population[p][7]:=ABS(CV-SP);
END_FOR;

When I do hit the start relay...it doesn't cycle through 3 to 9...it only cycles to the next number when the start relay is turned off and on again. This is all programmed in a DFB.
 
Last edited:
Lare & Nephets. Big thank you for your help...while I didn't do it in structured text (used ladder logic and relays) thanks for putting me in the right direction in terms of switching sections of code off. I was so engrossed with Structured Text and coding that I forgot about simple ladder logic.
 
Another quick question guys, how do I get the x and a FOR loops...to loop again for every increment of i?

I tried a repeat until...but couldn't seem to set it up correctly.
Code:
IF (ENABLE) THEN

FOR i:= 3 to 9 DO
FOR x:= 1 to 3 DO
FOR a:= 1 to 3 DO
NewPop[i][x]:=import[1][a];
END_FOR;
END_FOR;
END_FOR;
 
IF (ENABLE) THEN


FOR i:= 3 to 9 DO
FOR j:= 1 to 3 DO


NewPop[j]:=import[1][j];
END_FOR;
END_FOR;


END_IF;
 

Similar Topics

Hey all, Studio v20.05 Background. We are piggy backing another system to record attributes for product travelling down the line and several...
Replies
21
Views
3,514
I am trying to learn structured text on the controllogix platform and have managed to fault the processor by creating an infinite loop. My problem...
Replies
21
Views
3,734
In structured text, can you decrement in a for loop? I need to shift an array and I can either use while loop or if decrement in for loop works...
Replies
6
Views
4,968
Hello Everyone: I have been able to read value via canopen interface using ADS protocol. Actually my Structured Text Programming is weak. I can...
Replies
5
Views
3,984
I have to write some rslogix 5000 code that will loop through an array, copy each element in the array one at a time to a separate tag and set a...
Replies
19
Views
31,384
Back
Top Bottom