Sie sind auf Seite 1von 21

Introduction into Programming with LAD/FBD

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.1

Content Page
Programming with Ladder Diagram (LAD) ......................................................................................... 2
Programming with Function Block Diagram (FBD) ............................................................................ 3
Opening or Creating LAD/FBD Units ................................................................................................. 4
Unit Variables of a Source ................................................................................................................. 5
Opening or Creating LAD/FBD Programs .......................................................................................... 6
Inserting a Network into an LAD/FBD Program ................................................................................ 7
Inserting Bit Operations into LAD ....................................................................................................... 8
Inserting Bit Operations into FBD ...................................................................................................... 9
Inserting Comparators into LAD/FBD ................................................................................................ 10
Assigning the Output of a Network ..................................................................................................... 11
Inserting Complex Operations ........................................................................................................... 12
Operations with Memory Behavior (times, counters, ...) ................................................................... 13
Assigning Call Parameters ................................................................................................................ 14
Calling Functions and FB Instances .................................................................................................. 15
Assigning Blocks or Boxes ............................................................................................................. 16
Assigning Created LAD/FBD Programs to a Task ............................................................................. 17
Compiling and Downloading a Project .............................................................................................. 18
Downloading a Program in the Run State ......................................................................................... 19
Monitoring an LAD/FBD Program ...................................................................................................... 20
Setting Breakpoints in LAD/FBD Programs ...................................................................................... 21

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 1 Programming in LAD/FBD
Programming with Ladder Diagram (LAD)

Menu bar

Declaration section
Project
navigator

Statement section

Detail window, e.g.


for monitoring
variables

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.2

Ladder Diagram LAD is a graphic programming language for solving automation tasks. The
(LAD) syntax for the instructions is similar to a circuit diagram.
If LAD is used in programs with cyclic tasks, representation in LAD corresponds
to the flow of current between power rails via inputs, outputs and operations.
This way LAD makes it easy to follow the signals. LAD is less suitable for
representing motion sequences in motion tasks.
LAD statements consist of elements and boxes, which are graphically
connected to networks. The rules of Boolean logic apply to LAD operations.
The programming language LAD provides all elements that are required for
creating a full user program. LAD has a very powerful set of commands. It
includes various basic operations with a comprehensive range of operands and
ways to address them.
The concept of functions and function blocks allows the user to structure the
LAD programs in a clear, comprehensive manner.

Integration in Each of the components of the LAD programming environment is easy and
SIMOTION SCOUT convenient to use and is integrated directly into the SCOUT Workbench.
• Project navigator: The project navigator displays the project structure and
provides an overview of all programs that have been created. The project
navigator can be used for example to create new LAD programs.
• Work area: The work area contains the LAD editor which displays the
declaration part for declaring variables and data types, and the statement
part for creating the individual networks of a LAD program.
• Detail view: Variables, alarms, error messages, etc. are displayed in this
window. The display depends on the element selected in the project
navigator.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 2 Programming in LAD/FBD
Programming with Function Block Diagram (FBD)

Switch LAD <--> FBD

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.3

Function Block FBD is also a graphical programming language for solving automation tasks.
Diagram (FBD) The syntax of the instructions uses the logic boxes familiar from Boolean
algebra to represent the logic.
Just the same as in LAD, complex functions (for example, math functions) can
be called directly in conjunction with the logic boxes, like e.g.
If FBD is used in programs with cyclic tasks, the representation in FBD
corresponds to the flow of results of logic operations. Links to the logical boxes,
for example: AND, OR boxes etc. are connected to the input signals, the result
of logic operation is shown on the right. This makes it also easy to track signals
in FBD. FBD is less suitable for representing motion sequences in motion tasks.
FBD instructions consist of boxes that are graphically connected to form
networks. The programming language FBD provides all elements that are
required to create a full user program. FBD has the same powerful command
set and offers the same possibilities as LAD.

Toggling between You can toggle between LAD and FBD display modes in the editor:
LAD <--> FBD Proceed as follows:
1. Open an existing block (program, FB, FC).
2. Select the menu command: LAD/FBD program -> Switch to FBD (LAD) or
select the "Switch to FBD" icon in the function bar.
The block is displayed in the selected display mode.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 3 Programming in LAD/FBD
Opening or Creating LAD/FBD Units

