You are on page 1of 8

Creating a PLC Program

This is a simplified procedure for interface familiarisation purposes. For a PLC to function, you will
normally create a program off line (locally on your computer) then go online and transfer it into the PLC's
memory. Before you start this task, it is best to collect the following information:
Determine the PLC/CPU device type and PLC memory settings required to run your program.
Determine the type of communications connection to the PLC.
Determine the input/output requirements for your program, and organise I/O units into racks attached to your PLC.
PLC/Network Device Type Settings
Select the New option in the File menu.
A dialog box is displayed for selecting the PLC device type and connection settings. See the Change
PLC help for details.
The new project is created and the structure is shown in the project workspace .
Assigning I/O Points on the PLC's Racks and Units
Select the I/O Table of the new PLC on the project workspace.
When a PLC is first switched on it will create a real I/O table based on the units which are actually
plugged into its racks.
You may need to create an I/O Table model on your computer which matches the registered and real IO
table in the PLC.
When you work online you may then transfer your created I/O Table to the PLC's registered IO Table
(not all PLCs allow this). The PLC stores the registered I/O Table separately from the real I/O Table, and
will continually check that they match.
You can compare your local I/O Table on your computer with the registered I/O Table in the selected
PLC to check if there are differences.
When an I/O assignment has been made, addresses which are within the I/O table show special prefixes
on the ladder editor. An 'I' prefix shows that the address is mapped to an input unit. A 'Q' prefix shows
that the address is mapped to an output unit. The address' usage is also shown in the symbol tables .
Writing the Program
If you are using the mouse, ensure that you have the Diagram and Views tool bars displayed.
The PLC is designed to respond to sensing (on or off) inputs to which the PLC is connected. These inputs
are graphically represented in the ladder diagram as contacts, for example , allowing you place them in
a logical sequence to control the output (a coil) from the PLC or to trigger a function such as a timer.
Programs can be structured by using Function Blocks to handle repetitive tasks. Ladder or Structured
Text can be used within Function Blocks. The main programming language (and language used to call the
Function Blocks are Ladder or Structured Text).See ladder programming
The Ladder Section Window
A PLC executes programs of object code produced from a list of mnemonic instructions that are executed
in order. It is possible to view and edit the low-level mnemonic instructions with the mnemonic view. It is
possible to produce mnemonic instructions from a higher-level language - the ladder language provided
by CX-Programmer is an example. The CX-Programmer ladder view below shows an example ladder
program:

A ladder diagram is a graphical view of a PLC program and is concerned with power-flow. In the
diagram, power flows from the left (the left bus bar) to the right (the green right bus-bar). A ladder rung is
a logical connection between the left and right bus bars. These rungs are executed by the PLC in order
(i.e. from top to bottom).
The elements of a ladder rung that dictate power-flow are contacts, coils and instructions:
A contact ( ) behaves like an electrical contact and allows power to flow through it if it is closed. A contact can be
normally open or closed (a normally closed contact is shown as ). It is given an address within the PLC as an
operand. If the contents of the address (a binary bit of data) is set (high, or 1) then the logic of the contact is inverted
when a normally open contact becomes closed, and a normally closed contact becomes open.
A coil ( ) behaves similarly to a contact and is used to show output power. It can only be used on the right of a
rung. They can be normally open or closed (a normally closed coil is shown as ). Its operand is the PLC address
(a single binary bit of data) which will have power applied.
An instruction is used for all other types of data manipulation. They are mnemonic instructions, and each PLC has a
set that it can use. Each type of PLC has a particular instruction set, but most instructions are common. Instructions
may use zero or more operands, each of which may be a PLC address or a direct literal numeric value. As an
example, the END instruction is common to all PLCs, and does not use an operand and it must be present at the end
of every PLC program.
It is possible to link up these elements logically, using horizontal and vertical connectors, to give serial
and parallel logical constructs.
On the left of the diagram, there is a rung margin that identifies the position of the rung within the
program. It shows the rung number (which is just a unique number incremented from zero), and the step
number, which shows the offset from the beginning of the program in terms of number of instructions.
It is necessary to insert a rung into the editor before elements (contacts, coils, or instructions) can be
placed in it
In some cases, it is not possible to show parts of a mnemonic program as a ladder rung. In these cases, a
statement list box is used for the section, and other parts of the program appear as ladder. A block
program is a special part of a program that cannot be shown in ladder form. The block program contains
logical instructions that cannot be used in the normal ladder format.
When on-line to a PLC and monitoring, it is possible to see power-flow executing. The parts of the
diagram where power is present are shown with a thick line of the power-flow colour.
CX-Programmer can show the mnemonic instructions that are produced from the ladder constructs. The
mnemonics view displays these and updates the view whenever the ladder diagram is changed. It is also
write a program in mnemonic instructions and observe the changes in the ladder view.
Inserting Ladder Program Elements
Creating a PLC Program
Contact/Coil Dialogs
Instruction Dialogs
PLC Instructions
Mnemonics View
For details of how the Ladder Section Window has been affected by the introduction of the IEC61131-3
support, refer to the Enhancements to Support IEC61131-3 Function Blocks topic.
Entering a Contact/Coil (Ladder Section Window)
The same dialog is used for entering both contacts and coils. It can however be displayed in two forms,
either: simple dialog mode or detailed dialog mode. The default mode can be set in the Tools | Options
dialog.
Note: The operand of a contact or coil is an address representing a bit - a BOOL data type .
Simple dialog mode
An address or symbol name can be entered in this dialog. When Detail button is pressed, the dialog
changes to Detailed dialog mode.

