You are on page 1of 56

Design for Reuse: Increase Your Productivity

with Modular Programming

For Classroom Use Only!


Important User Information
This documentation, whether, illustrative, printed, “online” or electronic (hereinafter “Documentation”) is intended for use only as
a learning aid when using Rockwell Automation approved demonstration hardware, software and firmware. The Documentation
should only be used as a learning tool by qualified professionals.

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 about practices or circumstances


that can cause an explosion in a hazardous environment,
which may lead to personal injury or death, property damage, or economic loss.

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

Section 1: Reusable Code – Theory ............................................................................................................. 5


Design ............................................................................................................................................................................................... 5
Definition and Instantiation................................................................................................................................................................ 7
Code Development – Temp_Convert ............................................................................................................................................... 8
Code Development – Limit_Monitor................................................................................................................................................ 16

Section 2: Reusable Code – Implementation.............................................................................................. 23


Instantiating Code Modules ............................................................................................................................................................ 23
Testing the Logic............................................................................................................................................................................. 34

Section 3: Reusable Code – Examples ...................................................................................................... 36


Reuse Example............................................................................................................................................................................... 36
Hardware Upgrades ........................................................................................................................................................................ 39
Line Expansion ............................................................................................................................................................................... 47

3 of 56
Before you begin

About this lab


There are two types of programming methodologies that are commonly used in industry today. They include Modular
programming and Object Oriented Design (OOD) programming methodologies. Modular programming is a software design
technique that emphasizes the separation of the functionality of a specific project into independent and interchangeable modules.
These modules will be driven by verbs in the problem statement or functional specification. In other words, they will focus on the
actions to be performed. Object Oriented Design (OOD) programming is a software design technique that uses objects and their
relationships to programmatically define the problem to be solved. These objects are generally driven by non-trivial nouns in the
problem statement or function specification. In other words, they are focused on ‘objects’ or ‘things’. These objects will have
properties and methods (operations) to help define what the object is and what it is cable of doing. Both programming
techniques can dramatically improve a system’s maintainability and expandability. While some of the rules that define each
programming method are different, there are many programming commonalities that exist between the two. These
methodologies can be implemented in numerous ways within the Studio 5000™ Logix Designer environment. This lab will cover
some basic recommendations on how to implement Modular Programming methodologies using functionality that will be
available in version 22 of Studio 5000™ Logix Designer. Please keep in mind that these are strictly recommendations and many
designers may choose to implement the basic design rules differently.

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

1. Read the scenario below.


For this lab, let’s assume multiple engineers are working on a washing machine project. Your responsibility is to design
code for a water temperature display that meets the requirements listed below.

5.2.1 Basin Water Temperature Display


5.2.1.1 The basin water temperature shall be displayed on the washing machine HMI.
5.2.1.2 The user shall be able to select Fahrenheit or Celsius from the HMI.
5.2.1.3 Abnormal water temperature shall be annunciated by illuminating a warning light on the local machine.
5.2.1.3.1 The temperature warning light shall be illuminated if the basin water temperature is below 30°C
5.2.1.3.2 The temperature warning light shall be illuminated if the basin water temperature is above 85°C

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.

 Temp_Convert – Converts temperature values from Fahrenheit to Celsius or Celsius to Fahrenheit.


 Limit_Monitor – Monitors an analog value and will set a high and low status based on user programmed limits.

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.

 Cycle_Procedure – This code module handles the wash cycle.


 Input_Control – This code module will handle the majority of the physical and “soft” inputs.
 Valve_Control – This code module will handle the hot and cold water solenoid valves.
 Pump_Control – This code module will handle the drain pump.
 Motor_Control – This code module will handle the agitation motor.
 Sequence_Status – This code module will handle the washing machine operational status

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

2. Click on New Project.

3. Expand CompactLogix™ 5370 Controller and select 1769-L36ERM.

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’.

10. Add a description.

11. Select Ladder Diagram as the Type.


If you are new to AOIs, they allow you to create custom instructions. These instructions can be instantiated and used many
times in your program. The type drop-down gives you the option to select which programming language to use in the AOI.
The options are Ladder Diagram, Structured Text, and Function Block Diagram. AOIs can be used (instantiated) in any of
the four programming languages, regardless of the language type that is used within the AOI definition.

12. Leave the Revision at its default settings.


NOTE: AOIs have a Major and Minor revision options. This is a great way to keep track of AOI versions.

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.

17. Type ‘Inp_UnitSelect’.

18. Select Input in the usage box.

19. Select BOOL in the Data Type box.

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’.

21. Click Apply.


Let’s create the parameter that will be used to pass in the temperature value.

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.

