• No results found

CHAPTER 5 : Project STRUCTURE

5.1 Project Structure

5.1.2 Application

An application consists always a Library manager When applicable Global variables

POU‟s (Program Organisation Unit) (Program, Function, Function Block) 5.1.3 Libraries

Libraries can be a collection of functions for certain hardware.

5.1.3.1 Global variables

Global variables can be reached from all other POU‟s in the application.

They are created in the Global variable editor.

Local variables with the same name as a global variable have a higher priority in the processing of a POU.

5.1.3.2 Program

Every program consists of a declaration section and a body. In the declaration section the local variables are declared. The body is written in one of the IEC programming languages: IL, ST, SFC, FBD and LD; or CFC.

POUs may call other POUs; however recursive calling (calling itself) is prohibited.

5.1.3.3 Function

We are all familiar with such functions as, add, square root, sin, cos, equal, etc.

Within IEC, an enormous number of these standard functions are defined. You can even define your own functions, such as in the following example, defining the function simple of type REAL:

FUNCTION simple: REAL

Once defined, this function can be used endlessly in the same program, in other programs and even in other projects.

5.1.3.4 Function block

The same applies to function blocks as for functions; we can defines these ourselves, and use them as often as we wish.

Function block instances (copies) are allowed. Each Instance has a unique identifier, and can be declared locally or globally.

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-45

5.1.4 Task configurator 5.1.4.1 Task

In the task the POU can be given a priority. Based on this priority he will be processed.

5.1.4.2 Visualization Task

In the visualisation task the different HMI screens are processed. A visualisation task will never interrupt a POU task.

5.1.5 Visualisation manager 5.1.5.1 Target visualisation

This will process the visualisation for this target.

5.1.5.2 WEB visualisation

When supported will process the visualisation for the WEB 5.1.6 Visualisation screens

The actual visualisation screens for this application 5.2 Internal processing

The flowchart shows how the processor works when POUs are used.

Figure 51

A-46

5.3 Task Configuration

With the Task Configurator we can create tasks to be carried out in a specific order and at specific times.

In the Task Configurator each task is given a priority number. The task with the highest priority (priority number 1) will be performed first.

Tasks can be performed in the following way:

Cyclic, the task is performed cyclically according to the time specified in the

“interval” field.

Freewheeling, the task will be processed as soon as the program is started and at the end of one run will be automatically restarted in a continuous loop. There is no cycle time defined.

Event, (Boolean event, the task will be started as soon as the variable defined in the Event field gets a rising edge.)

Status, (Boolean event, the task will be started if the variable defined in the Event field is true.)

Triggered by external event, depending on the target, the task is performed if a system event occurs, which is defined in the “event” field. The system event is not the confused with the “Codesys” system events.

Watchdog

If the target system configuration supports a watchdog, a high and low limit can be set for each task.

Active watchdog

With an active watchdog, if the task exceeds the watchdog time, the task will be stop with an error signal.

Time: (Example t#200ms), if this time is exceeded the task will be stop. Depending on the target settings, the time has to be entered as a percentage value of the cycle time. The time block is gray, and there will be a % sign.

Sensitivity: here an integer number is entered that will be displayed as an error when the watchdog time is exceeded. NOTE! If a 0 is entered the watchdog is switched off.

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-47

Each task can call an unlimited amount of POU‟s.

For each task a priority number, between 0 and 31should be given.

A watchdog can be defined for each task.

With a “large” project with several hundred I/O‟s, between 3 to 5 tasks should be defined.

Switching from one task to the next takes approximately 10µs.

Codesys processes all POUs and any configured tasks independent of the underlying operating system.

If the underlying operating system is capable of multitasking, then it can carry out other tasks parallel to Codesys. Such a parallel task could for example be used to interrupt a running Codesys task that has got stuck in an endless loop. If the

underlying operating system is non-multitasking, then the entire controller will have to be reset to factory settings.

A-48

CHAPTER 6 : HARDWARE CONNECTION AND

TESTING

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-49

6.1 Controller connection

In this course we use a CECC, with 14 digital inputs and 8 digital outputs. It also has USB, Ethernet and CANopen interface on-board.

Figure 52

At the back is a 230V AC socket. Place the cord with the plug in the socket and turn the power on.

Device supply voltage X1

Pin Signal Comment

X1.1 24V U+ (electronic)

X1.2 0V U- (GND)

X1.3 GND Functional earth

X1.4 n.c. Not connected

I/O interface X2, X3 and X4

Pin Comment

X2.0 ..X2.1 Fast digital inputs (200kHz) X2.2 … x2.7 Digital Inputs (1 kHz) X3.0 … X3.5 Digital Inputs (1 kHz) X4.0 … X4.7 Digital outputs (500mA)

A-50

Supply voltage I/O X5

Pin Signal Comment

X5.1 24V U+ (I/O supply)

X5.2 0V U- (GND)

CAN open interface X6

Pin Signal Comment

1 n.c. Not connected

2 CAN_L1) CAN Low

