How To Create Function Blocks In OMRON CX-Programmer By using Structure Text
A user defined function block performs a specific task or set of tasks within a defined program. you can define your Function blocks by structured programming languages, ladder programming, Function block diagram etc. in this article we discuss only how to create Function Blocks In OMRON CX-Programmer By using Structure Text. a function block have one or more input and output or both. these input and output can be variables, data structures, or even other function blocks. you can make a Function blocks to perform complex arithmetical operations, file input/output operations, communication control, reduced control block etc. another benefit of function block you can reuse your function block to another plc.
What is a Function Block in Omron?
Function Blocks are predefined programs or user defined functions. in predefined program like Timer, counter instruction you can only change input and output. if the program have multiple uses in your logic for examples if you have ten motor so you can defined a user logic or reusable code for all of your motor these logic you can use anywhere. The functions can be reused as the same element (same memory) or occur as a new element with its own memory assigned. Function block easy to understand, easy to use.
Create Your Omron Function Block Library
so open your CX-Programmer and create a new project, enter device name, select device type and network type and press ok to continue
Select programming languages for Function Block in Omron ?
now in project explorer right click on Function Block and than select insert Function block select structured text or ladder diagram here i am selecting structured text.
cx programmer function block property
next set the function block property when you insert a new function block it is necessary to set some property like name of function block. when you insert a new function block a dialog will open on your screen or you can set property latter by right click on function block and then click to property. in function block general property tab enter the name of function block, author and revision of function block.
set protection of function block
when you make your function block add protection for unauthorized use. so in property of function block select protection tab and click on 'set' protection than select any one of the protection type and insert password and confirm password now your function block is protected.
set memory of function block
you can set memory of function block in memory tab of function property. you can assigned retain memory, non retain memory, timer and counter memory.
insert variables for function block
next part is to declare variables for your program these variables are as follows:
external variables: These are pre-defined variables or the variables that enable user-defined global symbols to be used.
Internals:These variables accessible only within the Function Block. Outside the function block you cannot access these variables.
input:These are variables that store data passed into the Function Block.
Outputs: these variables return the result or data.
IN OUT these variables stored data as well as return result.
define a program for function block
after all property setting now we make a program here i am making a simple push button program so i am using two input variables first is start second is stop and one output is motor start. logic as shown below you can make your own logic here is only a simple logic only for demonstration. and then compile your program.
insert function block in rung
now your block is ready for use. For Inserting Function Block select a rung where you want to add your function block than use any of the of following ways
select insert option and than select Function Block Invocation.
use shortcut key 'F' for insert a function block.
from toolbar select new function block call.
set Instances for your function block
when you insert your function block a dialog will open called 'New Function Block Invocation' here you define Instances name for your function block or you can use Existing Instances. when you create new Instances, new Function Block Instance will be created in the Global Symbol Table and the memory required will automatically be allocated by the Function Block/SFC Memory Allocation mechanism. The data type of each Function Block Variable will be displayed below the name (inside the Function Block). The EN, ENO and Function Block Parameters can now be connected as appropriate.
Insert Function Block Parameters
paramaeter like input, output defined by Function Block Parameter shortcut key 'P'. and EN/ENO same as below image.
test and save function block
test your program by simulation after successfully simulation test right click on function block and save function block as file select location of function block and enter the name of function block. now you can use this function block to another program.
reuse function block program
in project explorer select function block and than right click on it and select inser function block than select from file browse file location and enter into the project now set instance name, set input output parameter than test and download to plc.