Name of the source

Permit status
program

LAD/FBD source

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.4

LAD/FBD units SIMOTION SCOUT supports the concept of units when programming with
LAD/FBD. After a unit has been created, as many LAD/FBD programs as
required can be inserted. A unit serves as a container for all of the LAD/FBD
programs Further, global unit variables can be created within LAD/FBD units.
These unit variables are roughly comparable with the data blocks in a SIMATIC
S7.
Using this unit concept, for example, all LAB/FBD programs, FB and FC as well
as variables, which are required to control a piece of equipment of a machine
(roller feed, tool changer, etc.), are combined in a unit.
In particular, a unit, i.e. all of the programs contained in it, can be protected
against unauthorized access (Context menu -> Know-how protection). Then, a
password must be entered in order to open or view protected units and all the
associated blocks.

Inserting a unit A new LAD/FBD unit can, e.g. using the help of the project navigator, be
inserted into the "PROGRAMS" folder using the element "Insert LAD/FBD unit.

Settings Under the "General " tab of the property dialog (Select unit -> Context menu - >
Properties) the following settings can be made:
• Name: The name of the unit is specified here (from V4.1, max. 128
characters)
The same settings can be defined as for MCC units under the "Compiler" tab.
This is the reason that only the most important are listed here:
• Selective linking: Unused code is removed from the executable program.
• Permit program status: This setting must be selected if you want to perform a
test using the block status later on.
• Permit OPC/XML: Symbol information of the unit variables of the interface
section of the unit are available in the SIMOTION device (necessary for the
functions _exportUnitDataSet and _importUnitDataSet)

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 4 Programming in LAD/FBD
Unit Variables of a Source

INTERFACE variables:
• Access possible by all blocks in
the unit
• Access possible by other units
• Access possible by HMI devices

IMPLEMENTATION variables:
• Access possible by all blocks in
the unit
• Access not possible by other units
• Access not possible by HMI devices

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.5

Unit variables A unit not only serves as a container for programs, in the declaration part of a
unit, what are known as unit variables can be declared. The validity range
(scope) of the variable is dependent on the section of the declaration table in
which the variable is declared:
• If a variable is declared in the interface section (INTERFACE) of the
declaration table, then this variable is valid in the complete unit all programs,
function blocks and functions which were inserted in the unit can access it.
In addition, blocks which were inserted in other units can also access these
variables (global variables).
INTERFACE variables are also available on HMI devices, this means that an
HMI device can also access these variables. The total size of all unit
variables in the interface section is limited to 64 KB.
• If a variable is declared in the implementation section (IMPLEMENTATION)
of the declaration table, this variable is only valid in the unit. All programs,
function blocks and functions of the unit can access these variables.
Access from other units or from HMI devices to these variables is not
possible.

Variable type The following variable types can be selected:


• VAR_GLOBAL: Program-global variable; If you want to access this variable
from a block in another unit, you need to define a link in the other unit in the
INTERFACE section, tab "Connection" to the unit with the variable
declaration.
• VAR_GLOBAL_RETAIN: permanently saved global variables; are retained
after power failure.
• VAR_GLOBAL_CONSTANT: global constants; cannot be changed from
the program.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 5 Programming in LAD/FBD
Opening or Creating LAD/FBD Programs

Declaration section
for local variables

Open
LAD/FBD program
Properties dialog box
Statement section

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.6

Open LAD/FBD You can open an existing LAD/FBD program by double-clicking on the program
program icon in an LAD/FBD unit. After opening, the LAD/FBD program is displayed in
the workspace.

Insert LAD/ A new LAD/FBD program can be inserted into an LAD/FBD unit via the element
FBD program "Insert LAD/FBD program" After inserting an LAD/FBD program, the properties
dialog is opened to make the appropriate settings.

