implementing for/while loop with ladder programming

M

Thread Starter

M Divakar

how to implement for/while loop using ladder logic programming especially using RSLogix 5000 software? i have for loops in statement list programming of Step7 (siemens).
 
J
Hello M Divikar

Ladder logic in PLCs iterates continuously so it is easy to implement something like a for while loop.
If you need to see an integer incrementing, just add 1 to a register in the ladder logic.

Jamie.
 
K

kishorereddyj

I beleive that you can make use of counters (available with ladderlogic) to simulate this loop structures..
 
If you are using a CLX controller than implement your for/while loop in ST language rather than ladder.
 
T
I am assuming you do not want to use ladder.

In the project tree (on the left hand side of your screen) open the Main Task. Right Click the Main Program and select New Routine. Give it a name and choose STURCTURED TEXT as the type. You will call this routine with a JSR in your Main Routine. Alternatively, you could create a new task, schedule the task and make the main program of that task a STRUCTURED TEXT program.

You can choose three different kinds of loops: FOR DO, WHILE, REPEAT UNTIL. The syntax of each is as follows. Go to www.ab.com/manuals and download the 1756-RM006B-EN-P manual. Appendix B has ST programming information.
------------------------------
FOR count := initial_value
TO final_value
optional { BY increment If you don’t specify an increment, the loop increments by 1.
DO
<statement>;

optional
IF bool_expression THEN
EXIT; If there are
conditions when you want to exit the loop
early, use other statements, such as an
IF...THEN construct, to condition an EXIT Statement.
END_IF;

END_FOR;
-------------------------------------
WHILE bool_expression1 DO
<statement>; statements to execute while bool_expression1 is true

optional
IF bool_expression2 THEN
EXIT; If there are conditions when you want
to exit the loop early, use other satements,
such as an IF...THEN construct, to
condition an EXIT statement.
END_IF;

END_WHILE;
--------------------------------------
REPEAT
<statement>; statements to execute while bool_expression1 is false

optional
IF bool_expression2 THEN
EXIT; If there are conditions when you
want to exit the loop early, use other
statements, such as an IF...THEN construct,
to condition an EXIT statement.
END_IF;

UNTIL bool_expression1
END_REPEAT;
 
This is essentially impossibly. The only chance that you have is to write a subroutine, and call it as many times as you need from the main program. This is quite cumbersome. My suggestion, stick with Siemens or Modicon that support the text languages as well as ladder logic.
 
RSlogix 5000 in ladder logic does not offer for/while loops. in fact, i am not familiar with for/while loops used in ladder logic. you have to make use of counters and counter resets. For a FOR loop, when counter.DN is false, you can execute the rungs for the true condition. You can use structured text in RSlogix to create for/while loops. When counter.DN is true, you can stop executing it.

 
S
Athu rombo easy. for loop ley oru I ai increment pannitey iru ! apparum while conditionley athai check pannu. if true nna enna pannanumo athai pannu. illai false nna appo ennaa pannanumo athai pannu ! avalavu thaan matteru !

 
B
I have done so in RSLogix500 using a simple jmp/lbl pair. set your index before you enter your little for next area, than your first instruction would be the label. at the end of all the things you want to do inside the loop
increment the index. if the current index value is less than the ending index, jmp to the lbl. very simple and works very well. just make sure you set the indexes up correctly.

Bob Peterson
 
B
It's actually very easy. I'd be willing to send you the code if you don't believe it. Way too many people have forgotten that these "higher level" constructs are just tools, and you can create the logical construct w/o having to have it handed to you on a silver platter.
 
J

Jeremy Pollard

Just be careful of the watchdog timers.... looping can take you down hard... just like the Cubs are going to do the Marlins ( I write this in the 4th inning :) )

If timing isn't an issue the concept can be had by using scans as the loop construct.

Cheers from: Jeremy Pollard, CET The Crazy Canuckian!
Integration and Automation Training, Consulting, and Software
http://www.tsuonline.com
 
J

Juan De los Santos

Just use structured text. Version 11.11 have it included as an alternative programming language.
 
> It's actually very easy. I'd be willing to send you the code if you
> don't believe it. Way too many people have forgotten that these "higher level"
> constructs are just tools, and you can create the logical construct w/o having
> to have it handed to you on a silver platter.

I would be very interested to see your implementation. Could you post it here in text format (Boolean expressions)?

<b>Moderator's note:</b> We don't usually post requests to threads that are 10 years old. Bob Peterson is still a regular participant in this forum.
 
Top