3 CAN_GND CAN ground

4 n.c. Not connected

5 CAN_SHLD Connection to functional earth

6 CAN_GND CAN ground (optional)

7 CAN_H1) CAN high

8 n.c. Not connected

9 n.c. Not connected

1) If the CECC is located at the end of the cable, connect pin 2 and pin 7 with the help of a termination resistor (120 ohms/0,25W)

Ethernet interface X8

Load voltage supply IO-Link X11 (CECC-LK)

Pin Signal Comment

X11.1

24V

Connection for load voltage supply via IO-link master ports: UA+

X11.2 X11.3

0V

Connection for load voltage supply via IO-link master ports: UA- (GND)

X11.4

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-51

Communication interface IO-Link master (CECC-LK) X12, X13, X14 and X15

C/Q Communication signal IO-Link

X12.3,

X16.2 C/Q Communication signal IO-Link

X16.3 L- 0V

Status LED‟s

Pin Comment

Run Status of the application

Net Device detected

Error Error

Mod Reserved

Connecting CECC-LK to your PC

Plug the RJ45 crossover Ethernet cable into the Ethernet socket and the other end of the cable into the PC.

If you use a Hub, Switch or Router between the PC en de CECC-LK a 1:1 Ethernet cable can be used.

Use a screened LAN/Ethernet cable (shielded twisted pair, STP) from Cat 5/5e/6/7 for this.

A-52

6.2 Testing

Create a standard CECC project, use the “CECC template” “I_O_Test”

The (POU) program should be of the type Structured Text (ST) write only a semicolon “;” in it.

Open the input window and switch on “Always update variables”.

Open the output window and switch on “Always update variables”.

Download this project to the controller.

Activate the program.

Now you can “see” in the input window dynamically the actual status of the inputs.

When you switch to the output window, you can change the status of each output by placing the new value behind the output and use Ctrl + F7 to send this value to the controller.

This project can be used when you want to test only the I/O of the system.

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-53

A-54

CHAPTER 7 : MOTIONSTEP DIAGRAM

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-55

7.1 The Motion step Diagram

To create a universal working solution, regardless of which programming language will be used, we make use of a motion step diagram.

In the following sections the various parts of the motion diagram is explained. First we make a basic representation of the actuator movement from the rest position to the activated position, and vice versa. Then we will discuss the steps to get from a problem to a solution.

7.2 The Grid

The vertical lines in the diagram are called step. This is numbered from 1 to xx; the last step is equal to the step 1.

At the top of the diagram between two horizontal lines the action of the actuators is indicated. The bottom line indicates that the actuator is at rest, and the top line indicates the actuator is in the activated position.

Figure 53

The active position of the top cylinder marked with the letter A, has a digital value 1.

The active position of the second cylinder marked with the letter b, has a digital value 2.

The active position of the third cylinder marked with the letter c, has a digital value 4.

On each step the corresponding value should be recorded, and eventually added up, from top to bottom.

A

A-56

Each step will have a unique number. As soon as two steps have the same value, then a memory has to be used to differentiate between the two steps. This memory is called a “make uneven memory”.

There is one exception to the rule. If two consecutive steps have the same value, then a timer is used, and then a memory is not needed.

7.3 The rest position of an actuator

In the rest position the xx0 sensor is always activated. (See Figure 45).

Figure 54

The actuators are labels in capital letters and the sensors in small letters.

The memories that will be used are drawn under the actuators (cylinders).

7.4 The Memories

Figure 55

The memory cannot be activated or deactivated on the step where the numbers are the same.

The set and reset (of the bi-stable memory must be changed to a mono-stable memory) G

setG

reset

When two consecutive steps have the same number, timers is used to activate and deactivate the actuator. A memory is not needed

G1

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-57

7.5 The Signals (Sensors)

The signals are placed under the memories.

Figure 56

Above the line the signal is 1, and below the line the signal is 0.

The red squares indicate when a signal changes from a 0 to a 1.

The signals do not switch on the steps lines. Switch on happens just before the step line, and switch off happens just after the step line.

At the Start the red square is just before step 1, because that is the point when it is activated. The stipple line indicates that the Start signal can be on for a longer period.

7.6 The Actions

Figure 57

The red dot indicates where the action should start.

The horizontal line indicates for how long the action in active.

