Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 22

AC500 / S500 Training

Exercise 1 Introduction to PS501 Programming Languages

Goals
The goal of this exercise is to start your first project, and configure a simple program
for testing with a built in simulation facility. To be familiar with the IEC 61131
programming languages used in the PS501 Control Builder.

Legend
<> Indicates a key name.
| Indicates when you go from one menu to a sub-menu.
Bold Indicates a menu name or an option in a menu, or file structures
“ “ Indicates dialog box buttons, tabs, instructions etc.

 Indicates start/explanation of student activity

1 / 22
PLC Training Exercises

Exercise Objective
The objective of this exercise is to code some very simple digital logic, to achieve
this:-
Result = (A and B) or C

Exercise Steps

 Go to the following menu option on your PC

Start | Programs | 3S Software | CoDeSys V2.3 | CoDeSys V2.3

 Check that the programming software opens correctly, and then look into the project
defined options using

 Locate the User Information and fill in the fields appropriately.

2 / 22
AC500 / S500 Training

 Take a brief tour of the other options available (Load and Save, Editor, Desktop,
Colours, Directories, and Log)

 Click OK when you have finished the tour.

 Start a new project thus:-

Or alternatively, use

And ensure that a prompt as shown below is given.

When a new project is built, you should always specify the controller hardware type.
This is achieved using the drop down arrow.

 Set the controller type to a PM571 and click OK

3 / 22
PLC Training Exercises

Programming in FBD

 Do not change the name of your first program organization unit and make sure the
type is set to “Program” and the language as “FBD”

 In the program editor declare 4 local variables exactly as shown below

NOTE! Local variable “c” is incorrectly declared


There is a missing semi-colon at the end of the declaration, and we will
use this missing semi-colon to demonstrate a common programming
error in this exercise.

 In the pane below the variable declaration there are 3 question marks (???) shown
normally in red. Click on these.

4 / 22
AC500 / S500 Training

 Now type in the letter “a” (the assumption is that you can remember the name of the
variable)

 Select the element to the right hand side of the letter “a” as shown below

 Click on the “box” icon from the toolbar, whilst this is still selected.

 An AND block is automatically inserted.

 Allocate the second variable “b” in a slightly different manner (the assumption is that
you can NOT remember the name of the variable) by selecting the 3 question marks as
before and pressing F2.
The input assistant will be shown.

5 / 22
PLC Training Exercises

NOTE! As variable “c” was incorrectly declared – it is not


visible using the input assistant.
This is a common error when declaring variables, try to remember to put
a semi-colon at the end of the declaration

 Select “b” as the second input to the AND block.

 Fix the declaration of variable “c” by adding in the semi-colon.

 Add in another box.

 Use the input assistant to change the box type to “OR” by pressing F2 and navigating
to FBD Operators | OR

6 / 22
AC500 / S500 Training

NOTE! Alternatively, the word “OR” could just have been


typed in.

 Allocate the second pin of the OR gate as “c” by either typing it in, or using the input
assistant.

 Assign an output to the OR gate using the icon from the toolbar shown below.

 The logic should now look like this:-

 Select simulation mode from the drop down menu option

7 / 22
PLC Training Exercises

 And start the simulation running using the option Online | Login or press ALT+F8

 Set “c” to true by highlighting it, and typing in the number “1” on the keyboard.

8 / 22
AC500 / S500 Training

 And then activate the value by selecting Online | Write Values

 Run the program using Online | Run or F5.

 Check that the value for “result” is correctly calculated as being true.

 Check the AND gate operation works using a similar technique to the method above.

 Stop the simulation and save your work on the hard disk of your PC.

9 / 22
PLC Training Exercises

Programming in Structure Text

 Modify the existing project and add a new POU to it by right clicking on the POU
folder and selecting Add Object.

 Give a name for the new POU and make sure the type is set to Program and the
Language as ST.

 Declare the variables in the same manner as before

 And in the program code pane, add in the code:-

10 / 22
AC500 / S500 Training

NOTE! It would be nice to simply be able to test the logic now –


however there are no task connections
A task connection defines how execution of the logic should be
performed.

If you would like to attempt to test the logic now, then go ahead, and
notice how the variables in run mode are shown with question marks.

 Add in a new task connection. Highlight the resources tab.

 Double click on the task configuration option.

 And add in a new task using a right mouse click and “append task”

11 / 22
PLC Training Exercises

 Accept the default values for the moment.

 And then right click on the new task to append a program call

 This needs to be set to the structured text POU.

12 / 22
AC500 / S500 Training

 Now test the structured text program in the same manner as before.

13 / 22
PLC Training Exercises

Programming in Ladder Logic

 Modify the existing project and add a new POU to it by right clicking on the POU
folder and selecting Add Object.

 Give a name for the new POU and make sure the type is set to Program and the
Language as LD.

 Declare the variables in the same manner as before

 And in the program click on the toolbar to add a contact

14 / 22
AC500 / S500 Training

 It will be shown like this

And we need to click on the contact icon one more time, to add another contact in
thus:-

 Allocate variable a and b to the 2 contacts. Either type the variable name in, or use the
input assistant with the F2 key.

 Select both a and b with the mouse by holding the Shift key down and clicking on a
and then b.

 And add in a parallel contact

So the diagram looks like this.

15 / 22
PLC Training Exercises

 Code this contact to variable c

 And add in a coil when the end element is selected

 This can be coded to the variable “result”

 Append a program call to the Ladder Logic Program in the same manner as
previously.

 Test the logic in the same manner as the previous exercises.

16 / 22
AC500 / S500 Training

4.1.1 Programming in CFC

 Modify the existing project and add a new POU to it by right clicking on the POU
folder and selecting Add Object.

 Give a name for the new POU and make sure the type is set to Program and the
Language as CFC.

 Declare the variables in the same manner as before

 Note the toolbar items available for CFC’s

17 / 22
PLC Training Exercises

NOTE! These tools can also be accessed in the editor by right


clicking.
This author thinks that the right click method is a quicker method for
putting together CFC’s.

 In the code pane add 3 inputs

 Assign the variables a, b, and c to the inputs

 Add 2 boxes

NOTE! Notice the program execution order is shown


The top AND box in this example has the number 0 next to it – this box is
processed before the bottom box with the number 1 next to it.

 Add in an output

 Allocate the output pin to result

18 / 22
AC500 / S500 Training

 And then click and drag between the pins to connect lines as shown below.

 And finally, change the second AND block to an OR.

19 / 22
PLC Training Exercises

 Append a program call to the CFC program in the same manner as previously.

 Test the logic in the same manner as previous exercises.

 Save your work on the hard disk of your PC.

20 / 22
AC500 / S500 Training

Programming in Instruction List (IL)

 Modify the existing project and add a new POU to it by right clicking on the POU
folder and selecting Add Object.

 Give a name for the new POU and make sure the type is set to Program and the
Language as LD.

 Declare the variables in the same manner as before

 Add in the code as shown below to the code pane.

21 / 22
PLC Training Exercises

 Append a program call to the instruction list program in the same manner as
previously.

 Test the logic in the same manner as previous exercises.

 Save your work on the hard disk of your PC.

22 / 22

You might also like