If the Show with comment dialog option also ticked in the Option dialog, then a comment dialog will
appear after entering an address or symbol name.

Inputting Symbols
Input the symbol name and click the OK Button (or press the Enter Key). The New Symbol Dialog Box
will be displayed.

Enter the address and comment, and then click the OK Button.
The symbol can be registered in either the Global Symbol Table or Local Symbol Table. Select the check
box to register the symbol in the Global Symbol Table.
Detailed Dialog Mode
When the Detail button is pressed, the contact/coil dialog expands to include a number of additional
fields. Unchecking the Show in simple dialog mode box in the Option dialog, will cause the contact/coil
dialog to always be shown in the detailed mode.

Name or address
This list shows all defined symbols for the program and PLC.
It is possible to just type an address in the operand list. If the address has been mapped to a symbol, the
symbol is indicated in the symbol information area.
As a name is typed, CX-Programmer attempts to complete the symbol name from those in the list. The
details of the symbol are shown in the symbol information area of the dialog. A new symbol name can
also be typed, if it is required to create a new symbol at the time of entering the contact/coil information.
Also, symbols can be filtered by symbol names or comments inputted in the dialog.
Creating a Symbol: It is possible to create a symbol directly from within this dialog, by typing a new
name (conforming to the symbol naming convention ) or address:
When typing a new symbol name, an address and optional comment can also be entered. If the
contact/coil was previously entered using an address, the address will be filled in. The address may be left
blank, to specify that the address is to be automatically allocated . The symbol will be created as local , unless the
Global check box is set.
A global symbol may be linked to a CX-Server file .
If an address is entered instead of a name, only a comment may be entered in addition. This will create a
global, unnamed symbol. If a comment is not entered, a symbol will not be created.
Edit Symbol
Press this button in order to edit an existing symbol - when pressed, the editing fields in the 'symbol
information' part of the dialog are enabled. Note that it is only possible to edit a BOOL data-type , non
pre-defined symbol in this dialog.
The name , address and comment may be changed. Note that the scope of the symbol (local/global )
cannot be changed. A local symbol must have a name. Only global symbols can be linked to a CX-Server
file .
When editing a symbol, the symbol information fields work in the same way as the Insert symbol dialog.
Symbol Information
The name, address/value, data type and comment of the chosen symbol is shown. The scope of the
symbol is shown as either global or local .
For CJ2H-CPU -EIP, whether the symbol is a network symbol is also shown.
Differentiation
It may be required for the contact to be differentiated, i.e. be active for one scan only.
Select differentiate up, differentiate down or none.
Note: This only applies to contacts - it is not available for coils.
Immediate Refresh
It may be required for the operand in an I/O unit to be read/written immediately upon execution of the
contact/coil. Usually, the input or output is read/written to the input/output unit at the end of the execution
cycle.


Instruction Dialog (Ladder Section Window)
Instruction
Instruction dialog is available in the ladder view to enter details of a PLC instruction . The dialog can be
displayed in two forms, either: simple dialog mode or detailed dialog mode. The default mode can be
set in the Tools | Options dialog.
Note: Some instructions are not available for use when programming in ladder language - they must be
used directly in a mnemonic list .
Simple dialog mode
Instruction and operand(s) can be entered in this dialog. When Detail button is pressed, the dialog
changes to Detailed dialog mode.

