gator461
  •  gator461
  • 51.99601% (Neutral)
  • Newbie Topic Starter
2020-04-29T22:38:15Z
i just had a plc course where they explained sbr and jsr and showed demo of operation but never explained how to turn a program into a sbr. i just searched through your site and did not find anything except brief definition and short explanation in Help. i notice the traffic light scenario has to be done in sbr's. could you please get me in the right direction
Guest
2020-04-29T22:39:03Z
Since you have posted this in the RSLogix500 forum I will answer this from the SLC500/micrologix point of view. Most of this will pertain to any AB processor.

The SLC has one program file that is scanned by default and that is program file 2. As you have mentioned, we recommend separating any PLC program into program modules or subroutines. To have those other program files scanned by the processor you must tell it to jump to them - thus the JSR or jump to subroutine command. If your total purpose is to have the processor jump to the subroutine and return back to the rung after where it was called from when complete, then the JSR is all you need. You simply insert a JSR in your program and the only information you need to provide is the program file it will jump to. That is the most common use of JSRs and subroutines in the AB platforms. We would suggest that file 2 be filled with nothing but JSR's pointed at multiple program files (plus maybe some minor overhead logic). Once again, for that purpose thats all you need. The processor will jump to the program file required, go to the end and return back to scan the rung immediately after the calling JSR. No RET statement is necessary unless you want it to jump back before the end of the program file.

The SBR gets a little more complecated. The JSR instruction can pass parameters to the subroutine and the SBR is necessary if you intend to pass parameters and it should be the first rung in the program file you are jumping to. Frankly if you need to do this, you need to ask yourself if your program is over complecated. There may be a rare instance where this is necessary, but they should be rare.

Hope all this helps. Check out the vids on the the JSR instruction for more.
gator461
  •  gator461
  • 51.99601% (Neutral)
  • Newbie Topic Starter
2020-04-29T22:39:57Z
how do you turn (or save) project files into program files to be used as subroutines? the jsr only refers to a ladder number in program file
Guest
2020-04-29T22:40:52Z
Any program file can be jumped into with the JSR and become a subroutine (I doubt you can jump to the calling program file - I suspect that would cause problems). There is no special action that need be taken to the program file to "make" it a subroutine. If you create a program file then you can jump to it with the JSR and the processor will return to the calling program file automatically and begin operation immediately after the calling JSR.
Guest
2020-04-29T22:41:28Z
Mike,

You sent this to us via the contact page, but this sheds some light on what you were asking so I want to copy it here:

"i have tried my question through your forum but i guess you are not understanding my question or maybe im not clear enough. i understand everything you are saying about the soubroutine,. my question is: i have saved some projects into my documents on my C: drive. I want to put those projects into program files so i can make them soubroutines. I didnt save them or start them as a program file. can this be done or do i have to open a program file as ladder 3, etc and re enter my whole ladder all over again or can I import or direct my project file over to the program file and make it ladder 3?"

Now I get the misunderstanding. Keep in mind that the program routines in your PLC program are called program files. I can see where this could be confusing as they have nothing at all to do with the files stored on your computer. You cannot make a separate PLC program into a subroutine. All subroutines must be located in the same program as the calling routine. Hope this helps. Once again you might want to review the videos on JSR or jump to subroutine.

You dont have to enter your whole program over rung by rung, but you can open both programs simultaneously and copy and paste from one to the other.
gator461
  •  gator461
  • 51.99601% (Neutral)
  • Newbie Topic Starter
2020-04-29T22:42:09Z
Thanx for understanding my question. the copy and paste worked fine and got the program up and running