Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
1K views43 pages

OMRON Function Block Introduction Guide R121 E1 01

The document discusses using Function Blocks from OMRON's FB Library in CX-Programmer. It describes what Function Blocks are, provides examples of using the library, and how to customize Function Blocks. It also covers using the ST programming language to create Function Blocks.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views43 pages

OMRON Function Block Introduction Guide R121 E1 01

The document discusses using Function Blocks from OMRON's FB Library in CX-Programmer. It describes what Function Blocks are, provides examples of using the library, and how to customize Function Blocks. It also covers using the ST programming language to create Function Blocks.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

The CD-ROM of CX-Programmer has User's Manual of the PDF file.

Please read the 'Notice' and the 'Precautions' in the User's Manual before using CX-Programmer. The Function Block Introduction Guide' describes the basic operation procedure to use Function Block of CX-Programmer. Refer to the Help or the User's Manual of the PDF file for detailed descriptions. * You need Acrobat Reader 4.0 or grater versions in your PC to display the PDF file.

Contents
Chapter 1 OMRON FB Library
1. What is a Function Block? 2. An Example of a Function Block 3. Overview of the OMRON FB Library 3-1. Benefits of the OMRON FB Library 3-2-1. Example of using the OMRON FB Library - 1 3-2-2. Example of using the OMRON FB Library - 2 3-3. Content of the OMRON FB Library 3-3-1. OMRON FB Part Files 3-3-2. Library reference 3-4. File Catalog and Where to Access the OMRON FB Library 3-4-1. Catalog of OMRON FB Library files 3-4-2. CX-Programmer installation CD 3-4-3. Accessing OMRON FB Library files from Web server 1-1 1-2 1-3 1-3 1-4 1-5 1-6 1-6 1-6 1-7 1-7 1-7 1-7

Chapter 2 How to use the OMRON FB Library


1. Explanation of the target program 1-1. Application Specifications 1-2. Specifications of the OMRON FB Part file 1-3. Input program 2. Opening a new project and setting the Device Type 3. Main Window functions 4. Import the OMRON FB Part file 5. Program Creation 5-1. Enter a Normally Open Contact 5-2. Entering an Instance 5-3. Entering Parameters 6. Program Error Check (Compile) 7. Going Online 8. Monitoring - 1 9. Monitoring - 2 Change Parameter Current Value 10. Online Editing 2-1 2-1 2-1 2-2 2-3 2-4 2-5 2-6 2-6 2-7 2-7 2-9 2-10 2-11 2-12 2-13

Chapter 3 Customize the OMRON FB Part file


1. Explanation of target program 1-1. Changing File Specifications 1-2. Changing the contents of the OMRON FB Part file 2. Copy the OMRON FB Part file 3. Add a variable to the Function Block 4. Changing the Function Block Ladder 4-1. Entering a Contact 5. Supplemental Information 5-1. How to delete unused Function Block definitions 5-2. Memory allocation for Function Blocks 3-1 3-1 3-1 3-2 3-3 3-4 3-4 3-5 3-5 3-5

Chapter 4 How to use the ST (Structured Text) language


1. What is the ST Language? 2. Explanation of the target program 3. Create a Function Block using ST 4. Entering Variables in to Function Blocks 5. Entry of ST program 6. Entering the FB to the Ladder Program and error checking 7. Program Transfer 8. Monitoring the Function Block execution Reference: Example of an ST program using IF-THEN-ELSE-END_IF Useful Functions 4-1 4-1 4-2 4-3 4-4 4-5 4-6 4-7 4-8 Appendix

OMRON FB Library
1. 1. What What is is a a Function Function Block? Block?
Function Blocks are predefined programs (or functions) contained within a single program element that may be used in the ladder diagram. A contact element is required to start the function, but inputs and outputs are editable through parameters used in the ladder arrangement. The functions can be reused as the same element (same memory) or occur as a new element with its own memory assigned. Partial Ladder program for machine A Defining Inputs and Outputs Input Input

Process (algorithm) Control Device n

Output Output

Control Device 1
A1 B1 X1 An An Bn Bn

An

Bn

Xn Xn Xn TIM n #0100

TIM 1 #0100 T1 Y1 Z1 Tn

