advertisement
from the for/while loop in ladder logic department...
implementing for/while loop with ladder programming
PLCs and related questions. topic
Posted by M Divakar on 9 October, 2003 - 5:02 pm
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).


Posted by Curt Wuollet on 10 October, 2003 - 5:38 pm
Huh?

For/next or While/do, but For/While?

Regards

cww


Posted by Jamie Downs on 12 October, 2003 - 8:31 pm
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.


Posted by Jeremy Pollard on 20 October, 2003 - 6:50 pm
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


Posted by kishorereddyj on 12 October, 2003 - 8:33 pm
I beleive that you can make use of counters (available with ladderlogic) to simulate this loop structures..


Posted by Anonymous on 13 October, 2003 - 8:54 am
If you are using a CLX controller than implement your for/while loop in ST language rather than ladder.


Posted by T. Connolly on 13 October, 2003 - 9:17 am
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;


Posted by Anonymous on 13 October, 2003 - 9:24 am
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.


Posted by Bob Peterson on 14 October, 2003 - 12:33 pm
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.


Posted by Eugene on 26 January, 2013 - 11:07 am
> 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)?

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


Posted by Juan De los Santos on 20 October, 2003 - 10:59 pm
Just use structured text. Version 11.11 have it included as an alternative programming language.


Posted by Anonymous on 14 October, 2003 - 7:50 am
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.



Posted by sivakumar s on 14 October, 2003 - 8:38 am
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 !



Posted by Bob Peterson on 14 October, 2003 - 12:14 pm
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

Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2014 Nerds in Control, LLC. All rights reserved.

Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.


Fortune
Real Programmers don't write in PL/I. PL/I is for programmers who
can't decide whether to write in COBOL or FORTRAN.
Advertise here
Advertisement
our advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive