You are on page 1of 26

Programming in LD

Programming in LD The ladder diagram programming language is


designed for programming logic operations of binary
variables.
Programs are represented in LD by the following
graphical elements:
Scan a variable for status 1

Scan a variable for status 0

Assigning a current result (CR) or a constant to a


variable
Assigning a negated current result or a negated
constant to a variable
Set a variable if current result = 1

Reset a variable if current result = 1

Unconditional jump to a label

Jump to a label if current result = 1

Jump to a label if current result = 0

Unconditional return to invoking program

Return to invoking program if current result = 1

Return to invoking program if current result = 0


The representation of a program sequence in LD is
02/00 AWB 2700-1306 GB

similar to a current path running beween two current


rails. The rails are the vertical outer lines in the
display. A logic sequence is made by combining
individual contacts in series or in parallel.

77
Programming in LD

Retentive assignment
The current result can be assigned to the output
variable retentively. The output will then retain its set
or reset status.
Set
If the current result is 1, the output variable is set,
i. e. is set to 1. The 0 status of the current result has
no effect on the value of the output variable. Setting
is represented by an output symbol with an S in the
middle.

Just a momentary switching to 1 status on the


System_ON input will be enough to switch on the
plant permanently.
Reset
If the current result is 1, the output variable is reset,
i. e. is reset to 0. The current result 0 has no effect
on the value of the output variable. Resetting is
represented by an output symbol with the letter R in
the middle.
02/00 AWB 2700-1306 GB

83
Graphical Programming
Languages

Just a momentary switching to 1 status on the


System_OFF input will be enough to switch off the
plant permanently

Jumps
The use of jump commands is a way of structuring
programs. They enable networks to be skipped
which are only processed occasionally. Jumps can
be executed depending on or irrespective of a
particular binary current result. The jump destination
is always the start of the network, i. e. the beginning
of a program sequence. A jump label must be
specified in addition to the jump symbol. The same
jump label name must be entered in the destination
network next to the network number.

02/00 AWB 2700-1306 GB

84
Programming in LD

Unconditional jump
The unconditional jump JMP is executed irrespective
of the current result and is only useful in a program
section that is processed occasionally. An uncondi-
tional jump creates an independent network.
Network 0006 of the program shown contains the
02/00 AWB 2700-1306 GB

unconditional jump to the label Cylinder. The jump


destination is the network 0012, the jump label name
Cylinder is shown in the header of this network.

85
Graphical Programming
Languages

Conditional jump
JMPC: The conditional jump JMPC is executed if the
current result is 1. The current result 0 causes the
program directly behind the jump operation to be
processed.
JMPCN: The conditional jump JMPCN is executed if
the current result is 0. If the current result is 1, the
program is processed directly after the jump
operation. Network 0003 of the program shown on
page 84 executes a jump to network 0007 if the value
of the variable Aggregate in network 0003 is 0.

Returns
Returns enable the program execution in the current
POU to be interrupted and returned to the program
level from which the POU was invoked. Returns can
be executed dependent on or irrespective of the
current result.
Unconditional return
The unconditional return RET is executed irrespec-
tive of the current result. It is only useful in a program
section that is only processed occasionally and
which is not the last network. An unconditional return
starts a separate network.
Conditional return
RETC: The conditional return RETC is executed if the
current result is 1. If the current result is 0, the
program will be processed directly after the return
operation.
02/00 AWB 2700-1306 GB

86
Graphical Programming
Languages

Programming in FBD In FBD the individual language elements are


represented as graphical symbols.
In FBD several functions can be combined within a
network. A function block is represented in an
individual network.
The following graphical symbols are available for
displaying the program in FBD:
Graphical symbol to show an operation with two
variables. It is used for logical, arithmetic and
comparison functions. In the case of logical
sequences the values of input variables can be
negated before sequencing.This kind of input
variable is marked with a negation symbol such
as Input_2, for example.
Assignment of a current result (CR) or a constant to
a variable

Assignment of a negated current result or a negated


constant to a variable

Setting of a binary variable if CR = 1

Resetting of a binary variable if CR = 1

Unconditional jump to a label


Jump to a label if CR = 1

Jump to a label if CR = 0
02/00 AWB 2700-1306 GB

90
Programming in FBD

Unconditional return to the invoking program


Return to the invoking program if
CR = 1
Return to the invoking program if
CR = 0
Graphical symbol which indicates a function.
Functions have any number of input operands but
only one output operand.