Yn Yn Yn Zn Zn Zn

Produce template
Partial Ladder program for machine A Function Block definition

Control Device 1

P_On
A1 B1

Device Control
Device Control

EN A B

ENO X Y Z

X1 Y1 Z1

EN Allocate to Ladder program


Function Block Instance (invocation)

ENO X Y Z

A B

Control Device 2 parameters

Sets input / output

P_On
A2 B2

Device Control

EN A B

ENO X Y Z

X2 Y2 Z2

Function Block definition ...This contains the defined logic (algorithm) and I/O interface. The memory addresses are not allocated in the Function Block Definition Function Block instance(invocation) ...This is the instruction that will call the function block instance when used by the ladder program, using the memory allocated to the instance.

OMRON FB Library
2. 2. An An Example Example of of a a Function Function Block Block
The following figures describe an example of a function block for a time limit circuit, to be used in the ladder. It is possible to edit the set point of the TIM instruction to reallocate the set time for turning off the output in the ladder rung. Using the function block as shown below, it is possible to make the time limit of the circuit arbitrary by only changing one specific parameter.

Ladder diagram
000.00 TIM0000 TIM 0000 #0020 001.00 001.00 000.00

By enabling the input parameter to be editable, it is possible to allow an arbitrary time limit circuit.
PULSE EN #0020 Time ENO 001.00

Timing chart
EN 000.00 001.00 2.0 sec T_FB TIM T_FB Time Q Q

OMRON FB Library

3. 3. Overview Overview of of the the OMRON OMRON FB FB Library Library


The OMRON FB Library is a collection of predefined Function Block files provided by Omron. These files are intended to be used as an aid to simplify programs, containing standard functionality for programming PLCs and Omron FA component functions.

3-1. Benefits of the OMRON FB Library


The OMRON FB Library is a collection of function block examples that aim to improve the connectivity of the units for PLCs and FA components made by Omron. Here is a list of the benefits to be gained from using the OMRON FB Library: (1)No need to create ladder diagrams using basic functions of the PLC units and FA components More time can be spent on bespoke programs for the external devices, rather than creating basic ladder diagrams, as these are already available. (2)Easy to use A functioning program is achieved by loading the function block file to perform the target functionality, then by inputting an instance (function block call instruction: invocation) to the ladder diagram program and setting addresses (parameters) for the inputs and outputs. (3)Testing of program operation is unnecessary Omron has tested the Function Block library. Debugging the programs for operating the unit and FA components for the PLCs is unnecessary for the user. (4)Easy to understand The function block has a clearly displayed name for its body and instances. A fixed name can be applied to the process. The instance (function block call instruction: invocation) has input and output parameters. As the temporary relay and processing data is not displayed, the values of the inputs and outputs are more visible. Furthermore, as the modification of the parameters is localised, fine control during debugging etc. is easier. Finally, as the internal processing of the function block is not displayed when the instance is used in the ladder diagram, the ladder diagram program looks simpler to the end user. (5)Extendibility in the future Omron will not change the interface between the ladder diagram and the function blocks. Units will operate by replacing the function block to the corresponding FB for the new unit in the event of PLC and the FA component upgrades, for higher performance or enhancements, in the future.

A fixed name can be named to the processes. It is not necessary to create the basic communications program.

INPUT/OUTPUT data is clear. Parameters are easy to understand and edit.

OMRON FB Library

3-2-1. Example of using the OMRON FB Library - 1


Controlling the predefined components made by Omron can be easily achieved from the PLC ladder diagram.

- Ability to configure low-cost communications (RS-232C/485)

CS/C J Series PLC

FB

Access by Function Block

Example: Communication between Temperature controller and PLC

Serial communications (Compoway/F protocol)

Temperature controller Smart sensor Omron Components

Vision sensor

OMRON FB Library

3-2-2. Example of using the OMRON FB Library - 2


High performance communications can be made by DeviceNet level.
- Ability to communicate between PLC and DeviceNet slaves easily.

CS/CJ series PLC

FB

Access by Function block

Example: data exchange between PLC and the slave devices

Communicate between PLC and the devices

DeviceNet

Temperature controller
Generic slaves such as IO terminal PLC Inverter