Now it’s time to configure the output parameters.

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.

25. Click Apply.


Now it’s time to develop our temperature conversion logic.

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.

29. Select ‘Rungs for Temp_Convert.L5X’. Click Open.


You can find the project in this directory: C:\Lab Files\AD07 - Design for Reuse\Exports.

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.

31. Click Save.

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.

4. Select Ladder Diagram as the Type.

5. Leave the Revision at its default settings.

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.

10. Type ‘Inp_MonitoredValue’.


This input parameter will be the analog value under test.

11. Select Input in the usage box.

12. Select REAL in the Data Type box.

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.

15. Type ‘Cfg_HiLimit’.


This input parameter will be used to configure the threshold values when the High Limit status bit is set.

16. Select Input in the usage box.

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. Click Apply.

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.

20. Click Apply.


Let’s create the parameters that will be used to pass the High and Low status bits out of the AOI.

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.

23. Right-click on (End) and select Import Rungs.

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.

26. Click Save.


NOTE: Modular programming practices allows you to test each code module separate from the actual system. This
simplifies unit testing and should reduce the amount of issues that will be seen during integration testing. We will not test
the modules we just created since we have a limited amount of time.
Now that we have developed our code modules, let’s integrate them with the main application file.

Congratulations! You have just finished Section 1. Proceed to Section 2.

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

Instantiating Code Modules

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

2. Click on Existing Project.

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\

4. Resize the windows for both instances of Studio 5000.


NOTE: Use the screen shot below for reference.

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.

8. Maximize the WashingMachine_Start.ACD file.

9. In the Controller Organizer, navigate to the Cycle_Procedure program.

10. In the Cycle_Procedure program, double-click on the MainRoutine.


NOTE: The code modules we developed in section one will reside in the Cycle_Procedure program. Let’s add the AOIs to
the MainRoutine.

11. Add a new rung at the bottom of the MainRoutine routine. The new rung should be number 24.

12. Select the Add-On tab in the toolbar.

13. Click the Temp_Convert instruction icon.

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.

15. Double-click on the ‘?’ to the right of Temp_Convert. Type ‘BasinTemp_Convert’.

16. Click outside of the AOI.

17. Right-click on BasinTemp_Convert. Select New “BasinTemp_Convert”.

27 of 56
18. Click Create.

The backing tag must be of the


same data type as the AOI.

19. Double-click the ‘?’ next to Inp_UnitSelect. Select Inp_TempUnitSelSw.

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.

20. Double-click the ‘?’ next to Inp_temp. Select Val_BasinWaterTemp.

21. Right-click on the BasinTemp_Convert tag and click Monitor “BasinTemp_Convert”.

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.

23. In the Cycle_Procedure program, double-click on the MainRoutine.


NOTE: The code modules we developed in section one will reside in the Cycle_Procedure program. Let’s add the AOIs to
the MainRoutine.

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.

25. Add the Limit_Monitor AOI to rung 25.

30 of 56
26. Double-click on the ‘?’ to the right of Limit_Monitor. Type ‘BasinTemp_Limits’.

27. Click outside of the AOI.

28. Right-click on BasinTemp_Limits. Select New “BasinTemp_Limits”.

29. Click Create.

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.

31. Double-click ‘0.0’ next to Cfg_HiLimit. Enter ‘85.0’.

32. Double-click ‘0.0’ next to Cfg_LoLimit. Enter ‘30.0’.


The AOI should look like the follow screen shot.

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.

34. Click Save.

33 of 56
Testing the Logic

In this section we will download our code to the controller and test the operation.

1. Click Communication  Who Active

2. Expand the AB_ETHIP-1 driver.

3. Select the 1769-L36ERM at 192.168.1.7 and click the Download button.

4. When prompted to confirm the download, click Download.

5. When prompted to change the controller to RUN mode, click yes.

6. Navigate to rung 24 of the MainRoutine in Cycle_Procedure.

7. Turn DI5 to the left (off). This will select Celsius for the Temp_Convert module.

8. Turn the potentiometer AI0 to 3.

9. Verify that Val_ConvertedTemp is approximately 55.

10. Turn DI5 to the right (on). This will select Fahrenheit for the Temp_Convert module.

11. Verify that Val_ConvertedTemp is approximately 130.

34 of 56
12. Turn DI5 to the left (off).

13. Navigate to rung 25 of the MainRoutine in Cycle_Procedure.

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.

18. Go offline with the controller.

Congratulations! You have just finished Section 2. Proceed to Section 3.

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.

1. In the Controller Organizer, navigate to the Motor_Control program.

2. In the Motor_Control program, double-click on the MainRoutine.