Graphical symbol which indicates a function block.


Function blocks have any number of input and
output operands.

Variable names of the inputs and outputs can be


entered with a maximum length of 64 characters.
Long variable names, however, will appear in up to
3 lines above the input or output symbol.
02/00 AWB 2700-1306 GB

91
MS_TimeRising

MS_TimeRising
On-Delay Timer, Milliseconds

Prototype of function block

Meaning of operands
Set Start condition, rising edge

ReSet Reset condition

Hold Time interruption

PresetTime Time setpoint in milliseconds

OutputControl Control output

ElapsedTime Actual time value in milliseconds


06/99 AWB 2700-1306 GB

347
Function Blocks

Description

Time diagram

A rising edge on the Set input transfers the


PresetTime value as delay time T in milliseconds to
the timer and starts the time. The OutputControl
output switches to 1 after the delay time has elapsed
and keeps this status until the Set input is reset to 0
(1). The ElapsedTime output shows the current time
value in milliseconds. If the status 1 at the Set input
is shorter than T, the OutputControl output stays
at 0.
Elapsing of the delay time can be stopped by setting
the Hold input to 1. The held delay time then
continues to run when the Hold input is reset to 0.
The delay time is therefore lengthened by the
duration of the Hold signal, i. e. T+THOLD (2).
If the Hold input is 1 when the rising edge occurs on
the Set input, the start of the time delay will be
delayed further by the duration of the 1 signal on the
Hold input (4). If Set input is reset from 1 to 0 after the
06/99 AWB 2700-1306 GB

time has elapsed, and while the Hold input is set to


1, OutputControl output returns to 0 when the Hold
input is reset to 0 (3).

348
Function Blocks

MS_TimeFalling
Off-Delay Timer, Milliseconds

Prototype of function block

Meaning of operands
Set Start condition, rising edge

ReSet Reset condition

Hold Time interruption

PresetTime Time setpoint in milliseconds

OutputControl Control output

ElapsedTime Actual time value in milliseconds

06/99 AWB 2700-1306 GB

344
MS_TimeFalling

Description

Time diagram

A rising edge on the Set input transfers the


PresetTime value as delay time T in milliseconds to
the timer. The OutputControl output switches to 1.
The time is started when the Set input switches to 0.
The OutputControl output switches off, i. e. set to 0
(1), after the delay time T has elapsed). The
ElapsedTime output shows the current time value in
milliseconds. If the status 0 at the Set input is shorter
than T, the OutputControl output stays 1.
Elapsing of the delay time can be stopped by setting
the Hold input to 1. The held delay time then
continues to run when the Hold input is reset to 0.
The off-delay time is therefore lengthened by the
duration of the Hold signal, i. e. T+THALT (2).
If the Hold input is 1 when the rising edge occurs on
the Set input, the start of the PresetTime value will be
delayed further by the duration of the 1 signal on the
Hold input. The status 1 will also be delayed on the
06/99 AWB 2700-1306 GB

OutputControl output (4).

345
Function Blocks

S_TimeRising
On-Delay Timer, Seconds

Prototype of function block

Meaning of operands
Set Start condition, rising edge

ReSet Reset condition

Hold Time interruption

PresetTime Time setpoint in seconds

OutputControl Control output

ElapsedTime Actual time value in seconds

06/99 AWB 2700-1306 GB

424
S_TimeRising

Description

Time diagram

A rising edge on the Set input transfers the


PresetTime value as delay time T in seconds to the
timer and starts the time. The OutputControl output
switches to 1 after the delay time has elapsed and
keeps this status until the Set input is reset to 0 (1).
The ElapsedTime output shows the current time
value in seconds. If the status 1 at the Set input is
shorter than T, the OutputControl output stays at 0.
Elapsing of the delay time can be stopped by setting
the Hold input to 1. The held delay time then
continues to run when the Hold input is reset to 0.
The on-delay time is therefore lengthened by the
duration of the Hold signal, i. e. T+THOLD (2).
06/99 AWB 2700-1306 GB

425
S_TimeFalling

S_TimeFalling
Off-Delay Timer, Seconds

Prototype of function block

Meaning of operands
Set Start condition, rising edge

ReSet Reset condition

Hold Time interruption

PresetTime Time setpoint in seconds

OutputControl Control output

ElapsedTime Actual time value in seconds


06/99 AWB 2700-1306 GB