If the Show with comment dialog option is also ticked in the Option dialog, then a comment dialog (for
each operands) will appear after entering an instruction and operand(s).

Detailed dialog mode
When the Detail button is pressed, the Instruction dialog expands to include a number of additional fields.
Unchecking the Show in simple dialog mode box in the Options dialog, will cause the Instruction dialog
to always be shown in the detailed mode.

There are three ways to select an instruction:
1. Type its name into the Instruction edit box. CX-Programmer attempts to complete
the function name as it is typed, and displays details of the required operands below
the instruction edit box.
2. Type the instruction number into the Instruction edit box. Use the correct number
of digits for the PLC (some PLCs use 2 digits, the others use 3 digits). When an
instruction number has been recognised, CX-Programmer fills in the instruction
name and displays details of the required operands below the instruction edit box.
3. Select an instruction from a list by selecting the Find Instruction button. When the
Find Instruction dialog appears, select the instruction category in the left side of the
displayed dialog then the required instruction in the category from the right side of
the dialog.
Note that it is possible to get full help on a particular instruction by typing its mnemonic into the
Instruction field, and pressing Instruction Help. If the instruction exists on more than one family of
PLCs (i.e. C-series, CV-series, or CS/CJ-series), a choice of family will first be given.
Note than certain instructions have dependencies between operands, so that the value of one operand will
determine the valid range of another. For these instructions, it is possible to check whether the operands
are valid by pressing the Check button.
Operands
The number of operands available for selection will depend on the instruction selected.
Instruction and operands should be divided with a space when entering in Simple dialog mode. To enter
operand in detailed dialog mode, use the keyboard up/down cursor, or Tab keys to select the operand
number to edit .
The valid range for the selected operand is indicated below the operand box. This updates as information
is typed. Initially (when the information for the operand is empty), it shows the address ranges which are
valid. When beginning to type the operand details, the information is updated to show the valid range for
the address type chosen.
It is possible to use a symbol for the operand. The symbol name may be typed directly or the symbol can
be selected using the find symbol dialog. To browse for a symbol, press F3 when entering the operand, or
press the browse button to the right of the edit box.
When a symbol name or comment is input in the operand box and the [Filter symbol] button is pressed,
the [Filter Symbol] dialog is shown and the target symbol can be selected from the dialog to input it in the
[Operand] box.
See operand types for an explanation of how to enter a correct operand.
Symbol Information
Whenever CX-Programmer finds a symbol associated with the typed operand, symbol information is
displayed in this box. The name, address/value and comment are shown, together with the data type of the
symbol and its scope (global or local).
Expansion Table
You can use this table to define the expansion instructions .
PLC Instruction Sets
Every PLC has a set of special instructions which can be used for programming. Different types of PLC
have different abilities and this is reflected in the instructions available. Some instructions are common
across all PLCs.
PLCs can be split into 3 families - the instruction sets for each are described below:
C-Series PLC Instructions
CV-Series PLC Instructions
CS/CJ-Series PLC Instructions
Mnemonic Editing
Select the Mnemonics option from the View menu (or press Alt+M keys) to display the Mnemonics
representation of the ladder diagram (note that a section must be selected for this menu option to be
available). Use Alt+D to return to diagram view.
The mnemonic editor behaves in a similar way to a text editor, except that you can be in 'block' or
'editing' modes.
When starting the mnemonic editor, it opens in block mode and whole line is shown selected at the cursor
position. In this mode, it is possible to manipulate the lines of mnemonic using the copy / cut / paste and
delete options. To select more than one line at a time, select the line at the top of the desired range of
lines, hold down the shift key and click/move the cursor to the end of the range.
It is possible to paste a mnemonic program into CX-Programmer from a text-editor - the text will be
pasted in the position of the cursor.
To enter 'edit' mode, press return. In this mode, a line of text is highlighted in the text highlight colour.
The text may now be edited in a normal way. To add another line, press return. To exit 'edit' mode, press
Esc.
The mnemonic instructions available for each PLC type are described in the PLC Instruction Set
references.
Note: To synchronize the cursor in the mnemonic editor and the ladder editor, Synchronize ladder and mnemonic
cursors option must be checked - see Diagram Options .
Note
The Mnemonic Editor is not available in a CS/CJ-H and CJ1M PLC's project with Function Blocks being
used.

You might also like