3. Add a new rung at the bottom of the MainRoutine routine. The new rung should be number 3.

4. Select the Add-On tab in the toolbar.

36 of 56
5. Click the Limit_Monitor instruction icon.

6. Double-click on the ‘?’ to the right of Limit_Monitor. Type ‘MotorCurrent_Limit’.

7. Click outside of the AOI.

8. Right-click on MotorCurrent_Limit. Select New “MotorCurrent_Limit”.

9. On the New Parameter or Tag dialog box, click Create.

10. Double-click the ‘?’ next to Inp_MonitoredValue. Select Inp_MotorCurrent.

37 of 56
11. Double-click ‘0.0’ next to Cfg_HiLimit. Enter ‘2.5.

12. Leave Cfg_LoLimit at the default value of ‘0’.


NOTE: Since we will not be using the Sts_LowLimit bit of this instance of the AOI, it does not matter what value we
configure for Cfg_LoLimit.
The AOI should look like the follow screen shot.

Now we have to add the logic that will set the Alm_HighCurrentFlt alarm bit.

13. Add the following branch around the Limit_Monitor instruction.

14. Click Save.

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.

1. Minimize the WashingMachine_Start.ACD file.

2. Open the project named TankFillStation.ACD.


You can find the project in this directory: C:\Lab Files\AD07 - Design for Reuse.

3. Click on Communications  Who Active.

39 of 56
4. Select the 1769-L36ERM and select Download.

5. Switch the controller to RUN mode.


Before we tackle the import, let’s take a minute to discuss how the Pump_01 and Motor_Control modules interface with one
another.
The Pump Motor is controlled by a motor contactor. When this system was initially designed, a device module was created
for a motor contactor. The Motor_Control program will connect the Pump logic with the actual motor contactor. Let’s take a
look at the interface between these two code modules.

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.

6. Right-click on the MainTask. Click Add  Import Program…

7. Navigate to the Motor_VFD.L5X file.


You can find the L5X in this directory: C:\Lab Files\AD07 - Design for Reuse\Exports.

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.

9. Select Motor_Control in the Final Name drop-down.

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.

10. Click the Collision Details… button.

The Collision Details window shows you the major differences between the two programs. Take a minute to look at the
differences.

11. Click the Close button.

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.

14. Click on Routines in the Import Content window.

15. Click on the Details button for the MainRoutine.

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.

17. Click the Connections folder in the Import Content window.

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.

19. Click in the ‘New Connection…’ box.

20. Select \Motor_Control.Sts_DriveActive from the drop-down.

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.

23. Double-click on \Pump_01.Inp_MotorRunning in the dialog box.

24. Click in the \Motor_Control.Cmd_Stop parameter box.


NOTE: Clicking on a different row will confirm the newly created connection.

25. Verify the Configure Connections window looks like the following screen shot.

26. On the Import Configuration dialog box, click OK.

45 of 56
27. Read the Online Options pop-up and click OK.

28. Navigate to the MainRoutine of the Motor_Control program.


NOTE: The new program was imported and connected to the Pump_01 module while running. Using a modular approach
when developing device modules can make hardware upgrades much quicker and efficient.

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.

1. Minimize the TankFillStation.ACD file.

2. Open the project named TankFillStation_Manager.ACD.


You can find the project in this directory: C:\Lab Files\AD07 - Design for Reuse.

3. In the Controller Organizer, expand the Tasks folder.

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.

5. Expand the State_Machine program folder.

6. Expand the TankStation_01 folder.

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.

11. In the Final Name field, enter TankStation_02.

12. Click in the Description box.


NOTE: Clicking outside of the Final Name box will cause the new name to be accepted. Notice how the Operation window
changed from “Use Existing” to “Create”.

13. Click on the Programs Folder in the Import Content window.

14. Click in the Final Name box for PumpControl_01.

15. Change the final name to PumpControl_02.

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.

18. Click Replace All.

19. Close the Find / Replace window.


The Programs window should look like the following screen shot.

20. Click the OK button on the Paste Configuration window.

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.

22. Navigate back to the Controller Organizer.

23. Expand the Unscheduled Programs / phases folder.

We must schedule our newly created programs.


24. Drag and drop the Pump_02 program to the Periodic_25ms Task.

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.

NOTE: We have to add some logic and we are done.

52 of 56
28. In the Periodic_10ms Task, expand the State_Machine program.

29. Double-click on the MainRoutine in the State_Machine program.

30. Add the following instruction to rung 3.

31. Add the following instruction to rung 4.

32. Add the following instruction to rung 6.

33. Add the following instruction to rung 7.

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.

Congratulations! You have just finished Section 3. Lab is complete!

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

You might also like