Wireless

OMRON FB Library
3-3. Content of the OMRON FB Library
The OMRON FB Library consist of the following:

3-3-1. OMRON FB Part Files


The OMRON FB Part file is prepared using the ladder diagram function block, for defining each function of the PLC unit and the FA component. The files contain a program written in ladder diagram and have the extension .CXF. The file name of the OMRON FB Part file begins with _ (under score). When the OMRON FB Library is installed onto a personal computer, the OMRON FB Part files are classified in the folder appropriate to each PLC Unit and FA component in the Omron Installation directory.

3-3-2. Library reference


The library reference describes the operation specifications of the OMRON FB Part file, and the specifications of the input and the output parameters for each. The file format for this is PDF. When the OMRON FB Library is used, the user should select the OMRON FB Part file, set the input / output parameters, and test the program operations referring to the library reference.

OMRON FB Library
3-4. File Catalog and Where to Access the OMRON FB Library 3-4-1. Catalog of OMRON FB Library files
Number of OMRON FB Part files (at the time of July 04) approx. 80

Type FA components

Target components Temperature controller, Smart sensor, ID sensor, Vision sensor, 2 dimensions bar code reader CPU unit, Memory card, Special CPU IO unit (Ethernet, Controller Link, DeviceNet unit, Temperature control unit) Position control unit Inverter Servo motor driver

PLC

approx. 95

Motion control components

approx. 30

3-4-2. CX-Programmer installation CD


CX-Programmer Ver.5.0 installation CD contains the OMRON FB Library files. The user can select to install the OMRON FB Library during the installation of CX-Programmer Ver.5.0.

CX-Programmer Ver.5.0 Install CD

3-4-3. Accessing OMRON FB Library files from Web server


The latest version OMRON FB Library files will be provided by Omron on the Web server. New files will be added to support new or enhanced PLC units and FA components. The download service of the OMRON FB Library is provided as a menu of Omron Web in each country.
Web server
The internet

The internet

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

1. 1. Explanation Explanation of of the the target target program program


This chapter describes how to use OMRON FB Library using the OMRON FB Part file Make ON Time/OFF Time Clock Pulse in BCD.

1-1. Application Specifications


The target application specifications are as follows :- Pulse is generated after PLC mode is changed torun or monitor mode. - Output the pulse to address 1.00. - On time of generated pulse is set at D100. - Off time of generated pulse is 2 seconds.

1-2. Specifications of the OMRON FB Part file


The OMRON FB Part file Make ON Time/OFF Time Clock Pulse in BCD has the following specifications:-

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

1-3. Input program


Create the following ladder program:-

[Reference] If created as a straightforward ladder diagram, the program would be as below:-

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

2. 2. Opening Opening a a new new project project and and setting setting the the Device Device Type Type
Click the toolbar button [New] in CX-Programmer.

Click

Click the left mouse button.

!To use Function Blocks, select the following PLCs: CS1G-H, CS1H-H, CJ1G-H, CJ1H-H, CJ1M

Click the left mouse button

Click the left mouse button to select CPU type.

Click [OK] to decide the selected CPU type.

3. 3. Main Main Window Window functions functions


The main window functionality is explained here.
Title bar Menus

Tool bar

Project Project Tree Tree Section Section

Function Function Block Block Definition Definition

Status bar Project Project Workspace Workspace Ladder LadderWindow Window

Name

Contents / Function

Title Bar Menus Toolbars Section Project Workspace Project Tree Ladder Window Function Block Definition

Shows the file name of saved data created in CX-Programmer. Enables you to select menu items. Enables you to select functions by clicking icons. Select [View] -> [Toolbars], display toolbars. Dragging toolbars enables you to change the display positions. Enables you to divide a program into several blocks. Each can be created and displayed separately. Controls programs and data. Enables you to copy element data by executing Drag and Drop between different projects or from within a project. A screen for creating and editing a ladder program. Shows Function Block definition. By selecting the icons, you can copy or delete the selected Function Block definition. is shown if the file is a OMRON FB Part file. - In the case of a User-defined Function Block, is shown if Ladder, is shown if ST. Shows information such as a PLC name, online/offline state, location of the active cell.