421
Function Blocks

Description

Time diagram

A rising edge on the Set input transfers the


PresetTime value as delay time T in seconds to the
timer and starts the time. The OutputControl output
is set to 1. The time is started when the Set input is
reset to 0. The OutputControl output is reset to 0
once the delay time has elapsed, i. e. it returns to “0”
(1). The ElapsedTime output shows the current time
value in seconds. If the status 0 at the Set input is
shorter than T, the OutputControl output stays at 1.
Elapsing of the delay time can be stopped by setting
the Hold input to 1. The held delay time then
continues to run when the Hold input is reset to 0.
The off-delay time is therefore lengthened by the
duration of the Hold signal, i. e. T+THALT (2).
If the Hold input is 1 when the rising edge occurs
on the Set input, the start of the time delay will be
delayed further by the duration of the 1 signal on the
Hold input. The OutputControl (4) output also has the
06/99 AWB 2700-1306 GB

delayed status 1.

422
TOF

TOF
Off delay

Prototype of the function block

Meaning of operands
IN Start condition

PT Predefined time value

Q Binary status of timer

ET Current time value

Description

Time diagram

The status 1 of the input operand IN is transferred to


the output operand Q without delay. The falling edge
of IN starts the time function of the timer TON for the
duration of the time value defined by the operand PT.
06/99 AWB 2700-1306 GB

The change of the status on the input IN to 0 during


the running time does not effect the operation. After
the time has elapsed, the status of the operand Q
changes to 0. If the PT value changes after the start,

535
TON

TON
On delay

Prototype of the function block

Meaning of operands
IN Start condition

PT Predefined time value

Q Binary status of the timer

ET Current time value

Description

Time diagram

The rising edge of the input operand IN starts the


time function of the timer TON for the duration of the
time value defined by the operand PT.
During this time the output operand Q has the
06/99 AWB 2700-1306 GB

status 0. After the time has elapsed, the status


changes to 1 and is kept until the operand IN
changes to 0.

537
TP

TP
Impulse

Prototype of the function block

Meaning of operands
IN Start condition

PT Predefined time value

Q Binary status of the timer

ET Current time value

Description

Time diagram

The rising edge of the input operand IN starts the


time function of the timer TP for the duration of the
time value defined by the operand PT.
During this time the output operand Q has the status
06/99 AWB 2700-1306 GB

1. The change of the status on the input IN does not


effect the operation.

539
TimeGenerator

TimeGenerator
Pulse generator

Prototype of the function block

Meaning of operands
Set Start condition, rising edge

Period Period in milliseconds

PulseOutput Pulse output

Time diagram

Description
A rising edge on the Set input transfers the Period
value as period duration T in milliseconds to the
timer. As long as the Set input is 1 the PulseOutput
will then supply an output pulse sequence for the
duration defined on the Period input at a pulse/pause
ratio of 1 : 1.
The period duration can be set at the Period input
06/99 AWB 2700-1306 GB

between 1 and 65535 ms.


If the Period value is changed during pulse
generation, the frequency is not adapted

519
TimePulse

TimePulse
Time pulse

Prototype of the function block

Meaning of operands
Set Start condition, rising edge

ReSet Reset condition

PresetTime Time setpoint in milliseconds

PulseOutput Control output

ElapsedTime Time actual value in milliseconds

Description

Time diagram

A rising edge on the Set input transfers the


06/99 AWB 2700-1306 GB

PresetTime value as a delay time T in milliseconds


to the time pulse generator and starts it. The
PulseOutput switches to 1 and keeps this status for
the duration of the time set.

521
TimerAlarm

PS 4-200 TimerAlarm
PS 4-300 Alarm function block Time
PS 416

TimerAlarm

BOOL EnableDisable
USINT Mode Error UINT
UINT Predivide CallUpNumber UINT
UINT SetpointValue
ANY_FUNCTION_BLOCK SubRoutine

Prototype of the function block

Meaning of operands
EnableDisable Enable and disable of alarm execution
(0 = Disable, 1 = Enable)
Mode Operating mode (1 = Timer, 2 = Pulse generator)
Predivide Predivider for the counter
SetPointValue Setpoint number pulses
SubRoutine Instance name of the function block called by the
alarm
Error Error messages
CallUpNumber Number of alarm-controlled function block
invocations

