×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Sub routines

Sub routines

Sub routines

(OP)
Friends,
Can some please tell me the function of SUB ROUTINES and JSR as concerned with AB SLC 500 PLCs.

RE: Sub routines

I use subroutines in all by AB programs.
The main program is just a list of calls for the subs.

I group code by subroutine for easy trouble shooting later.

ie.  all code for machine 1 is in a subroutine for machine 1
     all code for machine 2 in in a subroutine for machine 2


You can also have each subroutine index a counter upon completion, then the counter value will help you know where you are at in the program if problems occur.

RE: Sub routines

You may want to consider using subroutines to minimise duplication of code. You can call the subroutine multiple time is one scan. Coupled with indirect addressing it can vastly reduce the amount of ladder but be careful it can be a nightmare to debug!

RE: Sub routines

We also use subroutines to minimize the duplication of code and for operation specific.  They can be very useful for putting certain operations aside from the rest of the code.  

ex.  Each station watches for a fault.  When a fault is encountered a subroutine is executed.  The subroutine sorts out the fault possibly using an offset for station identification for display on a panelview.

Remember that on fixed and SLC 5/01's you can only nest  4 subs deep and on 5/02, 03, 04's you can nest 8 subs deep. (Unsure about 5/05)
Ex.  main prog (file 2) executes #1 sub and it executes #2 sub and it executes #3 sub etc.  You must return in the same order.  Returning = #3 to #2 to #1 and back to file 2 (main prog).

As you see it can become very difficult.  But if used properly the Subroutine can be a great asset.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources