Professional Documents
Culture Documents
The variety of uses for the hardware, software and firmware (hereinafter “Products”) described in this Documentation, mandates
that those responsible for the application and use of those Products must satisfy themselves that all necessary steps have been
taken to ensure that each application and actual use meets all performance and safety requirements, including any applicable
laws, regulations, codes and standards in addition to any applicable technical documents.
In no event will Rockwell Automation, Inc., or any of its affiliate or subsidiary companies (hereinafter “Rockwell Automation”) be
responsible or liable for any indirect or consequential damages resulting from the use or application of the Products described in
this Documentation. Rockwell Automation does not assume responsibility or liability for damages of any kind based on the
alleged use of, or reliance on, this Documentation.
No patent liability is assumed by Rockwell Automation with respect to use of information, circuits, equipment, or software
described in the Documentation.
Except as specifically agreed in writing as part of a maintenance or support contract, equipment users are responsible for:
• properly using, calibrating, operating, monitoring and maintaining all Products consistent with all Rockwell Automation
or third-party provided instructions, warnings, recommendations and documentation;
• ensuring that only properly trained personnel use, operate and maintain the Products at all times;
• staying informed of all Product updates and alerts and implementing all updates and fixes; and
• all other factors affecting the Products that are outside of the direct control of Rockwell Automation.
Reproduction of the contents of the Documentation, in whole or in part, without written permission of Rockwell Automation is
prohibited.
Throughout this manual we use the following notes to make you aware of safety considerations:
Identifies information that is critical for successful application and understanding of the product.
Identifies information about practices or circumstances that can lead to personal injury or death, property
damage, or economic loss. Attentions help you:
• identify a hazard
• avoid a hazard
• recognize the consequence
Labels may be located on or inside the drive to alert people that dangerous voltage may be present.
Labels may be located on or inside the drive to alert people that surfaces may be dangerous temperatures.
Design for Reuse: Increase Your Productivity with Modular Programming
Contents
Before you begin ........................................................................................................................................... 4
About this lab .................................................................................................................................................................................... 4
Tools ................................................................................................................................................................................................. 4
Prerequisites ..................................................................................................................................................................................... 4
3 of 56
Before you begin
IMPORTANT:
Throughout the lab, there will be several tool tip boxes that explain possible design approaches using
modular design methodologies. These are suggestions. It should be understood that there are many ways
to implement modular programming methodologies within the Studio 5000™ Logix Designer environment.
This lab has three sections. Each section should take approximately 20 – 25 minutes to complete.
Tools
Pre-Release Studio 5000™ Logix Designer v22
CMX 5370 Lite Demo Box
ACD Files: TankFillStation.ACD, TankFillStationManager.ACD, WashingMachine_Start.ACD
Import Files: Motor_VFD.L5X, Rungs for Limit_Monitor.L5X, Rungs for Temp_Conver.L5X
Prerequisites
Familiarity with the Logix 5000 design environment is required. The user must be comfortable creating tags, programs, tasks
and I/O Modules. The user must also be comfortable with creating RSLinx drivers, downloading, and online edits. A basic
understanding of modular design methodologies is a plus.
4 of 56
Section 1: Reusable Code – Theory
This section of the lab will focus on the theory behind designing for reuse. We will focus on taking requirements from a
specification and developing code within the controller. It is important to remember that there are many ways to design reusable
code. This section will show an example of one way this can be done.
Subsections:
Design
Definition and Instantiation
Code Development – Temp_Convert
Code Development – Limit_Monitor
Design
Sometimes its easy to take requirements and immediately begin writing code. In this example, it would take only minutes to
create code for the requirements above. The key to developing reusable code is to take extra time during the design phase
to pull out pieces of functionality that can be reused. If we carefully design these pieces, we can create libraries of modules
that will increase your efficiency and decrease development time. Let’s see what we can do with the requirements above.
First, its concievable that somewhere down the road we may need to perform temperature conversions. This is a great
option for a small code module that we can add to our library. Additionally, we could add logic to the code module to
monitor the temperature for high and low temperatures. Remember, as you add complexity, you begin to limit the reuse
capabilites of the code. It is also common to monitor an analog value for a high and low value. This is another great
example of a small code module that can be reused across many applications. Our proposed code modules are listed
below.
Now that we have identified our code modules, lets continue the design.
5 of 56
The code modules we are designing must be integrated with the current structure of code modules. Let’s take a look at the
current structure and determine the best way to develop our code. Lets assume the engineering team developed a set of
module interface diagrams. These diagrams will show how the system is broken down into modules and how they interact
with one another. From the hypothetical diagrams, we determined that the system is broken into six core code modules.
They are listed below.
After further investigation, we determined that the logic associated with the Temp_Convert and Limit_Monitor modules will
be located in the Cycle_Procedure code module. The interface diagram below gives us a glimpse of the interaction
between the Cycle_Procedure, Limit_Monitor, and Temp_Convert code modules.
The Limit_Monitor code module will also interface with the Cycle_Procedure module. The diagram below shows a
representation of this interaction.
There are many ways you can develop interface diagrams. Ultimately, it boils down to the preferences of the engineering
team. The Temp_Convert example shows a simple interface between Cycle_Procedure and Temp_Convert. The
Temp_Convert module will connect to Cycle_Procedure to obtain the raw value of the temperature sensor as well as the
position of the temperature unit selector switch. The Temp_Convert module will make public the proper basin water
temperature through the Val_Temperature parameter. A configuration tag is also added to allow the user to configure the
code module to make the proper conversion depending on the units of the input temperature. The Limit_Monitor diagram
shows the code module obtaining the Basin Water Temperature value from the Cycle_Procedure code module. The
Limit_Monitor code module will monitor the input temperature and set the high and low limit status bits when applicable.
There are two configuration tags which allow the user to define when they want the high and low status bits to be set.
6 of 56
Definition and Instantiation
Terms you will often hear when implementing modular design methodologies are Definition and Instantiation.
Understanding these two terms will help users see the true power behind modular programming. Additionally, as we move
into the future, Studio 5000™ will continue adding features and functionality to further help users implement modular design
methodologies.
Definition:
A module definition is best described as the program logic required to solve a particular problem along with all
corresponding public and private tags for the module. We will show examples of module definitions later in the lab.
Instantiation:
The process of module instantiation refers to making the connections required for the execution of the logic. Essentially,
you are plugging in real inputs and outputs so the logic actually controls a real process. As soon as the connections are
made, you now have an instance. See the image below for a visual representation of this process.
The example above shows a pump module being instantiated three times. The logic in the pump module will be executed
three times using the inputs and outputs associated with pumps 1, 2, and 3. If changes are made to the pump module
definition, they will be reflected throughout all instances of the pump module. In addition to conserving memory, this
enables users to easily develop a code library of modules that can be reused across many applications.
7 of 56
Code Development – Temp_Convert
There are several types of “containers” within the Studio 5000 design environment that can be utilized for modular
programming. Routines, Programs, Tasks, AOIs, and UDTs are several great examples. There is really no right or wrong
way to determine which containers to use. Understanding the uniqueness of each type will help you make the best
decision. For this example, we will be using Add-On Instructions (AOI) for the smaller code modules.
IMPORTANT:
When designing your system using modular programming methodologies it’s important to use AOIs when
applicable. Since there is no written standard for when to use an AOI for a code object, you will find that
users develop and implement a variety of standards based on their preferences on code design and layout.
When considering the use of an Add-On Instruction, remember that they do not support online edits. Keep
this in mind, especially in applications where potential program changes while running are frequent. AOIs
are a great choice for smaller code classes that can be tested early in development and have a low
possibility of requiring changes during runtime.
1. Open Studio 5000 by double-clicking on the Studio 5000 icon on the desktop
You can also navigate to Start menu > All Programs > Rockwell Software > Studio 5000
8 of 56
4. Enter ‘Module_Development’ in the Name field.
5. Click Next.
6. Select ‘22’ for the revision.
7. Click Finish.
9 of 56
8. In the Controller Organizer, right-click on the Add-On Instructions folder. Select New Add-On Instruction....
9. In the New Add-On Instruction dialog box, enter the name ‘Temp_Convert’.
13. Confirm that the Add-On Instruction Dialog box looks like the following screen shot. Click OK.
10 of 56
14. When the Add-On Instruction Definition dialog box is displayed, navigate to the Parameters tab.
AOI parameters allow us to pass information in and out of an AOI. We can use parameters to construct the interface layer
of our module code. Let’s create the parameters required for the Temp_Convert module.
15. Using the interface diagrams as reference, we can create the parameters required for this code module.
The Temp_Convert module requires two elements for it to operate. The first is the Temperature Unit Selector Switch
position and the second is the Water Temperature Sensor Value. In an effort to keep this module generic so it can be
reused later, lets create a handful of parameters so the module can interface to other modules.
FYI
In most cases, as a module becomes more complex, it becomes less generic. Keeping code modules as
generic as possible will increase its reusability.
16. Click in the name box of the first available row in the parameters tab.
11 of 56
20. Select the Req and Vis boxes.
Confirm the new parameter looks like the following screen shot. For this module, we will convert from Fahrenheit to Celsius
if the Inp_UnitSelect parameter is set to ‘0’. We will convert from Celsius to Fahrenheit if it is set to ‘1’.
22. Create another input parameter that matches the screen shot below.
That covers the connections to the Cycle_Procedure module. Let’s move on to the code module configuration parameters.
23. Create another input parameter that matches the screen shot below.
NOTE: Be sure to uncheck the ‘Vis’ and ‘Req’ checkboxes. This configuration tag is used to tell the code module the
temperature unit of the input value. A value of ‘0’ will indicate that the input temperature is in Celsius. A value of ‘1’ will
indicate that the input temperature is in Fahrenheit.
12 of 56
24. Create an output parameter that matches the screen shot below.
NOTE: Be sure to uncheck the ‘Req’ checkbox and check the ‘Vis’ checkbox.
That should cover all of the parameters for this code module.
26. Click the Logic button in the bottom left corner of the Temp_Convert definition window.
For the sake of time, you will import the logic required for this code module.
27. Click on Rung 0. Press the delete button to delete the empty rung.
13 of 56
28. Right-click on (End) and select Import Rungs.
14 of 56
30. The Import Configuration dialog box will appear. Click OK.
NOTE: We will cover details on this feature later in the lab.
NOTE: The imported rungs should look like the following screen shot.
15 of 56
Code Development – Limit_Monitor
Now that we are finished with the Temp_Convert module, it’s time to compete the Limit_Monitor module.
1. In the Controller Organizer, right-click on the Add-On Instructions folder. Select New Add-On Instruction....
2. In the New Add-On Instruction dialog box, enter the name ‘Limit_Monitor.
3. Add a description.
6. Confirm that the Add-On Instruction Dialog box looks like the following screen shot. Click OK.
16 of 56
7. When the Add-On Instruction Definition dialog box is displayed, navigate to the Parameters tab.
8. Using the interface diagrams as reference, we can create the parameters required for this code module.
The Limit_Monitor module requires one element for it to operate. The Limit_Monitor module will connect to the Basin Water
Temperature value in the Cycle_Procedure module.
FYI
Remember, our goal is to keep this code module generic. Since it’s possible the next application would
require High and Low thresholds of a pressure sensor input, we should pick parameter names that are not
temperature specific.
9. Click in the name box of the first available row in the parameters tab.
17 of 56
13. Select the Req and Vis boxes.
Let’s create the input parameters that will be used to set the high and low threshold values.
14. Click in the name box of the first available row in the parameters tab.
17. Select REAL in the Data Type box. Be sure to check the ‘Vis” box and uncheck the ‘Req’ box
NOTE: The new parameter should look like the following screen shot.
18 of 56
19. Create another input parameter that matches the screen shot below.
This input parameter will be used to configure the threshold values when the Low Limit status bit is set.
21. Create an output parameter that matches the screen shot below.
22. Create another output parameter that matches the screen shot below.
19 of 56
20. Click Apply.
Let’s add some logic.
21. Click the Logic button in the bottom left corner of the Limit_Monitor definition window.
For the sake of time, you will import the logic required for this code module.
22. Click on Rung 0. Press the delete button to delete the empty rung.
20 of 56
24. Select ‘Rungs for Limit_Monitor.L5X’. Click Open.
You can find the project in this directory: C:\Lab Files\AD07 - Design for Reuse\Exports.
25. The Import Configuration dialog box will appear. Click OK.
NOTE: We will cover details on this feature later in the lab.
21 of 56
NOTE: The imported rungs should look like the following screen shot.
22 of 56
Section 2: Reusable Code – Implementation
This section of the lab will focus on the instantiation of reusable code. In Section 1, we developed code based on system
requirements and basic interface diagrams. In Section 2, we will take our reusable code and instantiate (use) it within the
washing machine control code.
Subsections:
Instantiating Code Modules
Testing the Logic
1. Open Studio 5000 by double-clicking on the Studio 5000 icon on the desktop
You can also navigate to Start menu > All Programs > Rockwell Software > Studio 5000
23 of 56
3. Navigate to the WashingMachine_Start.ACD file. Click Open.
You can find the project in this directory: C:\Lab Files\AD07 - Design for Reuse\
24 of 56
5. Drag / drop the Limit_Monitor AOI from the Module Development.ACD file to the Washing Machine ACD file.
6. Drag / drop the Temp_Convert AOI from the Module Development.ACD file to the Washing Machine ACD file.
Verify the Add-On Instructions folder in the WashingMachine_Start.ACD file contains both AOIs.
25 of 56
7. Close the Module Development.ACD file.
11. Add a new rung at the bottom of the MainRoutine routine. The new rung should be number 24.
26 of 56
14. Verify the Temp_Convert instruction was added to rung 24.
NOTE: We need to instantiate the AOI. Lets start by creating a backing tag.
27 of 56
18. Click Create.
28 of 56
The AOI graphic should look like the following screen shot.
We only have to make one more connection before this instance of the AOI is fully instantiated.
29 of 56
22. Expand BasinTemp_Convert.
NOTE: In section 1 we added a configuration bit to this AOI so the user could define which temperature unit was being
converted. When Cfg_InputTempUnit is set to 0, the AOI will perform conversions assuming the input temperature is in
Celsius. If the input temperature is in Fahrenheit, then the configuration would need to be set to 1.
Now that we have instantiated this code module, let’s move on to the Limit_Monitor module.
24. In the Cycle_Procedure program, add a new rung at the bottom of the MainRoutine routine.
NOTE: The new rung should be number 25.
30 of 56
26. Double-click on the ‘?’ to the right of Limit_Monitor. Type ‘BasinTemp_Limits’.
31 of 56
30. Double-click the ‘?’ next to Inp_MonitoredValue. Select Val_BasinWaterTemp.
The AOI graphic should look like the following screen shot.
This code module is now fully instantiated. We need to define the high and low limit thresholds.
Now we have to add the logic that will turn on a warning light if either limit status bit is set.
32 of 56
33. Add the following branch around the Limit_Monitor instruction.
33 of 56
Testing the Logic
In this section we will download our code to the controller and test the operation.
7. Turn DI5 to the left (off). This will select Celsius for the Temp_Convert module.
10. Turn DI5 to the right (on). This will select Fahrenheit for the Temp_Convert module.
34 of 56
12. Turn DI5 to the left (off).
14. Slowly turn potentiometer AI0 counter-clockwise. Watch the red light at DO3. Stop when it illuminates.
15. Look at the Limit_Monitor AOI. Note how the Sts_LowLimit output parameter is true.
16. Slowly turn potentiometer AI0 clockwise. Verify that the red light at DO3 turns off.
17. Continue turning potentiometer AI0 clockwise. Verify that the red light at DO3 turns on around 85 degrees.
35 of 56
Section 3: Reusable Code – Examples
This section of the lab will focus on showing other examples of how reusable code can increase productivity and efficiency. We
will be reusing a code module developed in Section 1 in a different area of the code. We will also investigate how reusable code
can dramatically improve hardware upgrades and line expansions.
Subsections:
Reuse Example
Hardware Upgrades
Line Expansion
Reuse Example
The following subsection will be using the washing machine example from sections 1 and 2. Let’s assume the washing
machine has been in service for a while. During its life your team has discovered that depending on the clothing material
and / or the amount of clothing in the washing machine, the agitation motor can fail causing significant downtime. The team
decides that motor failures can be minimized if we monitor the current of the agitation motor and automatically shutdown the
process if an over current condition is detected. Let’s use the Limit_Monitor code module to monitor the motor current.
3. Add a new rung at the bottom of the MainRoutine routine. The new rung should be number 3.
36 of 56
5. Click the Limit_Monitor instruction icon.
37 of 56
11. Double-click ‘0.0’ next to Cfg_HiLimit. Enter ‘2.5.
Now we have to add the logic that will set the Alm_HighCurrentFlt alarm bit.
FYI:
We just used an AOI that was originally designed to monitor a temperature value to monitor a motor’s current
value. It can be easy at times too get specific when designing our code modules. Since we kept the AOI’s
parameter names generic, it can be easily reused across many applications.
38 of 56
Hardware Upgrades
This subsection will be using a different example file. The Tank Fill Station application is an over-simplified group of code
modules that fills and empties a tank. We will focus on how modular programming can greatly improve efficiencies when
upgrading equipment. In this application, we will be replacing a code module for an existing motor contactor with a new
code module for a VFD. Partial Import Online (PIO) will be used to perform the update while online with the controller.
39 of 56
4. Select the 1769-L36ERM and select Download.
The line connecting the two modules above represents at least one connection. In this example, the tags requiring a
connection are shown in the Motor_Control module. The connections for the interface above are all made using Program
Parameters. This is a new feature with version 22 that allows you to pass values between programs without using controller
scope tags. This provides a greater level of encapsulation. Program Parameters give programs a similar look and feel as
AOIs. One key difference is programs that implement program parameters can be edited online. AOIs do not support
online edits. A list of the connections is shown below.
Pump_01.Out_MotorRunFWD (output) is connected to Motor_Control.Cmd_RunFWD (input)
Pump_01.Out_MotorStop (output) is connected to Motor_Control.Cmd_Stop (input)
Pump_01.Inp_MotorRunning (input) is connected to Motor_Control.Sts_Running (public)
The new Motor_Control module that we are using will interface with a VFD. The new VFD Motor_Control module for this
example is a basic example. More than likely, a VFD code module would be much more complex than the one we will be
working with in the lab.
40 of 56
The image below shows a diagram of the possible interface options for the new VFD code module.
Let’s use PIO to import a code module that will interface between the Pump module and a VFD.
41 of 56
8. Select the Motor_VFD.L5X file and click Open.
The Import Configuration window will appear. This feature is referred to as Partial Import Online (PIO). This window gives
you a quick way to identify and handle component names, collisions, and connections.
NOTE: As soon as you select Motor_Control you will notice that the Import Configuration window will flag multiple items in
the Import Content display. Additionally, since the Motor_Control program already exists, the Operation field will
automatically change to Overwrite. Let’s take a closer look at the discrepancies.
The Collision Details window shows you the major differences between the two programs. Take a minute to look at the
differences.
12. In the Import Content window, click Parameters and Local Tags.
42 of 56
13. Take a few moments to scroll through the Parameter and Local Tags.
This gives you a quick summary of the differences between routines that will be replaced. In this case, we are replacing a
motor contactor with a drive. I would fully expect to see a higher rung count when comparing code modules for a drive and
a motor contactor.
43 of 56
16. Click the Close button on the Routine Name Collision dialog box.
18. Expand the Configure Connections window so you can see the all of the columns.
NOTE: The connection to Sts_Running is disconnected because the parameter is no longer present for the VFD
Motor_Control code module. The Cmd_RunFWD and Cmd_Stop connections have not changed. We do need to add a
new connection that is required for the interface between the Pump and VFD Motor Control module. The Sts_Running
parameter was replaced with the Sts_DriveActive. We need to create this connection prior to performing the import.
44 of 56
21. Click in the Final Connection box for the Sts_DriveActive parameter. Click the drop-down arrow.
22. Click the “Show parameters from other program” drop-down and select Pump_01.
25. Verify the Configure Connections window looks like the following screen shot.
45 of 56
27. Read the Online Options pop-up and click OK.
46 of 56
Line Expansion
This subsection will be using a different example file. The Tank Fill Station Manager application is an over-simplified group
of code modules that manages multiple tank fill stations. We will focus on how modular programming can greatly improve
efficiencies during line expansions. In this application, we will be adding a second tank fill station to the application. Partial
Import Online (PIO) will be used to perform the update while online with the controller.
NOTE: In this example, we separated the different modules into 3 different tasks, all executing at difference rates.
The Controller Organizer shows the different code modules in an application from a perspective of execution. In
the latest release of Studio 5000, the Logical Organizer was introduced. Let’s take a look at how that view can
help us understand the structure of our application.
47 of 56
4. Double-click on the Logical Model icon in the Controller Organizer.
NOTE: Take a look at the folder icon for TankStation_01. This icon represents a folder, not a program. Folders are
used for organization and cannot be scheduled for execution. However, they can contain program parameters.
This can be extremely beneficial when grouping small code modules together to create larger more complex
modules.
7. Double-click on the Parameter and Local Tags under the TankStation_01 folder.
NOTE: Commands and Statuses were created to control and monitor a single tank fill station. The small code modules that
exist in the TankStation_01 folder will connect to these higher level parameters.
48 of 56
8. Expand the PumpControl_01 folder.
The Pump_01 and MotorControl_01 code modules have been grouped into a single folder named PumpControl_01.
This logically groups the pump code module with the motor contactor code module that controls the pump motor.
Let’s add an additional Tank Station.
9. Right-click and drag / drop the TankStation_01 folder to the root folder.
49 of 56
10. When prompted, click Copy here with Configuration.
NOTE: The Paste Configuration window will appear. This allows us to customize the paste and handle any
exceptions. Let’s continue with the paste.
50 of 56
NOTE: The Operation changed to Create.
It can take a while to make the changes required for a new import. Let’s use the Find/Replace functionality to
finish the changes quickly.
16. Click the Find/Replace button at the top of the Paste Configuration window.
17. Enter the following information into the Find / Replace window. Don’t forget to select the “Use Wildcards”
checkbox.
51 of 56
21. Click OK when prompted about Online Options.
After the import completes, the Logical Organizer view should contain a TankStation_02 folder.
25. Drag and drop the MotorControl_02 program to the Periodic_25ms Task.
26. With the CTRL key pressed, left-click on the Tank_02 and Valve_02 programs.
27. Drag and drop the Tank_02 and Valve_02 programs to the Periodic_50ms Task.
52 of 56
28. In the Periodic_10ms Task, expand the State_Machine program.
NOTE: Feel free to download the program and test the updates. Both Tank Stations should be filling and draining at the
same time. If time permits, try adding a third Tank Station.
53 of 56
Notes
54 of 56
Notes
55 of 56
Publication XXXX-XX###X-EN-P — Month Year 56 of 56 Copyright© 2012 Rockwell Automation, Inc. All rights reserved.
Supersedes Publication XXXX-XX###X-EN-P — Month Year