Status Bar

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

4. 4. Import Import the the OMRON OMRON FB FB Part Part file file
Select Function Block definition icon from the project tree using the mouse cursor, right click. Select Insert Function Block, then select a Library file using mouse to navigate.

Click mouse right button -> Insert Function Block -> Library File

Double click mouse left button. -> [OmronLib] -> [Programmable Controller] -> [CPU] Select each of the above in series.

Double click mouse left button

Select the necessary OMRON FB Part file in the Select Function Block Library dialog.

! The default path of the OMRON FB Library is


C:/Program Files/Omron/Lib/FBL.

Left Click _CPU007_MakeClockPulse_BCD.cxf Left Click the [Open] button

Function Block definition _CPU007_MakeClockPulse_BCD is registered as part of the project file.

Function Function Block Block Definition Definition

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

5. Program Creation
Confirm cursor position is at the upper left of Ladder Window to start programming.

5-1. Enter a Normally Open Contact


C

Press the [C] key on the keyboard to open the [New Contact] dialog. Use the dropdownbox to select the P_On symbol.

P_On

ENT Deleting instructions z Move the cursor to the instruction and then press the DEL key or z Move the cursor to the right cell of the instruction and press the BS key. P_On is a system defined symbol. Its state is always ON. 0 of the upper digit of an address is omitted when shown. [.] (period) is displayed between a channel number and a relay number.

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

5-2. Entering an Instance


F

Press the [F] key on the keyboard to open the [New Function Block Invocation] dialog.

Enter text to create an FB instance name. [WorkInputTimingGenerator]

Applies Applies a a name name for for the the specific specific process process in in the the diagram. diagram.

ENT

Shows FB instance (invocation) WorkInputTimingGenerator.

5-3. Entering Parameters

or

ENT

Move the cursor to the left of input parameter.

Enter the address. [d100]

ENT

Choose an address for the input parameter OnTime.

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

Enter the remaining parameters in the same way.

Or

ENT

#10
Please add the following prefix for entering constants as parameters: # (Hexadecimal/BCD) Or & (Decimal)

ENT

1.00

ENT
[Generated Pulse]

ENT

Offline Operation
Explanation Explanation of of target target Program Program Opening Opening a a new new project project Import Import FB FB Library Library Creating Creating a a program program Program Program Check Check

6. Program Error Check (Compile)


Before program transfer, check for errors using the program compile.

Click

Errors Errorsand andaddresses addressesare are displayed displayedin inthe theOutput OutputWindow. Window.

Double-click Double-clickon ondisplayed displayederrors, errors, and LadderDiagram Diagram cursor cursor andthe theLadder will willmove moveto tothe thecorresponding corresponding error errorlocation, location,displaying displayingthe theerror error rung rungin inred. red.

Modify Modifythe theerror. error.

Output Window automatically opens at program check. The cursor moves to an error location by pressing J or F4 key. z Output Window closes by pressing the ESC key.
z z

Online Operation Online Online to to transfer transfer Monitoring Monitoring Online Online Edit Edit

7. Going Online
CX-Programmer provides three methods of connecting, depending on usage.
Normal Normal online. online. Enables Enables you you to to go go online online with with a a PLC PLC of of the the device device type type and and method method specified specified when when opening opening a a project. project. Auto Auto online. online. Automatically Automaticallyrecognizes recognizes the the connected connected PLC PLC and and enables enables you you to to go go online online with with a a PLC PLC with with one one button. button. -> -> Uploads Uploads all all data, data, such such as as programs, programs, from from the the PLC. PLC. Online Online with with Simulator. Simulator. Enables Enables you you to to go go online online with with CX-Simulator CX-Simulator with with one one button button (CX-Simulator (CX-Simulator must must be be installed.) installed.)

Online/debug Online/debug functions functions when when working working online online with with CX-Simulator CX-Simulator are are explained explained in in this this guide guide (Install (Install CX-Simulator CX-Simulatorseparately). separately).

Click

Click [OK]

Program transfer starts.

Click [OK]

The The CX-Simulator CX-Simulator Console Console box boxis is shown. shown. The The operating operating mode mode of of the the active active PLC PLCis is shown. shown.

The The background background color color of of the the Ladder LadderWindow Window changes changes to to gray. gray.

Scan Scan time time is is displayed displayed (except (except during during Program Program Mode). Mode).

Online Operation Online Online to to transfer transfer Monitoring Monitoring Online Online Edit Edit

8. Monitoring - 1
Change Change the the PLC PLC (Simulator) (Simulator) to to Monitor Monitormode. mode.

The on/off status of contacts and coils can be monitored.

Click

Click [Yes].

If your program has a large volume of data, the scroll speed of the screen may become slow when monitoring. To resolve this, click the icon below to cancel monitoring, scroll to the address you want to monitor, then restart the monitor mode.

toggles PLC monitoring on/off

The The monitored monitored area area is is displayed displayed in in a a specified specified color. color.

The The current current values values of of parameters parameters are are shown. shown.

Online Operation Online Online to to transfer transfer Monitoring Monitoring Online Online Edit Edit

9. Monitoring - 2 Change Parameter Current Value


Change the current value of contact/coils or word data in the Ladder Window.

Move the cursor to the input parameter D100.

Click mouse right button and select the menu item [Set/Reset(S)] ->[Setting Value(V)] Or Double click mouse left button.

Change Change the the current current value value of of Input Input parameter. parameter. Click Click [Set] [Set] Please add the following prefix for entering constants as parameters: # (Hexadecimal/BCD) Or & (Decimal)

Or

ENT

Online Operation Online Online to to transfer transfer Monitoring Monitoring Online Online Edit Edit

10. Online Editing

Move the cursor to the rung requiring modification. You can also select multiple rungs by using the Drag & Drop facility with the mouse.

Select [Program] ->[Online Edit] -> [Begin] Shortcut: [Ctrl]+[E]

Move the cursor to a instruction you want to modify. Double click the left mouse button.

Double click

Edit the address to the required bit number (4.11 in the example)

Select [Program] ->[Online Edit] -> [Send Change] Shortcut: [Ctrl]+{Shift]+[E]

End

Explanation Explanation of of target target Program Program

Copy Copy of of FB FB part part

Change Change of of FB FB Definition Definition

1. Explanation of target program


This chapter describes how to customize the OMRON FB Library using the OMRON FB Part file Make ON Time/OFF Time Clock Pulse in BCD.

1-1. Changing File Specifications


The OMRON FB Part file Make ON Time/OFF Time Clock Pulse in BCD is designed to repeatedly turn off the ENO for the specified OffTime (unit: 100 msec) and on for the specified OnTime (unit: 100 msec). In this example, the OMRON FB Part file will be changed to output an invert signal by adding the output parameter INV_ENO.
EN ON OFF OnTime(*100ms) ENO ON OFF OffTime(*100ms)
INV_ENO

ON OFF

1-2. Changing the contents of the OMRON FB Part file


To satisfy the requirement described above, the following changes must be made to OMRON FB Part file Make ON Time/OFF Time Clock Pulse in BCD 1. Add an output parameter INV_ENO. 2. Add ladder program to output the ENO for inverting the signal.

OMRON OMRON cannot cannot guarantee guarantee the the operation operation of of a a customized customized OMRON OMRON FB FB parts. parts. Please Please be be sure sure to to check check the the process process of of your your FB FB part part sufficiently sufficiently before before customization customization and and confirm confirm the the operation operation of of each each FB FB parts parts thoroughly thoroughly after after that. that.

Caution Caution

Explanation Explanation of of target target Program Program

Copy Copy of of FB FB part part

Change Change of of FB FB Definition Definition

2. Copy the OMRON FB Part file


Import the Make ON Time/OFF Time Clock Pulse in BCD Function Block Part file as explained in Chapter 1 (FB definition name: _CPU007_MakeClockPulse_BCD)

Select the OMRON FB Part icon then right click the mouse. -> Copy

Select Function Block Definition icon and right click the mouse. -> Paste The OMRON FB Part file is pasted.

Change the FB definition name.

Select pasted Function Block icon and click mouse right button. -> Rename [MakeClockPulse_BCD_INV]

Note: Note: The The user user cant cant create create Function Function Block Block Definitions Definitions With With name name starting starting _ _ (underscore). (underscore). Please Please use use names names not not starting starting with with _. _.

Enable editing of the internal FB Program code.


Select pasted Function Block icon and right click the mouse button. -> Property Or

ALT

ENT
Tick Tick the the check check box box using using the the left left mouse mouse click. click.

Explanation Explanation of of target target Program Program

Copy Copy of of FB FB part part

Change Change of of FB FB Definition Definition

3. Add a variable to the Function Block


Open the Function Block Ladder Editor.

Variable Variable Table Table

Opens Opens the the Function Function Block Ladder Block Ladder Editor. Editor.

Select the Function Block icon using the mouse cursor and double click the left mouse button.

The The original original OMRON OMRON FB FB Part Part file file is is also also able able to to display display its its ladder ladder program, program, but but cannot cannot be be edited. edited. Ladder Ladder Editor Editor Variable table

Select Output tab in Variable Table using the mouse cursor And click the left mouse button.

Click the left mouse button and select Insert Variable(I).

Enter Enter a a new new variable variable name. name.

Select Select BOOL BOOL for for bit bit data. data.

Confirm the entered variable is correct.

Explanation Explanation of of target target Program Program

Copy Copy of of FB FB part part

Change Change of of FB FB Definition Definition

4. Changing the Function Block Ladder


Add the required ladder diagram on Function Block Ladder edit field. Move the cursor to the left column of the next rung.

4-1. Entering a Contact


/

ENO

ENT

INV_ENO

ENT

5. Supplemental Information 5-1. How to delete unused Function Block definitions


When you delete unused Function Block definitions, it is not enough just to delete the Function Block invocations (instructions). This is because the Function Block instance definitions are registered in the global symbol table. At this situation, when the compile (program check) is done, then the unused function block instances will be shown on the output window. You can identify the unused function block instance definitions and delete them easily. The Function Block definitions and Function Block instances are a part of user program in the CPU unit even if they are not called, so it is recommended to delete unused Function Block definitions and instances before transferring the program to the CPU unit.

Execute Compile

F7

key

Result of Compilation

Del Double Double click click mouse mouse left left button button

key

Click mouse left button Function Function Block Block definition definition will will be be deleted. deleted.

5-2. Memory allocation for Function Blocks


It is necessary to allocate required memory for each function block instances to execute Function Blocks. CX-Programmer allocates the memory automatically based on the following setting dialog information. ( PLC menu -> Function Block Memory -> Function Block Memory Allocation) There are 4 types of areas, Not retain, Retain, Timers, and Counters. Please change the settings if requires. - Notice when changing the settings If you change the Not retain or Retain area, please consider the allocated memory areas for the special IO unit and CPU SIO unit. - Special memory area for the Function Blocks CS1/CJ1-H/CJ1M CPUs (unit version: 3.0 or higher) have a special memory area which is extended hold (H) relay area. The address of the area is from H512 to H1535. CX-Programmer sets the area as a default. Please note that the area cannot be used for the operands of ladder instructions.

Offline Operation
Explanation Explanation of of target target Program Program Create Create new new FB FB Definition Definition Entering Entering Symbols Symbols Creating Creating ST ST Program Program Creating Creating Ladder Ladder Program Program and and check check

1. What is the ST Language?


The ST (Structured Text) language is a high-level language code for industrial controls (mainly PLCs) defined by the IEC 61131-3 standard. It has many control statements, including IF-THEN-ELSE-END_IF, FOR / WHILE loop, and many mathematical functions such as SIN / LOG. it is suitable for mathematical processing. The ST language supported by CXProgrammer is in conformance with IEC 61131-3 standard. The arithmetic functions in CXProgrammer Ver.5.0 are as follows: sine (SIN), cosine (COS), tangent (TAN), arc-sine (ASIN), arccosine (ACOS), arc-tangent (ATAN), square root (SQRT), absolute value (ABS), logarithm (LOG), natural-logarithm (LN), natural-exponential (EXP), exponentiation (EXPT) Reference: The IEC 61131 standard is an international standard for programming Programmable Logic Controllers (PLC), defined by the International Electro-technical Commission (IEC). The standard consists of 7 parts, with part 3 defining the programming of PLCs.

2. Explanation of the target program


This example describes how to create an ST program in a Function Block to calculate the average value of a measured thickness.

The The data data type type should should be be set set to to REAL REAL to to store store the the data. data. REAL REAL type type allows allows values values with with 32 32 bits bits of of length, length, see see range range below:below:38 -38, -3.402823x10 -3.402823x1038 ~ ~ -1.175494x10 -1.175494x10-38,,, 0, 0, -38 38 +1.175494x10 +1.175494x10-38 ~ ~ +3.402823x10 +3.402823x1038

x x(REAL (REAL type), type), y y(REAL (REAL type), type), z z(REAL (REAL type) type) score Output score(REAL (REAL type) type) Output symbol symbol ST score := := ((x x+ +y y+ +z z)) // 3.0; 3.0; ST Program Program definition definition score
Input Input symbols symbols Substitute Substitute a a value value to to a a symbol symbol is is expressed expressed by by := := . .
Enter Enter ;; (semicolon) (semicolon) to to complete complete the the code. code.

FB FB definition definition name name AverageCalc_3Value AverageCalc_3Value

Offline Operation
Explanation Explanation of of target target Program Program Create Create new new FB FB Definition Definition Entering Entering Symbols Symbols Creating Creating ST ST Program Program Creating Creating Ladder Ladder Program Program and and check check

3. Create a Function Block using ST


Create a Function Block using Structured Text.

Select the Function Block icon using a mouse cursor, and click the right mouse button. -> Insert Function Block(I) ->Structured Text(S)

A New Function Block definition is created.

Change Change the the Function Function Block Block definition definition name name

Select the Function Block definition icon using the mouse cursor and right click the mouse button. Select Paste. -> Rename Enter [AverageCalc_3value] Open Open Function Function Block Block ST ST Editor Editor Select Function Block definition Icon by mouse cursor and double click the left mouse button.

Note: Note: The The user user cant cant create create Function Function Block Block Definitions Definitions with with names names starting starting _ _ (underscore). (underscore). Please Please use use names names not not starting starting with with _. _.

Variable Variable Table Table

ST ST Edit Edit Field Field

Offline Operation
Explanation Explanation of of target target Program Program Create Create new new FB FB Definition Definition Entering Entering Symbols Symbols Creating Creating ST ST Program Program Creating Creating Ladder Ladder Program Program and and check check

4. Entering Variables in to Function Blocks


Select Variable Table.

Select the Input tab using the mouse cursor.

Select Insert from the Pop-up menu.

Enter Enter a a variable variable name name

Enter data for the following. Name Data type Comment

Select Select REAL REAL

Enter Enter and and applicable applicable comment comment

Enter Enter input input symbol symbol x, x, output output symbols symbols y,z y,z by by repeating repeating the the process process above. above.

Input Input Variables Variables

Output Output Variables Variables

Reference: Reference: The The copy copy and and paste paste operation operation is is available available in in FB FB Header. Header. Reference: Reference: The The order order of of the the variables variables in in the the FB FB table table becomes becomes the the order order of of parameters parameters on on FB FB instance instance (invocation) (invocation) in in the the normal normal ladder ladder view. view. To To change change the the order, order, it it is is possible possible to to drag drag & & drop drop variables variables within within the the table. table.

Output Variables Input Variables FB instance (invocation)

Offline Operation
Explanation Explanation of of target target Program Program Create Create new new FB FB Definition Definition Entering Entering Symbols Symbols Creating Creating ST ST Program Program Creating Creating Ladder Ladder Program Program and and check check

5. Entry of ST program
Select the ST Editor text field in the Function Block ST Editor window.

Enter Enter text text into into the the field: field: score score := := (x (x + +y y+ + z) z) // 3.0;. 3.0;.

When the input expression is a real type calculation, please enter the constant value with decimal point and zero for single decimal places, e.g. 3.0.

Reference: Reference: User User may may type type Comments Comments in in the the ST ST program. program. Enter (* and *) both ends of comment Enter (* and *) both ends of comment strings, strings, see see below. below. This This is is useful useful for for recording recording change change history, history, process process expressions, expressions, etc. etc.

