You are on page 1of 9

9/10/2017 Program Structure: How to Layout Routines Contact and Coil

Contact and Coil | Nearly In Control


Home
About
RSLogix 5000 Tutorial
TwinCAT 3 Tutorial
Patterns of Ladder Logic Programming

Mail
RSS

Sidebar

A A+ A++

Sponsored Links

Categories

.NET
Automation
Home Automation
Industrial Automation
Software
Uncategorized

Blogroll

ArchestrAnaut
Arduino Ladder Logic
Beckhoff Open Source (GitHub)
Got TwinCAT (ru)
Harold On Controls
Moms4mom
One Robotics Company Blog
SoapBox Automation
http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 1/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

SoapBox Core
TwinCAT 3.1 What's New

Meta

Log in
Entries RSS
Comments RSS
WordPress.org

Program Structure: How to Layout Routines


This is part of an RSLogix 5000 Tutorial.

So I just finished explaining how to layout your high level program structure. Now lets look at how to layout your
routines.

When we created our programs, we had the advantage that within the continuous task, we could order our programs
any way we liked, and the processor will actually execute them in that order, and the software will display them in that
order in the controller organizer. Anyone reading your program expects the logic to be scanned in the order that they see
it in the controller organizer, so this is great. However, when we get into laying out the routines, you have to be more
careful.

Each program has one Main Routine (you can tell because it has a 1 overlaid on the icon of the routine). When the
program starts, it only executes that one routine, and you have to jump to any other routines that you want to call. Of
course you can create a really elaborate program that jumps to one routine, and it jumps to another, etc., but the
readability really suffers. In almost every case, its better to make sure that the logic scans in the same order that your
routines are laid out inside the program. (If you want to make re-usable logic, I highly suggest looking into writing your
own function blocks).

You can name the routines in your program anything you want, as long as it starts with a letter and contains no spaces. In
the controller organizer, they will be listed alphabetically. Therefore, if you want to make them list in the same order that
they scan, you need to come up with a naming convention. Since you have to start the name with a letter, that limits your
options (you cant just use 001, 002, 003). In most cases, the first letter of the routine will group the routines into the
general type of routine, and the letters or numbers following that will order the routines within that group. Its typical to
add some kind of description to the name after that as well. This is best illustrated with an example:

Aa_Main
Ab_Modes
Ca_Arm_UpDown
Cb_Arm_ClampUnclamp
Cc_Slide
Cd_Bowl_Feeder
Ma_Axis1
Mb_Axis2
Pa_Part_Tracking
Sa_Sequence
Za_HMI

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 2/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

So in this case, Ive grouped my routines into A for housekeeping, C for discrete output control, M for motion axes, P
for part tracking, S for sequence logic, and Z for HMI logic. Within each group Im using a, b, c to give some kind of
ordering to the routines. Your Aa_Main routine has to be selected as the main routine for this program, and it must call
each of the rest of the subroutines in the same order as they are listed above (unconditionally). Anything else just
confuses the next person who has to decipher your program.

Going back to our WashingMachine program for a second:

Currently it has no routines at all. Right click on the WashingMachine program and select New Routine:

That will display the New Routine dialog box. Enter the routine name Aa_Main (highlighted) and click OK:

You will now see the new Aa_Main routine in the program:

However, the new routine isnt actually set as the Main Routine of the program. To do that, right click on the
WashingMachine program and select Properties:

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 3/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

That opens the program properties dialog for the WashingMachine program. Click on the Configuration tab, and choose
Aa_Main from the Main: drop down box (highlighted):

Click OK and youll now see that the Aa_Main program has a small 1 displayed on the routine icon (highlighted):

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 4/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

Ive gone ahead an entered some more routines into the WashingMachine program (Ive left out the Auto Sequence
routines for now):

Now you have to add logic to call each routines from the Main Routine. Double click on the Aa_Main to open it. Youll
see an empty routine:

Those small letter es in the left column means theres an error in that rung. It doesnt like that the rung is empty. Lets
start by adding a JSR (jump to subroutine) instruction. The easiest way to do this, if you have the rung highlighted, is to
type the letters J S R and then press enter:

As you can see, theres still an error. We havent filled in what routine were jumping to (see the question mark next to
Routine Name in the JSR instruction). Double click on the question mark and it will turn into a drop down list where you
can select from the routines youve already defined in this program:

Select the first routine after Aa_Main (in this case Ba_CycleSelection):

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 5/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

Now repeat the process for the rest of the routines in your program. You should end up with something like this:

Thats the basics of laying out your routines. In the next section Ill get into mapping your inputs.

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 6/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

16

4 comments

Mohd Sahli October 8, 2012 at 9:40 pm

Hi,

Good tutorial! Really helps a newbie like me to program properly. Keep up the good work

Dennis January 27, 2015 at 8:12 am

If you would like to use numbers to name your routine, it does allow you to do so if you start with an underscore
i.e. _010_Main

Rey PJ February 19, 2015 at 3:43 am

Thanks for lending a hand to newbies. Keep up the good work!

Oz January 31, 2016 at 2:37 pm

I like how you presented the information.


I teach PLC / DCS / Industrial networks, and you can always see a good instructor. That person lays the material
out like a book. Beginning, middle, and an end.

Good presentation.

Leave a Reply
http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 7/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

Name* Mail* (will not be published) Website


Your Comment

Submit Comment

Find it!

Search... Go

Theme Design by devolux.nh2.me

Tag Cloud

.net agile allen-bradley beckhoff complexity controlsoverload coordinated-motion copyright custom deep-
thoughts dry-principle estimation frustrations future g-scale garden-railroad helping hmi innovation internal-state
ladder-logic motion-control motivation plc productivity project-management quality review risk
rockwell-automation rslogix-5000 security sequencer shrinkwrap snap standards stuxnet troubleshooting tutorial
twincat vb6 vendors voting wiring x10
Archives

June 2017
April 2017
March 2017
February 2017
January 2017
April 2016
February 2016
January 2016
November 2015
October 2015
September 2015
May 2015

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 8/9
9/10/2017 Program Structure: How to Layout Routines Contact and Coil

To top

http://www.contactandcoil.com/rslogix-5000-tutorial/program-structure-how-to-layout-routines/#Aa_Main 9/9

You might also like