Settings You can make the following settings in the "General" tab sheet:
• Name: Here you enter the name of the program or function block or function
to be created (within the surrounding unit). This name can consist of up to
80 characters.
• Creation type: Here you can select whether the created LAD/FBD program
is to describe a program, function block or function.
• Exportable: If the check box is activated, an LAD/FBD block can be called
from other program units (e.g. MCC units, ST units) in the same manner as,
for example, a function or a function block.
A program can only be assigned to a task with activated checkbox.
If the checkbox is deactivated, this LAD/FBD block can only be called by
blocks of the associated LAD/FBD unit

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 6 Programming in LAD/FBD
Inserting a Network into an LAD/FBD Program
Toggling between:
LAD <--> FBD Insert network

Network

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.7

Insert networks Every LAD/FBD program in SIMOTION SCOUT comprises a collection of


individual networks. Elementary logic operations are programmed as well as
functions or function blocks are called in networks.
Before you start to program instructions, you must first insert one or several
networks into an LAD/FBD program.
Networks can be inserted into LAD/FBD programs in various ways:
• Using the associated icon "Insert network" in the toolbar
• Using the command from the context menu "Insert network"
• Using the menu command LAD/FBD program > Insert network.

Select For example, to copy a network, it must first be selected. A network is selected
networks by clicking on it. You can select several networks, by clicking on the first network
required and with the Shift key pressed, click on the last network required.
Selected networks are indicated by a light blue edge on their left-hand side. For
example, selected networks can be deleted, copied, and reinserted at a different
location.

Numbering When a network is inserted, it is automatically given the next consecutive


networks number. This number is unique and is used to identify the network, for example,
in the cross-reference list.
The user is not able to change the numbering. The networks are automatically
renumbered after a network has been deleted.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 7 Programming in LAD/FBD
Inserting Bit Operations into LAD

NC and NO contacts

Drag&drop

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.8

LAD representation The LAD diagram complies with Standard IEC 61131-3 and is structured around
the binary ladder diagram. The ladder diagram line begins with a vertical line
(power rail) and ends with a coil, call (box) or with a jump to another network.
In between the power rail and output there are special LAD elements (NO
contacts, NC contacts, connectors), general logic elements (comparator, SR,
RS flipflop), complex function calls (e.g arithmetic operations).

LAD/FBD Binary LAD/FBD elements can be inserted into a network in the following
elements fashion:
1. Click on the required location of the ladder diagram (LAD) or select an input
or connection line (FPD).
2. Insert the LAD/FBD element, either:
• by clicking on the corresponding icon in the LAD/FBD toolbar
• using the context menu, for example -> Insert element -> Comparator
• by dragging and dropping from the command library
After inserting, the LAD/FBD elements must be labeled, i.e. mandatory
parameters shown in red need to be specified with the addresses or names of
the associated operands.

Selecting LAD/FBD For example, to delete LAD/FBD elements, these must first be selected. An
elements LAD/FBD element is selected by clicking on it. You can select several LAD/FBD
elements by keeping the Ctrl key pressed and then clicking on the appropriate
LAD/FBD elements.
Selected LAD/FBD elements are identified by a thick blue frame. For example,
selected LAD/FBD elements can be deleted, copied, and reinserted at a
different location.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 8 Programming in LAD/FBD
Inserting Bit Operations into FBD

Drag&drop

Context menu

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.9

FBD representation The FBD diagram complies with Standard IEC 61131-3 and is structured around
the binary ladder diagram. The main binary signal path starts with a logic box
(top left) and ends with an assignment, call (box) or with a jump to another
network.
In between, there are logic elements (AND, OR box), general logic elements
(SR, RS flipflop), system components calls (e.g arithmetic operations), and
functions or function blocks.