Description
The input EnableDisable controls the start of the
counter. The counter is started if this input is set to 1
or TRUE and the function block instance to be called,
Predivide and SetPointValue are accepted and
temporarily saved. The value of CallUpNumber is
reset. The function block is stopped and reset if the
06/99 AWB 2700-1306 GB

input status changes from 1 or TRUE to 0 or FALSE.


In the operating mode Mode = 1 the function block is
a Timer. The Predivide input then defines the time
base in ms (e. g. 1000 = 1 ms). The smallest pulse

523
Function Blocks

PS 4-300 _32Bit_Compare
PS 416 32-bit comparator

Prototype of the function block

Meaning of operands
InputValue1 First comparison value

InputValue2 Second comparison value

Greater Result: first value greater

Equal Result: both values equal

Less Result: first value less

Description
The _32Bit_Compare function block compares
InputValue1 to InputValue2 to see whether the value
of the number InputValue1 is greater, equal or less
compared with the value of the number InputValue2.
The result of the comparison is indicated by the three
output operands as follows:
Less Equal Greater

InputValue1< InputValue2 1 0 0

InputValue1 = InputValue2 0 1 0
06/99 AWB 2700-1306 GB

InputValue1 > InputValue2 0 0 1

216
Function Blocks

PS 4-300 _32BitCounter
PS 416 32-bit up/down counter

Prototype of the function block

Meaning of operands
Forward Up counter pulse, rising edge

Backward Down counter pulse, rising edge

Set Set condition, rising edge

ReSet Reset condition

InputValue Set value

Zero Signal: Counter status = 0

OutputValue Counter status

Description
The _32BitCounter function block is used for the
upward and downward counting of signals. Each
rising edge on the Forward input operand increments
the counter by one. A rising edge on the Backward
input operand decrements the counter by one. The
06/99 AWB 2700-1306 GB

current counter status is shown in the OutputValue


operand. A rising edge on the Set input transfers the
value of the InputValue to the counter.

220
_32BitCounter

The counter is cleared when the ReSet input is 1,


and other counting functions are disabled while the
ReSet is 1.
The counter range is between 0 and 4294967295.
The counter returns to 0 after it is incremented to
4294967295 and to 4294967295 after it is
decremented to 0. A carry is not formed in either
case.
If the counter is not instantiated as retentive, it is
assigned the value 0 when it is initialised. The zero
output operand will then be 1. A retentive instantia-
tion of a counter retains its original value.
Example: 32-bit up counter
PROGRAM parts_32

VAR RETAIN
Count_parts : _32BitCounter;
END_VAR

VAR
Light_barrier : AT %I0.0.0.0.6 : BOOL;
Quantity : UDINT;
Clear : AT %I0.0.0.0.7 : BOOL;
END_VAR

CAL Count_parts(Forward := Light_barrier,


ReSet := Clear)
LD Count_parts.OutputValue
ST Quantity

END_PROGRAM
06/99 AWB 2700-1306 GB

221
CTD

CTD
Down Counter

Prototype of the function block

Meaning of operands
CD Counter pulses, rising edge

Load Set condition

PV Initial value

Q Message: counter status ≤ 0

CV Counter status

Description
The function block CTD is used for the down
counting of impulses provided at the input operand
“CD”. The counter is set to “0” when initialised.
The value defined by the operand “PV” is loaded into
the counter as the initial value if the value of the
operand “Load” is “1”.
Each rising edge on the input “CD” is decremented,
i. e. reduced by one.
The output operand “CV” outputs the current
counter value. If the counter value is above the value
“0”, the output operand “Q” has the Boolean value
06/99 AWB 2700-1306 GB

“0”. The output “Q” is set to “1” when reaching or


dropping below the counter value “0”.

267
Function Blocks

CTU
Up Counter

Prototype of the function block

Meaning of operands
CU Counter pulses, rising edge

ReSet Reset condition

PV Counter limit

Q Signal: counter status PV

CV Counter status

Description
The function block CTU is used for the up counting
of impulses provided by the input operand “CU”.
The counter is set to “0” when initialised. Each rising
edge on input “CU” increments the counter, i. e.
increases its value by one.
The counter value can be cleared with the value “1”
at the operand “ReSet”.
The output operand “CV” outputs the current
counter value. If the counter value is below the limit
value “PV”, the output operand “Q” has the Boolean
value “0”. The output “Q” is set to “1” when reaching
06/99 AWB 2700-1306 GB

or exceeding the limit value.

268

You might also like