Programs for microprocessor-based systems have to be loaded into them
in machine code, this being a sequence of binary code numbers to
represent the program instructions. However, assembly languagebased on
the use of mnemonics can be used, e.g. LD is used to indicate the
operation required to load the data that follows the LD, and a computer
program called an assembler is used to translate the mnemonics into
machine code. Programming can be made even easier by the use of the
so-called high level languages, e.g. C, BASIC, PASCAL, FORTRAN,
COBOL. These use pre-packaged functions, represented by simple words
or symbols descriptive of the function concerned. For example, with C
language the symbol & is used for the logic AND operation. However, the
use of these methods to write programs requires some skill in
programming and PLCs are intended to be used by engineers without any
great knowledge of programming. As a consequence, ladder
programmingwas developed. This is a means of writing programs which
can then be converted into machine code by some software for use by the
PLC microprocessor.
This method of writing programs became adopted by most PLC
manufacturers, however each tended to have developed their own versions
and so an international standard has been adopted for ladder programming
and indeed all the methods used for programming PLCs. The standard,
published in 1993, is IEC 1131-3 (International Electrotechnical
Commission). The IEC 1131-3 programming languages are ladder
diagrams (LAD), instruction list (IL), sequential function charts (SFC),
structured text (ST), and function block diagrams (FBD).
This chapter is an introduction to the programming of a PLC using
ladder diagrams and functional block diagrams, with discussion of the
other techniques in the next chapter. Here we are concerned with the basic
techniques involved in developing ladder and function block programs to
represent basic switching operations, involving the logic functions of
AND, OR, Exclusive OR, NAND and NOR, and latching. Later chapters
continue with further ladder programming involving other elements.
LaDDER DIAGRAM :
As an introduction to ladder diagrams, consider the simple wiring diagram
for an electrical circuit in Figure 5.1(a). The diagram shows the circuit for
switching on or off an electric motor. We can redraw this diagram in a
different way, using two vertical lines to represent the input power rails
and stringing the rest of the circuit between them. Figure 5.1(b) shows the
result. Both circuits have the switch in series with the motor and supplied
with electrical power when the switch is closed. The circuit shown in
Figure 5.1(b) is termed a ladder diagram
Figure 5.1 Ways of drawing the same electrical circuit
With such a diagram the power supply for the circuits is always shown
as two vertical lines with the rest of the circuit as horizontal lines. The
power lines, or rails as they are often termed, are like the vertical sides of
a ladder with the horizontal circuit lines like the rungs of the ladder. The
horizontal rungs show only the control portion of the circuit, in the case of
Figure 5.1 it is just the switch in series with the motor. Circuit diagrams
often show the relative physical location of the circuit components and
how they are actually wired. With ladder diagrams no attempt is made to
show the actual physical locations and the emphasis is on clearly showing
how the control is exercised.
Figure 5.2 shows an example of a ladder diagram for a circuit that is
used to start and stop a motor using push buttons. In the normal state,
push button 1 is open and push button 2 closed. When button 1 is pressed,
the motor circuit is completed and the motor starts. Also, the holding
contacts wired in parallel with the motor close and remain closed as long
as the motor is running. Thus when the push button 1 is released, the
holding contacts maintain the circuit and hence the power to the motor.
To stop the motor, button 2 is pressed. This disconnects the power to the
motor and the holding contacts open. Thus when push button 2 is
released, there is still no power to the motor. Thus we have a motor which
is started by pressing button 1 and stopped by pressing button 2.
5.1.1 PLC ladder programming
A very commonly used method of programming PLCs is based on the use
of ladder diagrams. Writing a program is then equivalent to drawing a
switching circuit. The ladder diagram consists of two vertical lines
representing the power rails. Circuits are connected as horizontal lines,
i.e. the rungs of the ladder, between these two verticals.
In drawing a ladder diagram, certain conventions are adopted:
1 The vertical lines of the diagram represent the power rails between
which circuits are connected. The power flow is taken to be from the
left-hand vertical across a rung.
2 Each rung on the ladder defines one operation in the control process.
3 A ladder diagram is read from left to right and from top to bottom,
Figure 5.3 showing the scanning motion employed by the PLC. The
top rung is read from left to right. Then the second rung down is read
from left to right and so on. When the PLC is in its run mode, it goes
through the entire ladder program to the end, the end rung of the
program being clearly denoted, and then promptly resumes at the start
(see Section 4.4). This procedure of going through all the rungs of the
program is termed a cycle. The end rung might be indicated by a
block with the word END or RET for return, since the program
promptly returns to its beginning.
4 Each rung must start with an input or inputs and must end with at
least one output. The term input is used for a control action, such as
closing the contacts of a switch, used as an input to the PLC. The
term output is used for a device connected to the output of a PLC,
e.g. a motor.
5 Electrical devices are shown in their normal condition. Thus a switch
which is normally open until some object closes it, is shown as open
on the ladder diagram. A switch that is normally closed is shown
closed.
6 A particular device can appear in more than one rung of a ladder. For
example, we might have a relay which switches on one or more
devices. The same letters and/or numbers are used to label the device
in each situation.
7 The inputs and outputs are all identified by their addresses, the
notation used depending on the PLC manufacturer. This is the
address of the input or output in the memory of the PLC
Starting with the input, we have the normally open symbol | | for the
input contacts. There are no other input devices and the line terminates
with the output, denoted by the symbol ( ). When the switch is closed, i.e.
there is an input, the output of the motor is activated. Only while there is
an input to the contacts is there an output. If there had been a normally
closed switch |/| with the output (Figure 5.5(b)), then there would have
been an output until that switch was opened. Only while there is no input
to the contacts is there an output.
In drawing ladder diagrams the names of the associated variable or
addresses of each element are appended to its symbol. Thus Figure 5.6
shows how the ladder diagram of Figure 5.5(a) would appear using (a)
Mitsubishi, (b) Siemens, (c) Allen-Bradley, (d) Telemecanique notations
for the addresses. Thus Figure 5.6(a) indicates that this rung of the ladder
program has an input from address X400 and an output to address Y430.
When wiring up the inputs and outputs to the PLC, the relevant ones must
be connected to the input and output terminals with these addresses.
in machine code, this being a sequence of binary code numbers to
represent the program instructions. However, assembly languagebased on
the use of mnemonics can be used, e.g. LD is used to indicate the
operation required to load the data that follows the LD, and a computer
program called an assembler is used to translate the mnemonics into
machine code. Programming can be made even easier by the use of the
so-called high level languages, e.g. C, BASIC, PASCAL, FORTRAN,
COBOL. These use pre-packaged functions, represented by simple words
or symbols descriptive of the function concerned. For example, with C
language the symbol & is used for the logic AND operation. However, the
use of these methods to write programs requires some skill in
programming and PLCs are intended to be used by engineers without any
great knowledge of programming. As a consequence, ladder
programmingwas developed. This is a means of writing programs which
can then be converted into machine code by some software for use by the
PLC microprocessor.
This method of writing programs became adopted by most PLC
manufacturers, however each tended to have developed their own versions
and so an international standard has been adopted for ladder programming
and indeed all the methods used for programming PLCs. The standard,
published in 1993, is IEC 1131-3 (International Electrotechnical
Commission). The IEC 1131-3 programming languages are ladder
diagrams (LAD), instruction list (IL), sequential function charts (SFC),
structured text (ST), and function block diagrams (FBD).
This chapter is an introduction to the programming of a PLC using
ladder diagrams and functional block diagrams, with discussion of the
other techniques in the next chapter. Here we are concerned with the basic
techniques involved in developing ladder and function block programs to
represent basic switching operations, involving the logic functions of
AND, OR, Exclusive OR, NAND and NOR, and latching. Later chapters
continue with further ladder programming involving other elements.
LaDDER DIAGRAM :
As an introduction to ladder diagrams, consider the simple wiring diagram
for an electrical circuit in Figure 5.1(a). The diagram shows the circuit for
switching on or off an electric motor. We can redraw this diagram in a
different way, using two vertical lines to represent the input power rails
and stringing the rest of the circuit between them. Figure 5.1(b) shows the
result. Both circuits have the switch in series with the motor and supplied
with electrical power when the switch is closed. The circuit shown in
Figure 5.1(b) is termed a ladder diagram
Figure 5.1 Ways of drawing the same electrical circuit
With such a diagram the power supply for the circuits is always shown
as two vertical lines with the rest of the circuit as horizontal lines. The
power lines, or rails as they are often termed, are like the vertical sides of
a ladder with the horizontal circuit lines like the rungs of the ladder. The
horizontal rungs show only the control portion of the circuit, in the case of
Figure 5.1 it is just the switch in series with the motor. Circuit diagrams
often show the relative physical location of the circuit components and
how they are actually wired. With ladder diagrams no attempt is made to
show the actual physical locations and the emphasis is on clearly showing
how the control is exercised.
Figure 5.2 shows an example of a ladder diagram for a circuit that is
used to start and stop a motor using push buttons. In the normal state,
push button 1 is open and push button 2 closed. When button 1 is pressed,
the motor circuit is completed and the motor starts. Also, the holding
contacts wired in parallel with the motor close and remain closed as long
as the motor is running. Thus when the push button 1 is released, the
holding contacts maintain the circuit and hence the power to the motor.
To stop the motor, button 2 is pressed. This disconnects the power to the
motor and the holding contacts open. Thus when push button 2 is
released, there is still no power to the motor. Thus we have a motor which
is started by pressing button 1 and stopped by pressing button 2.
5.1.1 PLC ladder programming
A very commonly used method of programming PLCs is based on the use
of ladder diagrams. Writing a program is then equivalent to drawing a
switching circuit. The ladder diagram consists of two vertical lines
representing the power rails. Circuits are connected as horizontal lines,
i.e. the rungs of the ladder, between these two verticals.
In drawing a ladder diagram, certain conventions are adopted:
1 The vertical lines of the diagram represent the power rails between
which circuits are connected. The power flow is taken to be from the
left-hand vertical across a rung.
2 Each rung on the ladder defines one operation in the control process.
3 A ladder diagram is read from left to right and from top to bottom,
Figure 5.3 showing the scanning motion employed by the PLC. The
top rung is read from left to right. Then the second rung down is read
from left to right and so on. When the PLC is in its run mode, it goes
through the entire ladder program to the end, the end rung of the
program being clearly denoted, and then promptly resumes at the start
(see Section 4.4). This procedure of going through all the rungs of the
program is termed a cycle. The end rung might be indicated by a
block with the word END or RET for return, since the program
promptly returns to its beginning.
4 Each rung must start with an input or inputs and must end with at
least one output. The term input is used for a control action, such as
closing the contacts of a switch, used as an input to the PLC. The
term output is used for a device connected to the output of a PLC,
e.g. a motor.
5 Electrical devices are shown in their normal condition. Thus a switch
which is normally open until some object closes it, is shown as open
on the ladder diagram. A switch that is normally closed is shown
closed.
6 A particular device can appear in more than one rung of a ladder. For
example, we might have a relay which switches on one or more
devices. The same letters and/or numbers are used to label the device
in each situation.
7 The inputs and outputs are all identified by their addresses, the
notation used depending on the PLC manufacturer. This is the
address of the input or output in the memory of the PLC
Starting with the input, we have the normally open symbol | | for the
input contacts. There are no other input devices and the line terminates
with the output, denoted by the symbol ( ). When the switch is closed, i.e.
there is an input, the output of the motor is activated. Only while there is
an input to the contacts is there an output. If there had been a normally
closed switch |/| with the output (Figure 5.5(b)), then there would have
been an output until that switch was opened. Only while there is no input
to the contacts is there an output.
In drawing ladder diagrams the names of the associated variable or
addresses of each element are appended to its symbol. Thus Figure 5.6
shows how the ladder diagram of Figure 5.5(a) would appear using (a)
Mitsubishi, (b) Siemens, (c) Allen-Bradley, (d) Telemecanique notations
for the addresses. Thus Figure 5.6(a) indicates that this rung of the ladder
program has an input from address X400 and an output to address Y430.
When wiring up the inputs and outputs to the PLC, the relevant ones must
be connected to the input and output terminals with these addresses.