Binary operations Bit logic operations interpret the signal states 1 and 0 of the operands and gate
them according to the rules of Boolean logic. The following bit operations are
available in LAD or FBD:
• --| |--- NO contact AND box
• --| / |--- NC contact OR box
• XOR exclusive OR gate XOR box
• --( ) Relay coil, output --[ = ]
• ---( # )--- Connector --[# ]--
• ---|NOT|--- invert signal state --o
Some operations react to a rising or falling edge change, so that you can
perform one of the following operations:
• ---(N)--- scan signal edge 1 -> 0 --[N]--
• ---(P)--- scan signal edge 0 -> 1 --[P]--
• NEG scan signal edge 1 -> 0 --NEG--
• POS scan signal edge 0 -> 1 --POS--

Assign Assigning input and output parameters of boxes, which were inserted into
parameter an FBD network, can either be realized by entering the variable name or by
dragging the variable from the declaration window or symbol browser and
dropping it to the parameter.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 9 Programming in LAD/FBD
Inserting Comparators into LAD/FBD

Comparator

Symbolic input help

Drag&drop

Symbol browser

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.10

Comparators Comparators play a special role when programming with SIMOTION.


Comparators can be used to compare not only arithmetic values such as INT or
REAL numbers with one another, but can also be used to evaluate enumeration
data types.

Evaluating
enumeration To identify states in the system variables of technological objects (TO), such as
data types "axes", SIMOTION only uses enumeration data types.
For example, the system variable "Error" of technology object "Axis", which
indicates the occurrence of an error, does not accept the values "TRUE" or
"FALSE" of data type BOOL, but values "yes" and "no" of the enumeration type
"enumyesno". Operands of BOOL data type can be evaluated using boolean
operations, for example AND, OR, XOR. On the other hand, enumeration type
operands can only be evaluated for equality and inequality using comparison
operations.

Inserting and Comparators can either be inserted using the icon from the toolbar or directly
connecting taken from the "Comparator" command library with drag& drop and inserted at
comparators the required position in an LAD/SBD network. The inputs of a comparator can be
directly connected with the required operand/system variable manually or by
drag& drop
For system variables, you must first select the desired TO in the project
navigator before opening the symbol browser window (detail view) by clicking on
the "Symbol browser" tab. And then select the system variable from the first
column and drag it to the required input of the comparator.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 10 Programming in LAD/FBD
Assigning the Output of a Network

Operation for
network output

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.11

Operation for The end of a network must be terminated with an appropriate Boolean output
network output operation. Using these operations, especially variables, data type BOOL, can be
assigned new values as well as query and jump operations implemented.
The following operations are available for a network output:
• ---( )--- assign output (= instruction)
• ---(S)--- set output
• ---(R)--- reset output
• ---( JMP )--- jump if power flow (signal flow)
• ---( JMPN )--- jump if no power flow (signal flow)
• ---( RET )--- end block if power flow (single flow)
You assign corresponding output operations by selecting the output coil Select
the required operation from the open list.

Note The output of a network does not necessarily have to be assigned/connected, it


can also be deleted. To do this, select the network output and press the<DEL>
key.

Assigning If a new value is to be assigned to an enumeration data type, then this is not
enumeration realized via the assignment at the network output, but but must be realized using
data types what is known as a MOVE box.
The MOVE box is directly inserted from the command library "LAD elements" or
"FBD elements" in a network using drag& drop or can be realized using what is
known as the "empty box".
Using a MOVE box, variables with a numerical data type – such as INT, REAL,
etc. – can be assigned any values. The MOVE box corresponds to the =
operation of a high-level language, for example ST (Structured Text).

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 11 Programming in LAD/FBD
Inserting Complex Operations

Empty box

"Empty box"

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.12

Complex Complex operations such as e.g.: arithmetic operations can either be directly
operations inserted from the command library, or realized using what is known as the
"empty box". For an "empty box", the actual functionality itself, for instance
adder, converter etc. are selected from a list after insertion. User-defined
functions and function blocks can also be called using the "empty box".
Proceed as follows to insert an "empty box" at a certain location in the circuit:
1. Select the required position in the circuit.
2. Insert the "empty box", either
• Using the associated icon in the LAD/FBD toolbar
• Using the menu item, e.g., LAD/FBD program > Insert element > Empty box
• By dragging and dropping from the command library The command library
can be opened in the window of the project navigator from the "Command
library" tab.

Select command After inserting the empty box, the actual command can be selected from a list.
To do this, select the three question marks "???" of the "empty box" and select
the required command from the open list.
After selecting the command, the corresponding operands are displayed in the
box The following functions can be implemented using the empty box:
• Assignments (MOVE)
• Arithmetic operations (ADD, SUB, MUL, DIV, SIN, etc.)
• Conversion (BYTE_TO_SINT, etc.)
• Timers, counters, SR, RS flip-flops etc. (these must be instantiated)
• MUX, SEL, MIN, MAX, LIMIT
• FC and FB calls.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 12 Programming in LAD/FBD
Operations with Memory Behavior (timers, counters, ...)

Dialog for declaration

Name of the instance

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.13

Operations with Operations with memory behavior require a memory area to save the internal
memory behavior state (e.g. counter state for counters, expired time for timers, setting for flip-
flops). The user must provide this memory area by creating an instance
(variable).
The instance can be created before actually calling the operation or using a
dialog while inserting and assigning.
Operations with memory behavior can only be used in cyclic tasks, for example
BackgroundTask or TimerInterruptTask.
Operations with memory behavior include:
• Counters: (CTU: Up counters, CTD: Down counters, CTUD: Up and down
counters)
• Timers (TP: Time pulse, TON: ON time, TOF: OFF time)
• Flip-flops (RS: setting dominant, SR: reset dominant)
• Edge evaluation (R_TRIG: Rising edge, F_TRIG: Falling edge)

Select operation The required operation (timers, counters, etc.) can either be inserted directly
from the "system function block" library or via the "empty box" into the required
network.
If the "empty box" is used, then initially the required data type must be selected
from the list The instance name must then be entered in the field above the box.
If the instance has still not been declared, then a dialog "Variable declaration" is
automatically opened to enter the variable type, initial value, comments etc.
After the dialog has been acknowledged, the instance declaration is
automatically entered into the declaration part of the LAD/FBD Editor.

Displaying Using the "Display" command of the context menu, you can select whether, for
parameters example all or only the assigned and mandatory parameters of a box are
displayed.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 13 Programming in LAD/FBD
Assigning Call Parameters

Double-click

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.14

Assigning Finally, the parameters of the inserted operation can be assigned. The
parameters parameters can also be assigned using a dialog box.
To do this, proceed as follows:
1. Double-click on the box or in the context menu, select the command
"Parameterize call ...."
The dialog box "Enter call parameter" is opened. Only the already declared
variables or icons or variables provided by the system are listed for selection.
2. Enter the following:
- Return value: Here, you assign the return value of the function a variable
of the calling program.
- Instance: Here, you enter the instance of the function block.
- Value: Here, you can assign actual variables or values to the parameters.
3. Confirm your selection with OK.

Note The Value list contains all of the symbols that are visible in the actual target
(variables, enumeration values etc.) whose type matches the parameter data
type. Implicit data type conversion is taken into consideration here. You can
select a symbol from the list or enter one yourself.
The value of string constants must be entered in inverted commas
(e.g. 'st_until')

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 14 Programming in LAD/FBD
Calling Functions and FB Instances

Declare instance

Drag&drop

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.15

Functions and Local functions and function blocks as well as system functions and system
function blocks function blocks can also be called using the "empty box", or can be directly
inserted into a network from the project navigator window by dragging &
dropping or from the command library.
Proceed as follows to call a block:
1. Ensure that the FB/FC to be called are "visible" in the LAD/FBD program. If
required, insert the corresponding connections to the units or libraries in the
declaration part.
- System functions and system function blocks are always reachable.
- For FB/FC from other programs (LAD/FBD/ST/MCC) or libraries, enter
the appropriate units into the "Connections" tab in the declaration part.
- For TO functions, the appropriate TP configuration must be set at the
device.
2. Then insert an "empty box" into your LAD/FBD program at the required
location in the network, or drag the required function or function block from
the window of the project navigator, and drop it at the required location in the
network.
3. In the 1st case, in the entry field, enter the name of the calling function or the
name of the function block. For a function block, the instance name must
then be entered.
If the instance has still not been declared, then the "Variable declaration"
dialog box is automatically opened. The necessary entries to declare the
instance can be entered there. In this case, the procedure is identical to the
"procedure for operations with memory behavior"
4. Assign the input and output parameters of the called block with the required
actual operands. To do this, double-click on the block to open the "Enter call
parameters" dialog box.
5. Confirm your selection with "OK".

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 15 Programming in LAD/FBD
Assigning Blocks or Boxes

1. Double click on the box

2. Context menu:
"Symbolic input help"

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.16

Connecting From V4.0 and higher, there are now two options to supply input and output
boxes parameter boxes in a user-friendly fashion with actual operands.
1. Option (connecting all parameters using a dialog box)
A connection dialog is opened by double clicking on the box. All parameters
with name, data type and where relevant, default assignment are listed in
this dialog.
In the "Value" column, the actual operand can be selected from the list or
can be directly entered. After all of the parameters have been connected, the
dialog is closed using the "OK" button.
2. Option (connect individual parameters)
Using the command: "Symbol input help..." from the context menu of an
operand, the "Symbol input help" dialog can be opened.
Into this dialog, all of the symbols of the projects are listed, i.e. all system
and user variables with data type and access information for the connection.
The selected symbol can be accepted by selecting a symbol and then
clicking on the "OK" button.

Note Of course you can also drag the required actual operand from the declaration
part or from the symbol browser window and drop it at the parameter – or
directly enter the name and/or value.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 16 Programming in LAD/FBD
Assigning Created LAD/FBD Programs to a Task

Double-click on
"Execution system" Selected task

Assigned
program

Click to select
the task

Select + assign
program

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.17

Compiling Before you can assign an LAD/FBD program in the execution system to a task
LAD/FBD blocks or before you can call a function or function block from the program, the
programs, functions and function blocks that have been created, must be
compiled.
If, when compiling the project, errors in the individual blocks are displayed, then
the errors must first be removed before the program in the execution system
than can be assigned to the task.
To do this, proceed as follows
1. Opened the program in the editor.
2. In the toolbar, select the button "Accept and compile" or select the source
with the program and from the context menu select the command "Accept
and compile".

Task assignment Follow the steps below to assign a program to a task:


1. In the project navigator double-click on the EXECUTION SYSTEM object
below the required SIMOTION device. The window for configuring the
execution system is opened.
2 In the left-hand section of the window, select the desired task (e.g.
BackgroundTask). The selected task is also displayed in the output window
of the window section on the right-hand side.
3. Click the "Program assignment" tab and select the required program in the
"Programs" selection list.
4. Click on the ">>" button. The selected program is displayed in the list of
"used programs".
5. Select the "Task configuration" tab and define any additional settings for the
task there.
6. Click "Close" to confirm what you have entered. The settings that have been
made will be accepted in the project data.
Before the project can be loaded into the target system, the complete project
must be compiled.
SITRAIN Training for MC-SMO-SYS
Automation and Drive Technology Page 17 Programming in LAD/FBD
Compiling and Downloading a Project
Save and compile
the project Establish an online Load project
connection

Compile LAD/FBD
program Load the project
into the selected target system

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.18

Download to The intermediate code generated in SIMOTION SCOUT can be downloaded


target device after a connection has been established with the target system (online channel).
Follow the steps below to download a project to the target system:
1. First check the consistency of the program by selecting the menu command
Project -> Check Consistency.
2. Compile the entire project again including all dependent files. To do this,
select the menu command: Project -> Save and Compile All or the
equivalent icon on the toolbar.
3. Go online with the target system: To do this, use the menu command
Project -> Connect to target system or the corresponding icon in the
toolbar.
4. Download the project to the target system. To do this, use the menu
command Target system-> Download -> Project to target system or the
corresponding icon in the toolbar.
In this case, the project data of all devices of the project are loaded. Whether
also the data are loaded into the drive units depends on the settings in the
dialog: Options -> Settings -> Download.
Alternatively, the project data can be downloaded into individually selected
devices using the command: Target system -> Download-> To target device.

Note If, when compiling the project, errors are displayed in the individual programs,
then you must separately compile the corresponding program and/or the
associated unit.
To do this, open the program in the editor and in the toolbar, select the button
"Accept and compile" or select the source with the associated program and from
the context menu select the command "Accept and compile".
All blocks belonging to the selected source are always compiled. In the detail
view (tab: "Output" compilation errors of the block are displayed. When double-
clicking on an error entry, the cursor jumps to the appropriate location in the
block

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 18 Programming in LAD/FBD
Downloading a Program in the Run State

Options > Settings > CPU download

Target device -> Load to target device

Allow download and


RAM2ROM in RUN

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.19

Download In order to make minor changes to programs and transfer them directly during
during RUN operation, you can download these changes to the target system in the RUN
operating state.

Notes • With download during RUN it is only permissible to change the code of the
user program and nothing else!
• For MotionTasks, the MotionTask must first be terminated before the code
can be changed. With cyclic tasks, the system will try for two seconds to
replace the code. If this is not successful, because e.g. long commands are
being processed, then the download is interrupted with the corresponding
message.
The function must be enabled via the SCOUT menu command: Options ->
Settings -> CPU download -> Permit download / RAM to ROM during RUN.
• The download during RUN must be performed using the menu command:
Target system - Download -> To target device or alternatively using the
corresponding symbol from the toolbar.

Procedure 1. After you have made changes in your program, click on the "Save and
compile" button.
The program is saved and compiled.
2. In the project navigator select the device under which you have carried out
the program changes, e.g. D435.
3. Right-click to open the context menu and select: Target device -> Download
to target device.
4. Click "OK" or "Yes" to confirm the prompts.
The changes are downloaded to the target device but are only in the RAM
and not in the ROM. If the data is to be saved to the storage medium of the
target device, select the command: "Copy RAM to ROM".

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 19 Programming in LAD/FBD
Monitoring an LAD/FBD program
Program status

Monitor and control variables

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.20

Program status Execution of an LAD program can be tracked/monitored using the "Program
status" test function. If the program execution monitoring is activated, the ladder
diagram lines/signal paths of the selected networks or the networks displayed
on the screen have different colors according to the status of the operation:
• GREEN: Signals a signal state of 1, true
• RED: Signals a signal state of 0, false
• LIGHT BLUE: Signals an unknown signal state, i.e. it is possible that this
network or this operation may not be processed.
The test function "Program status" can be selected using the associated symbol
in the LAD, using the commands of the context menu or the LAD menu.

Note In addition to the test function "Program status", the following test functions can
also be used, known from MCC:
• Monitor variable
• Watch tables
• Cross references list and program structure
• Trace tool

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 20 Programming in LAD/FBD
Setting Breakpoints in LAD/FBD Programs
Breakpoint toolbar
1. Select debug mode,
Define debug 5. Resume
task group, etc., program execution

3. Set or
Active activate breakpoint
breakpoint

2. Select network

Inactive
breakpoint

4. Monitor local
variables

SIMOTION Date: 09.02.2012 SITRAIN Training for


Automation and Drive Technology
Siemens AG 2012. All rights reserved. File: MC-SMO-SYS_06.21

Breakpoints From V4.0 and higher, in an LAD/FBD program, breakpoints can be set at
in LAD/FBD. networks. When program execution encounters an activated breakpoint, then
execution is stopped in front of this network.
The content of the local variables can be monitored in the detail window under
the "Variable status" tab. The global variables can be monitored in the symbol
browser.

Procedure the procedure is identical to the procedure with MCC charts. With the LAD/FBD
program in the online mode, proceed as follows:
1. For the corresponding SIMOTION device, select the debug mode and define
the tasks of the "Debug task group" i.e. the tasks which should be stopped
when reaching a breakpoint. If necessary, display the "Breakpoint" toolbar
2. Select the required network and click on the symbol "Set breakpoint". An
inactive breakpoint is displayed as an open red circle at the beginning of the
network.
3. Define the call path for the LAD/FBD program and activate their breakpoints.
An active breakpoint is displayed as a solid red circle. If program execution
encounters a breakpoint, then this is displayed using a small yellow arrow in
the red solid circle.
4. The instructions on the network have still not be processed Under the
"Status variable" tab, in the detail view, the local variables of the LAD/SBD
program can be monitored at this instant in time.
5. Program execution can be resumed via the "Continue" symbol in the toolbar.
Program execution stops when the next breakpoint is reached.

SITRAIN Training for MC-SMO-SYS


Automation and Drive Technology Page 21 Programming in LAD/FBD

Das könnte Ihnen auch gefallen