a-b sub routine

The A-B subroutine works similarly to most PLCs or other programming language subroutines. You can use it to divide your code up for simpler de-bugging, to make adding similar functions for multiple routines easy, and to bypass portions of the logic that don't require execution in every scan.

You create the new file by right clicking the File tab in the left side main menu. I always immediately add the RET at the end of the new file. You can add any logic or commands that you want in the subroutine file just like in the main program.

You call the subroutine by inserting a rung with the JMP command in the main program (File 2) or in any other subroutine that you want to call the new one. You can insert conditions in the JSR rung if you want to control when it is called.

I always try to give each subroutine a descriptive name by right clicking on the file and hitting Rename.
 
Last edited:
Ron Beaufort said:
my distinguished colleague has made a minor error

Thanks, Ron. Error corrected! Another example of diarrhea of the keyboard.

(Distinguished?? Maybe I should look into that Grecian Formula stuff??)
 
one other thing that might bear mentioning ... if you “nest” or “chain” your subroutines too many times (more than eight) you will fault the processor ... specific example:

suppose that a JSR in Ladder File #2 calls a subroutine in Ladder File #7 ...

and then a JSR in Ladder File #7 calls a subroutine in Ladder File #8 ...

and then a JSR in Ladder File #8 calls a subroutine in Ladder File #3 ...

and then a JSR in Ladder File #3 calls a subroutine in Ladder File #5 ...

well that’s FOUR jumps so far ... you’re only allowed eight before you start returning back up the chain ... if you keep on with the same “nesting” or “chaining” pattern shown above for more than eight jumps, then the processor will fault ...

on the other hand ... there is no limit to how many “jump-and-returns” you can do ... specific example:

suppose that a JSR in Ladder File #2 calls a subroutine in Ladder File #7 ... at the end of Ladder File #7, the scan returns to Ladder File #2 ...

and then a JSR in Ladder File #2 calls a subroutine in Ladder File #8 ... at the end of Ladder File #8, the scan returns to Ladder File #2 ...

and then a JSR in Ladder File #2 calls a subroutine in Ladder File #3 ... at the end of Ladder File #3, the scan returns to Ladder File #2 ...

and then a JSR in Ladder File #2 calls a subroutine in Ladder File #5 ... at the end of Ladder File #5, the scan returns to Ladder File #2 ...

in this case the subroutines are NOT “nested” or “chained” ... specifically, the scan returns to Ladder File #2 each time a “call” is completed ... as I’ve said, there is no limit to how many jumps of this type you can make ...

finally, this post gives some more information on how to learn more about this subject by inserting a “scan tester” in some experimental subroutines ... just remember that it was originally written for the larger PLC-5 processor family so some of the features mentioned might not apply to your system if you're using RSLogix500 ...
 
jump to sub routines suck.
I never could figure out why AB people liked them
so much, but then again they like ABs.
 

Similar Topics

We have a project that has all the routines viewable but not editable. I just want to force a bit high but cant do it. The only way to do so is...
Replies
2
Views
2,750
Good Morning , I'm merging another RS Logix 5000 PLC program ( CompactLogix ) into another . Everything is working great except this one...
Replies
9
Views
3,534
Hello everyone, I am new to ladder logic and am currently working on a small project where I might need some help. So I am modifying the sequence...
Replies
9
Views
2,352
Currently I am using a bunch of TON's and TOF's to start up and turn off a motor sequence. I created a sub routine for the manual sequence and I...
Replies
15
Views
4,675
Hi all, In the past I have use Sub Routines more as a organizational tool for my programs than anything else. I would just put things into nice...
Replies
6
Views
2,528
Back
Top Bottom