To perform an action, look above for a rising signal (signal that goes from a 0 to a 1).

Because this is the first step we also look for the last signal that was activated.

The formula for A+ should then be:

0 a Start A   

The formula for A- should then be:

1 a A  

When sensors are used twice then a relay which has multiple contacts has to be used.

7.7 Example without using a memory

Here is a solution using a motion step diagram using two cylinders and no memory.

Start

A-58

Figure 58

Step 1: Draw the motion of the actuators

Step 2: Check for the digital values that appear more than once Step 3: Draw the signals (sensors)

Step 4: Draw the actions to take place Step 5: Note the Boolean formulas

Step 6: Determine the length that actions are activated Step 7: Check for overlapping actions (shorten if necessary)

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-59

7.8 Example using a memory

Here is a solution using a motion step diagram for two cylinders using a memory.

Figure 59

Step 1: Draw the motion of the actuators

Step 2: Check for the digital values that appear more than once Step 3: draw the memories

Step 4: draw the signals (sensors) Step 5: Note the memory formulas Step 6: Draw the actions

Step 7: Note the Boolean formulas

Step 8: Determine the length the action is activated

Step 9: Check for overlapping actions (shorten if necessary)

Here we see to activate the memory, the primary signal combination “Start AND a0”

is used. If we look at the signal needed for “A+” then we can use the same signals.

But because “Start AND a0” is used to activate the memory, we use “G1”for “A+”.

Here we see how primary and secondary signals are used in the formulas.

Start

A-60

7.9 Example using a timer and a memory

Here is a solution using a motion step diagram for two cylinders using a timer and a memory.

Figure 60

Step 3 and 4 has the same value “3“. This will only happen when a timer is used. The timer has two parts, the timer “T” and the contact “t”. As soon as the start condition for the timer is true “1”, the timer starts timing. When the preset time has elapsed the timer contact “t” switches.

Step 1: Draw the motion of the actuators

Step 2: Check for the digital values that appear more than once Step 3: Draw the memories

Step 4: Draw the timer (T en t) Step 5: Draw the signals (Sensors) Step 6: Note memory formulas Step 7: Note formula for Timer T Step 8: Draw actions

Step 9: Note Boolean formulas

Step 10: Determine the length the action is activated

3

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-61

Step 11: Check for overlapping actions (shorten if necessary) 7.10 Example of a counter for the entire cycle

The whole sequence is repeated 5 times.

Figure 61

Between step 4 and 5 it is indicated that the sequence should be repeated a number of times. Extra steps should be taken to prevent the machine to start automatically when the supply is switched on. Using an extra memory will prevent this from happening.

Start must be replaced with G2. The set command is Start en the reset command is C.

Start

A-62

7.11 Example using a counter in the cycle

In this example cylinder B must move 5 times, then cylinder A is retracted in rest position. Cycle is finished.

F Figure 62

Between step 3 and 4 it is indicated that cylinder B should repeat a number of cycles.

Extra steps should be taken to prevent the machine to start automatically when the supply is switched on. Using an extra memory will prevent this from happening.

Start must be replaced with G2. The set command is Start en the reset command is C.

Start

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-63

A-64

CHAPTER 8 : SEQUENTIAL FUNCTION CHART

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-65

8.1 Sequential function chart

This solution is most suitable for sequential controllers. The BS EN IEC 60848:2002 is the standard in French and English. The BS 5848:1993 is the standard in Dutch and English. Both standards give the description of the symbols, and use a graphic representation of the control problem.

In the following sections we will discuss the symbols, the functions, and operations used in the diagrams.

8.2 The basic symbols

The function diagram is designed using the following symbols.

Figure 63

Each function diagram starts with an initiating step. Below the step is a horizontal line. This is where a condition is entered. This condition has to be met before going to the next step

Between the steps is the condition that has to be met before going to the next step. Once the condition is met, the previous step becomes inactive and the next step becomes active.

Once in the step the actions will be carried out.

In the “ini” step no actions is entered, except for loading timers and counters. If the PLC is in run mode this step becomes active immediately.

Figure 64

Ini

Initiating step Step

Ini

Condition

Condition Action

Action

A-66

More than 1 action can be connected to an action.

An action is represented in a square

Figure 65

In this way action is linked to one step.

To ensure proper functioning of the SFC it is important to have a condition that has to be met between the steps.

8.3 Unconditional Jump

In SFC it can happen that a jump function has to be performed between steps. Thus we get the “conditional jump” and the “unconditional jump”.

After step 3 a jump function will be performed, and jump back to the "ini”

step. Step 4 will never be performed.

Figure 66

Action 1

