for loop in structured text

Code:
//pseudo

timer.pre := timeToRun; //
call timer instance;
timer.timerEnable := true;

if timer.dn
then
           copy element[i] to someplace;
           i := i+1 mod 20;     
           timer.timerEnable := false;
end if

That will copy 20 elements (0 to 19) over and over again.
 
Last edited:
Code:
if iLoopCounter > 20 then
    iLoopCounter:=0;
end_if;

if testTimer.DN then
    startBit:=0;
    testTimer.TimerEnable:=0;
    testTimer.Reset:= 1;
end_if;

testTimer.PRE:= 5000;
TONR(testTimer);

if NOT startBit then
    startBit:=1;
    COP(arrayOfStrings[iLoopCounter], singleString, 1);
    iLoopCounter:= iLoopCounter + 1;
    testTimer.Reset:= 0;
    testTimer.TimerEnable:=1;
end_if;

Enjoy!
 

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,510
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,725
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
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...
Replies
8
Views
2,876
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
Back
Top Bottom