Basic question about Routines

passwordg

Member
Join Date
Aug 2011
Location
South Carolina
Posts
224
I have this test program with 3 routines:-
Rt_1, Rt_2, Rt_3 with Rt_1 - the main routine.

Rt_1 calls 2 & 3 using JSR as:

Rung 0
------------JSR Rt_2-----
Rung 1
------------JSR Rt_3-----
Rung 2
End

Will the program end execution after RT_3 ?

Rt_2 collects product data and Rt_3 then processes the data.
This needs to repeat over and over as multiple products are scanned one by one.

I want it the program to keep running and go back to Rung 0 after Rung 1 and start over.
How can I do this ?

If I put a JSR to RT_2 inside Rt_3, I feel it might cause the watchdog to run out due to an endless loop.
Someone at work suggested that the program automatically loops back anyways.

What is the better way to go about this please ?

ClipboardX.jpg
 
Last edited:
Unless you take extra steps to shut down the scan, most PLCs will repeat the main ladder program over and over again automatically forever and ever.

So, assuming your PLC (controllogix or compactlogix?) follows that convention, then your program Rt_1 will run over and over again, each time it runs, it will run the JSRs to the subroutines and run them too.

If you put a JSr to Rt_3 inside Rt_2, and had a JSR Rt_3 still programmed in the Main Rt_1, then the subroutine Rt_3 would get called twice per main PLC scan, but this should not cause an endless loop.

What software are you using?
 
As your other posts pertain to AB PLCs I'll presume this does also.

The PLC scan is setup to automatically start back at the beginning. You don't need to do anything special.
 
Unless you take extra steps to shut down the scan, most PLCs will repeat the main ladder program over and over again automatically forever and ever.

So, assuming your PLC (controllogix or compactlogix?) follows that convention, then your program Rt_1 will run over and over again, each time it runs, it will run the JSRs to the subroutines and run them too.

If you put a JSr to Rt_3 inside Rt_2, and had a JSR Rt_3 still programmed in the Main Rt_1, then the subroutine Rt_3 would get called twice per main PLC scan, but this should not cause an endless loop.

What software are you using?

Using RSLogix 5000
Sorry, I meant call routine 2 from main and call routine 3 from Routine 2, Then call back routine 2 from routine 3

Of course now I know there's no need of that. I'll test what happens when I do that on the weekend.
 
Actually, there may be a detail you've overlooked.

One of your routines (probably Rt_1) must be declared as the main routine of program. This is done on the configuration tab of the program properites.
 
Actually, there may be a detail you've overlooked.

One of your routines (probably Rt_1) must be declared as the main routine of program. This is done on the configuration tab of the program properites.

mellis hit the nail on the head !

the way your picture shows, absolutely NO code will run in that program at all, because there isn't a "Main Routine" declared.

You will get a warning about this when you verify the controller, or attempt to do a download
 

Similar Topics

Hi everyone, I am fairly new to programming subroutines and interrupts. I am used to dumping evrything on the main program. But with the Siemens...
Replies
6
Views
8,927
Hi all, I have a noob question regarding data handling from sensors. I understand configurations and I/O mapping sensor input/output variables...
Replies
2
Views
232
GE 90-30 using ME 6.0 - Newbie question... Let's say on rung 10 I set a coil (S) with a one-shot. Input to coil drops out, but coil stays...
Replies
30
Views
11,235
Dear experts, i have pretty basic/ dump question, can someone help me to figure out how to read/ what is this? i assume it is solenoid vavle...
Replies
4
Views
1,070
Create ladder logic program to count 4 on pulses (not using a counter) and then turn the output on if the on pulse input signal can look like the...
Replies
105
Views
36,770
Back
Top Bottom