Action 1 Action 2 Action 3

Action 1 Action 2 Action 3

1 Ini

2

3

4

The unconditional jump

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-67

8.4 Conditional Jump

A condition jump can also be called a destination jump.

Depending on the condition that is true, the corresponding branch will be executed.

Here a destination is made between the left and the right branch in SFC, depending on the condition.

Only one of the branches will be performed. This is referred to as an OR function.

Figure 67

1 Ini

2

3

4

5

6

The conditional Jump

A-68

8.5 Parallel Branches

In some cases it is necessary that several branches of the SFC must run simultaneous.

It will look as follows:

Figure 68

Both branches are processed at the same time. This is referred to as an AND function.

1 Ini

2

3

4

5

6

Start of simultaneous operation

End of simultaneous operation

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-69

8.6 Step Memories

A sequential function chart is a simplified version of a motion step diagram.

Before each step we need to make use of a memory.

Figure 69

For the program we use the following memories:

G0 before step ini, G1 before step 1, G2 before step 2, G3 before step 3, G4 before step 4.

A-70

First we need to create the steps G0set = G4 • b0 + ini

G0reset = G1 G1set = G0 • Start G1reset = G2 G2set = G1 • a1 G2reset = G3 G3set = G2 • b1 G3reset = G4 G4set = G3 • a0 G4reset = G0

Two memories will always be active.

8.7 Actions

Actions with the use of bi-stabile valves, uses the following formula:

A+ = G1 A- = G3 B+ = G2 B- = G4

If A used a mono-stabile valve, then the following formula is used:

A+ = G1 + G2

(A- = G3 is not used in this application) B+ = G2

B- = G4

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-71

A-72

CHAPTER 9 : RECOMMENDATIONS FOR NAMING

IDENTIFIERS

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-73

Naming of identifiers

Identifiers are defined at the declaration of variables (Variable names), user-defined data types and at the creation of POUs (functions, function blocks, programs) and visualizations. You might follow the following recommendations concerning the naming of identifiers in order to make it as unique as possible.

9.1 Identifiers for variables (variable names)

The naming of variables in applications and libraries as far as possible should follow the Hungarian notation:

For each variable a meaningful, short description should be found, the base name.

The first letter of each word of a base name should be a capital letter, the others should be small ones (Example: FileSize). If needed additionally a translation file for other languages can be created. Before the base name, corresponding to the data type of the variable, prefix(is) is added in small letters.

* Pointedly for BOOLean variables x is chosen as prefix, in order to differentiate from BYTE and also in order to accommodate the perception of an IEC-programmer (see addressing %IX0.0).

Data type lower limit upper limit Information content

A-74

Examples:

bySubIndex: BYTE;

sFileName: STRING;

udiCounter: UDINT;

In nested declarations the prefixes are attached to each other in the order of the declarations:

Example:

pabyTelegramData: POINTER TO ARRAY [0..7] OF BYTE;

Function block instances and variables of user-defined data types as a prefix get a shortcut for the

FB- resp. data type name (Example: sdo).

Example:

cansdoReceivedTelegram: CAN_SDOTelegram;

TYPE CAN_SDOTelegram : (* prefix: sdo *) STRUCT

Local constants (c) start with prefix c and an attached underscore, followed by the type prefix and

the variable name.

Example:

VAR CONSTANT

c_uiSyncID: UINT := 16#80;

END_VAR

For Global Variables (g) and Global Constants (gc) an additional prefix + underscore is attached to the

library prefix:

Appendix J: - Recommendations on the naming of identifiers Codesys V2.3 10-105

9.2 Identifiers for user-defined data types (DUT)

The name of each structure data type consists of a library prefix (Example: CAN), an underscore and a preferably short expressive description (Example: SDOTelegram) of the structure. The associated prefix for used variables of this structure should follow directly after the colon.

Codesys for Industry V3.5 [version 1.3] ۰Festo Didactic

A-75

A-76

Example:

TYPE CAN_SDOTelegram : (* prefix: sdo *) STRUCT

wIndex:WORD;

bySubIndex:BYTE;

byLen:BYTE;

abyData: ARRAY [0..3] OF BYTE;

END_STRUCT END_TYPE

Enumerations start with the library prefix (Example: CAL), followed by an underscore and the identifier in capital letters.

Regard that in previous versions of Codesys ENUM values > 16#7FFF have caused errors, because they did not get converted automatically to INT values. For this reason ENUMs always should be defined with correct INT values.

Regard that in previous versions of Codesys ENUM values > 16#7FFF have caused errors, because they did not get converted automatically to INT values. For this reason ENUMs always should be defined with correct INT values.

Related documents