Offline Operation
Explanation Explanation of of target target Program Program Create Create new new FB FB Definition Definition Entering Entering Symbols Symbols Creating Creating ST ST Program Program Creating Creating Ladder Ladder Program Program and and check check

6. Entering the FB to the Ladder Program and error checking


Enter the following FB into the ladder program. Instance name: ThicknessAvarage Input parameters: D0, D2, D4 Output parameter: D6 It It is is able able to to jump jump the the referred referred function function block block definition definition by by entering entering [Shift]+[F] [Shift]+[F] key key when when the the cursor cursor is is in in the the function function block block instance. instance.

Refer Refer page page 2-7 2-7 for for entering entering FB FB instances. instances. Entering Entering ST ST FB FB instances instances is is the the same same as as entering entering FB FB Ladder Ladder instances. instances.

Perform a programs check before transferring the program.

Refer Refer page page 2-9 2-9 for for program program checking. checking. The functionality is the The functionality is the same same as as for for Function Function Block Block Ladder Ladder instances. instances.

It is possible to change or add variables in the Function Block after inputting FB instance into the ladder editor. If modified, the Ladder editor changes the color of the left bus-bar of the rung containing the changed Function Block. When this occurs, please select the instance in the Ladder Editor using the mouse cursor, and select Update Function Block Instance (U) from the pop-up menu.

Online Operation
Transfer Transfer Program Program Monitoring Monitoring

7. Program Transfer
Go online to the PLC with CX-Simulator and transfer the program.

Change Change the the PLC PLC (Simulator) (Simulator) to to Monitor Monitor mode. mode. Click

Refer Refer to to page page 2-10 2-10 for for steps steps to to go go online online and and transfer transfer the the program. program. The on/off status of contacts and coils can be monitored.

Click [Yes]

Confirm that the PLC is Monitor mode.

Online Operation
Transfer Transfer Program Program Monitoring Monitoring

8. Monitoring the Function Block execution


Monitors the present value of parameters in the FB instance using the Watch Window.

Display the Watch Window.

Alt

Open the Edit dialog.

ENT

Click Browse button using the mouse left button.

Select Select REAL(32bit REAL(32bit floating floating point) point)

Click the button using the left mouse button, then select the following: [Symbols of type] [Name or address]

Select Select ThicknessAvarage.x ThicknessAvarage.x

Click [OK] button using the left mouse button.

When monitoring internal variables at debug phase, always use the Watch Window. It is not possible to monitor inside a Function Block Definition.

Reference: Example of an ST program using IF-THEN-ELSE-END_IF


The following ST program checks the average value calculated by the example of page 4-7 against a range (upper limit or lower limit).

FB Definition: OutputOfDecisionResult Input symbols: score(REAL type), setover(REAL type), setunder(REAL type) Output symbols: OK (BOOL type), overNG(BOOL type), underNG(BOOL type)

ST program: IF score > setover THEN underNG := FALSE; OK := FALSE; overNG := TRUE; (* If score > setover, *) (* Turn off underNG *) (* Turn off OK *) (* Turn on overNG *)

ELSIF score < setunder THEN (* if score =< setover and score < setunder then *) overNG := FALSE; (* Turn on overNG *) OK := FALSE; (* Turn off OK *) underNG := TRUE; (* Turn on underNG *) ELSE underNG := FALSE; overNG := FALSE; OK := TRUE; END_IF; (* if setover > score > setunder then*) (* Turn off underNG *) (* Turn off overNG *) (* Turn off OK *) (* end of IF section*)

Example of an FB instance (the instance name is ThicknessDecision)

Useful Functions
It is possible to automatically display a list of symbol names or IO comments when entering the operands of instructions. When entering the operand for contact or output (or special instructions), enter a string, and the dropdown list is automatically updated to display in symbol names or IO Comments using the defined string. Selecting the item from the list defines the operand information.. This is an efficient way of entering registered symbol information into the ladder. Example: Enter text Temperature to the edit field in the operand dialog.

Click or push [F4] key; all symbols / address having IO comment containing the text temperature are listed. See below:-

For instance, select temp_alarm01, W1.00, Temperature error of upper case of MachineA, from the list. The operand is set to be using symbol alarm01.

You might also like