Language reference

Project architecture

Common objects

SFC language

FC language

FBD language

LD language

ST language

IL language

Standard operators, function blocks and functions


 Project architecture

An ISaGRAF project is divided into several programming units called programs. The programs of the project are linked together in a tree-like architecture. Programs can be described using any of SFC, FC (Flow Chart), FBD, LD, ST or IL graphic or literal languages.

Programs

Cyclic and sequential operations

Child SFC and FC programs

Functions and sub-programs

Function blocks

Description language

Execution rules


Programs

A program is a logical programming unit, that describes operations between variables of the process. Programs describe either sequential or cyclic operations. Cyclic programs are executed at each target system cycle. The execution of sequential programs follows the dynamic rules of either the SFC language or the FC language.

Programs are linked together in a hierarchy tree. Programs placed on the top of the hierarchy are activated by the system. Sub-programs (lower level of the hierarchy) are activated by their father. A program can be described with any of the available graphic or literal following languages:

Sequential Function Chart (SFC) for high level programming

Flow Chart (FC) for high level programming

Function Block Diagram (FBD) for cyclic complex operations

Ladder Diagram (LD) for boolean operations only

Structured Text (ST) for any cyclic operations

Instruction List (IL) for low level operations

The same program cannot mix several languages, except LD and FBD can be combined in one diagram.


Cyclic and sequential operations

The hierarchy of programs is divided into four main sections or groups:

Begin	programs executed at the beginning of each target cycle

Sequential	programs following SFC or FC dynamic rules

End	programs executed at the end of each target cycle

Functions	set of non-dedicated sub-programs

Programs of the 'Begin' or 'End' sections describe cyclic operations, and are not time dependent. Programs of the 'Sequential' section describe sequential operations, where the time variable explicitly synchronizes basic operations. Main programs of the 'Begin' section are systematically executed at the beginning of each run time cycle. Main programs of the 'End' section are systematically executed at the end of each run time cycle. Main programs of the 'Sequential' section are executed according to either the SFC or the FC dynamic rules.

Programs of the "Functions" section are sub-programs that can be called by any other program in the project. A program of the "Function" section can call another program of this section.

Main and child programs of the sequential section must be described with SFC or FC language. Programs of cyclic sections (begin and end) cannot be described with SFC or FC language. Any program of any section may own one or more sub-programs. Any program of the sequential section may own one or more SFC or FC child programs (according to its own programming language). Sub-programs cannot be described with SFC or FC language.

Programs of the Begin section are typically used to describe preliminary operations on input devices to build high level filtered variables. Such variables are frequently used by the programs of the Sequential section. Programs of the End section are typically used to describe security operations on the variables operated on by the Sequential section, before sending values to output devices.


Child SFC and FC programs

Any SFC program of the sequential section may control other SFC programs. Such low level programs are called child SFC programs. A child SFC program is a parallel program that can be started, killed, frozen or restarted by its parent program. The parent program and child program must both be described with the SFC language. A child SFC program may have local variables and defined words.

When a parent program starts a child SFC program, it puts an SFC token (activates) into each initial step of the child program. This command is described with the GSTART statement. When a parent program kills a child SFC program, it clears all the tokens existing in the steps of the child. Such a command is described with the GKILL statement.

When a parent program freezes a child SFC program, it suspends its execution. Such a command is described with the GFREEZE statement. The suspended child program can then be restarted using the GRST statement.

Any FC programl of the sequential section may control other FC sub-programs. An FC father program is blocked (waits) during execution of an FC sub-program. It is not possible that simultaneous operations are done in father FC program and one of its FC sub-programs.


Functions and sub-programs

A sub-program or a function execution is driven by its parent program. The execution of the parent program is suspended until the sub-program or the function ends :

main	sub-programs

Any program of any section may have one or more sub-programs. A sub-program is owned by only one father program. A sub-program may have local variables and defines. Any language but SFC or FC can be used to describe a sub-program. Programs of the "Functions" section are sub-programs that can be called by any other program in the project. Unlike other sub-programs, they are not dedicated to one father program. A program of the "Function" section can call another program of this section. A function can be located in the Library.

Warning: The ISaGRAF system does not support recursivity during function calls. A run time error will occur if a program of the "Functions" section is called by itself or by one of its called sub-program.

Warning: A function or sub-program does not "store" the local value of its local variables. A function or sub-program is not instanciated and so can not call function blocks.

The interface of a sub-program must be explicitly defined, with a type and a unique name for each of its calling or return parameter. In order to support the ST language convention, the return parameter must have the same name as the sub-program.

The following table shows how to set the value of the return parameter in the body of a sub-program, in the different languages:

ST:	assign the return parameter using its name

(the same name as the sub-program):

   subprog_name := <expression>;

IL:	the value of the current result (IL register)

at the end of the sequence is stored in the return parameter:

   LD      10

   ADD   20   (* return parameter value = 30 *)

FBD:	set the return parameter using its name:

subprog_name

LD:	use a coil symbol with the name of the return parameter:

subprog_name


Function blocks

Function blocks can use the languages: LD, FBD, ST or IL. Function blocks are instanciated. It means local variables of a function block are copied for each instance. When calling a block in a program, you actually call the instance of the block: the same code is called but the data used are the one which have been allocated for the instance. Values of the variables of the instance are stored from one cycle to the other.

Warnings:

- A function block written with one of the IEC languages can not call other function blocks: the instanciation mechanism only manage the local variables of the block itself. Here is the list of standard function blocks that you cannot use inside an IEC function block:

SR, RS, R_Trig, F_Trig, SEMA, CTU, CTD, CTUD, TON, TOF, TP, CMP, StackInt, AVERAGE, HYSTER, LIM_ALRM, INTEGRAL, DERIVATE, BLINK, SIG_GEN

- For the same reason, you can not use Positive or Negative contact or coils, or Set and Reset coils.

- TSTART and TSTOP functions to start and stop timers cannot be used in a function block for 3.0x targets. It works since the 3.20 target.

- When you need loop in your function block, you must use local variable before doing the loop. See the example below:

This will not work:	This is OK:


Description language

A program can be described with any of the following graphic or literal languages:

Sequential Function Chart (SFC) for high level operations

Flow Chart (FC) for high level operations

Function Block Diagram (FBD) for cyclic complex operations

Ladder Diagram (LD) for boolean operations only

Structured Text (ST) for any cyclic operations

Instruction List (IL) for low level operations

The same program cannot mix several languages. The language used to describe a program is chosen when the program is created, and cannot be changed later on. The exception is that it is possible to combine FBD and LD in a single program.


Execution rules

ISaGRAF is a synchronous system. All the operations are triggered by a clock. The basic duration of the clock is called the cycle timing:

Basic operations processed during a target cycle are:

This system makes it possible to:

- guarantee that an input variable keeps the same value within a cycle,

- guarantee that an output device is not updated more than once in a cycle,

- work safely on the same global variable from different programs,

- estimate and control the response time of the complete application.


 Common objects

These are main features and common objects of the ISaGRAF programming data base. Such objects can be used in any program written with any of the SFC, FC, FBD, LD, ST or IL languages.

Basic types

Constant expressions

Variables

Comments

Defined words


Basic types

Any constant, expression or variable used in a program (written in any language) must be characterized by a type. Type coherence must be followed in graphic operations and literal statements. These are the available basic types for programming objects:

BOOLEAN:	logic (true or false) value

ANALOG:	integer or real (floating) continuous value

TIMER:	time value

MESSAGE:	character string

Note: Timers contain values less than one day and cannot be used to store dates.


Constant expressions

Constant expressions are relative to one type. The same notation cannot be used to represent constant expressions of different types.

Boolean constant expressions

Integer analog constant expressions

Real analog constant expressions

Timer constant expressions

Message string constant expressions


Boolean constant expressions

There are only two boolean constant expressions:

TRUE	is equivalent to the integer value 1

FALSE	is equivalent to the integer value 0

"True" and "False" keywords are case insensitive.


Integer analog constant expressions

Integer constant expressions represent signed long integer (32 bit) values:

from -2147483647 to +2147483647

Integer analog constants may be expressed with one of the following bases. Integer constants must begin with a prefix that identifies the bases used:

Base	Prefix	Example

DECIMAL	(none)	-908

HEXADECIMAL	"16#"	16#1A2B3C4D

OCTAL	"8#"	8#1756402

BINARY	"2#"	2#1101_0001_0101_1101

The underscore character ('_') may be used to separate groups of digits. It has no particular significance, and is used to increase constant expression readability.


Real analog constant expressions

Real analog constant expressions can be written with either decimal or scientific representation. The decimal point ('.') separates the integer and decimal parts. The decimal point must be used to differentiate a real constant expression from an integer one. The scientific representation uses the 'E' or 'F' letter to separate the mantissa part and the exponent. Exponent part of a real scientific expression must be a signed integer value from -37 to +37. Below are examples of real analog constant expressions:

3.14159	-1.0E+12

+1.0	1.0F-15

-789.56	+1.0E-37

The expression "123" does not represent a real constant expression. Its correct real representation is "123.0".


Timer constant expressions

Timer constant expressions represent time values from 0 second to 23h59m59s999ms. The lowest allowed unit is a millisecond. Standard time units used in constant expressions are:

Hour	The "h" letter must follow the number of hours

Minute	The "m" letter must follow the number of minutes

Second	The "s" letter must follow the number of seconds

Millisecond	The "ms" letters must follow the number of milliseconds

The time constant expression must begin with "T#" or "TIME#" prefix. Prefixes and unit letters are case insensitive. Some units may not appear. These are examples of timer constant expressions:

T#1H450MS	1 hour, 450 milliseconds

time#1H3M	1 hour, 3 minutes

The expression "0" does not represent a time value, but an analog constant.


Message string constant expressions

String or message constant expressions represent character strings. Characters must be preceded by a quote and followed by an apostrophe. For example:

'THIS IS A MESSAGE'

Warning: The apostrophe ''' character cannot be used within a string constant expression. A string constant expression must be expressed on one line of the program source code. Its length cannot exceed 255 characters, including spaces.

Empty string constant expression is represented by two apostrophes, with no space or tab character between them:

''   (* this is an empty string *)

The special character dollar ('$'), followed by other special characters, can be used in a string constant expression to represent a non-printable character:

Sequence	Meaning	ASCII (hexa)	Example

$$	'$' character	16#24	'I paid $$5 for this'

$'	apostrophe	16#27	'Enter $'Y$' for YES'

$L	line feed	16#0a	'next $L line'

$R	carriage return	16#0d	'   llo $R He'

$N	new line	16#0d0a	'This is a line$N'

$P	new page	16#0c	'lastline $P first line'

$T	tabulation	16#09	'name$Tsize$Tdate'

$hh   (*)	any character	16#hh	'ABCD = $41$42$43$44'

(*) "hh" is the hexadecimal value of the ASCII code for the expressed character.


Variables

Variables can be LOCAL to one program, or GLOBAL. Local variables can be used by one program only. Global variables can be used in any program of the project.

Reserved keywords

Directly represented variables

Boolean variables

Analog variables

Timer variables

Message string variables

Variable names must conform to the following rules:

- name cannot exceed 16 characters

- first character must be a letter

- following characters can be letters, digits or the underscore character


Reserved keywords

A list of the reserved keywords is shown below. Such identifiers cannot be used to name a program, a variable or a "C" function or function block:

A	ANA, ABS, ACOS, ADD, ANA, AND, AND_MASK, ANDN, ARRAY, ASIN, AT, ATAN,

B	BCD_TO_BOOL, BCD_TO_INT, BCD_TO_REAL, BCD_TO_STRING, BCD_TO_TIME, BOO, BOOL, BOOL_TO_BCD, BOOL_TO_INT, BOOL_TO_REAL, BOOL_TO_STRING, BOOL_TO_TIME, BY, BYTE,

C	CAL, CALC, CALCN, CALN, CALNC, CASE, CONCAT, CONSTANT, COS,

D	DATE, DATE_AND_TIME, DELETE, DINT, DIV, DO, DT, DWORD,

E	ELSE, ELSIF, EN, END_CASE, END_FOR, END_FUNCTION, END_IF, END_PROGRAM, END_REPEAT, END_RESSOURCE, END_STRUCT, END_TYPE, END_VAR, END_WHILE, ENO, EQ, EXIT, EXP, EXPT,

F	FALSE, FEDGE, FIND, FOR, FUNCTION,

G	GE, GFREEZE, GKILL, GRST, GSTART, GSTATUS, GT,

I	IF, INSERT, INT, INT_TO_BCD, INT_TO_BOOL, INT_TO_REAL, INT_TO_STRING, INT_TO_TIME,

J	JMP, JMPC, JMPCN, JMPN, JMPNC,

L	LD, LDN, LE, LEFT, LEN, LIMIT, LINT, LN, LOG, LREAL, LT, LWORD,

M	MAX, MID, MIN, MOD, MOVE, MSG, MUL, MUX,

N	NE, NOT,

O	OF, ON, OPERATE, OR, OR_MASK, ORN,

P	PROGRAM

R	R, REDGE, READ_ONLY, READ_WRITE, REAL, REAL_TO_BCD, REAL_TO_BOOL, REAL_TO_INT, REAL_TO_STRING, REAL_TO_TIME, REDGE, REPEAT, REPLACE, RESSOURCE, RET, RETAIN, RETC, RETCN, RETN, RETNC, RETURN, RIGHT, ROL, ROR,

S	S, SEL, SHL, SHR, SIN, SINT, SQRT, ST, STN, STRING, STRING_TO_BCD, STRING_TO_BOOL, STRING_TO_INT, STRING_TO_REAL, STRING_TO_TIME, STRUCT, SUB, SYS_ERR_READ, SYS_ERR_TEST, SYS_INITALL, SYS_INITANA, SYS_INITBOO, SYS_INITTMR, SYS_RESTALL, SYS_RESTANA, SYS_RESTBOO, SYS_RESTTMR, SYS_SAVALL, SYS_SAVANA, SYS_SAVBOO, SYS_SAVTMR, SYS_TALLOWED, SYS_TCURRENT, SYS_TMAXIMUM, SYS_TOVERFLOW, SYS_TRESET, SYS_TWRITE, SYSTEM,

T	TAN, TASK, THEN, TIME, TIME_OF_DAY, TIME_TO_BCD, TIME_TO_BOOL, TIME_TO_INT, TIME_TO_REAL, TIME_TO_STRING, TMR, TO, TOD, TRUE, TSTART, TSTOP, TYPE,

U	UDINT, UINT, ULINT, UNTIL, USINT,

V	VAR, VAR_ACCESS, VAR_EXTERNAL, VAR_GLOBAL, VAR_IN_OUT, VAR_INPUT, ,VAR_OUTPUT,

W	WHILE, WITH, WORD,

X 	XOR, XOR_MASK, XORN

All keywords beginning with an underscore ('_') character are internal keywords and must not be used in textual instructions.


Directly represented variables

ISaGRAF enables the use of directly represented variables in the source of the programs to represent a free channel. Free channels are the ones which are not linked to a declared I/O variable. The identifier of a directly represented variable always begins with "%" character.

Below are the naming conventions of a directly represented variable for a channel of a single board. "s" is the slot number of the board. "c" is the number of the channel.

%IXs.c	free channel of a boolean input board

%IDs.c	free channel of an integer input board

%ISs.c	free channel of a message input board

%QXs.c	free channel of a boolean output board

%QDs.c	free channel of an integer output board

%QSs.c	free channel of a message output board

Below are the naming conventions of a directly represented variable for a channel of a complex equipment. "s" is the slot number of the equipment. "b" is the index of the single board within the complex equipment. "c" is the number of the channel.

%IXs.b.c	free channel of a boolean input board

%IDs.b.c	free channel of an integer input board

%ISs.b.c	free channel of a message input board

%QXs.b.c	free channel of a boolean output board

%QDs.b.c	free channel of an integer output board

%QSs.b.c	free channel of a message output board

Below are examples:

%QX1.6	6th channel of the board #1 (boolean output)

%ID2.1.7	7th channel of the board #1 in the equipment #2 (integer input)

A directly represented variable cannot have the "real" data type.


Boolean variables

Boolean means logic. Such variables can take one of the boolean values: TRUE or FALSE. Boolean variables are typically used in boolean expressions. Boolean variables can have one of the following attributes:

Internal:	memory variable updated by the program

Input:	variable connected to an input device (refreshed by the system)

Output:	variable connected to an output device

Warning: When declaring a boolean variable, strings can be defined to replace 'true' and 'false' values during debug. Those strings cannot be used in the programs unless entered as 'defined words' for the language.


Analog variables

Analog means continuous. Such variables have signed integer or real (floating) values. Available formats for an analog variable are:

Integer	32 bit signed integer: from -2147483647 to +2147483647

Real    	standard IEEE 32 bit floating value (single precision)

1 sign bit + 23 mantissa bits + 8 exponent bits

REAL analog exponent value cannot be less than -37 or greater than +37. Analog variables can have one of the following attributes:

Internal	memory variable updated by the program

Input	variable connected to an input device (refreshed by the system)

Output	variable connected to an output device

Note: When a real variable is connected to an I/O device, the corresponding I/O driver operates the equivalent integer value.

Warning: Integer and real analog variables or constant expressions cannot be mixed in the same analog expression.


Timer variables

Timer means clock or counter. Such variables have time values and are typically used in time expressions. A timer value cannot exceed 23h59m59s999ms and cannot be negative. Timer variables are stored in 32 bit words. The internal representation is a positive number of milliseconds.

Warning: Timer variables cannot have the INPUT or OUTPUT attributes.

Timer variables can be automatically refreshed by the ISaGRAF system. When a timer is active, its value is automatically increased according to the target system real time clock. The following statements of the ST language can be used to control a timer:

TSTART	starts automatic refresh of a timer

TSTOP	stops automatic refresh of a timer


Message string variables

Message or string variables contain character strings. The length of the string can change during process operations. The length of a message variable cannot exceed the capacity (maximum length) specified when the variable is declared. Message capacity is limited to 255 characters. Message variables can have one of the following attributes:

Internal	memory variable updated by the program

Input	variable connected to an input device (refreshed by the system)

Output	variable connected to an output device

String variables can contain any character of the standard ASCII table (ASCII code from 0 to 255). The null character can exist in a character string. Some "C" functions of the standard ISaGRAF library will not correctly operate messages which contain null (0) characters.


Comments

Comments may be freely inserted in literal languages such as ST and IL. A comment must begin with the special characters "(*" and terminate with the characters "*)". Comments can be inserted anywhere in a ST program, and can be written on more than one line.

These are examples of comments :

counter := ivalue;   (* assigns the main counter *)

(* this is a comment expressed

on two lines *)

c := counter (* you can put comments anywhere *) + base_value + 1;

Interleave comments cannot be used. This means that the "(*" characters cannot be used within a comment.

Warning: The IL language only accepts comments as the last component of an instruction line.


Defined words

The ISaGRAF system allows the re-definition of constant expressions, true and false boolean expressions, keywords or complex ST expressions. To achieve this, an identifier name has to be given to the corresponding expression. For example:

YES	is	TRUE

PI	is	3.14159

OK	is	(auto_mode AND NOT (alarm))

When such an equivalence is defined, its identifier can be used anywhere in an ST program to replace the attached expression. This is an example of ST programming using defines:

If OK Then

   angle := PI / 2;

   isdone := YES;

End_if;

Defined words can be LOCAL to one program, GLOBAL, or COMMON.

Local defined words can be used by only one program.

Global defined words can be used in any program of the project.

Common defined words can be used in any program of any project.

Note that common defined can be stored separately with the Archive manager.

Warning: When the same identifier is defined twice with different ST equivalencies,  the last defined expression is used. For example:

Define:	OPEN	is	FALSE

OPEN	is	TRUE

means:	OPEN	is	TRUE

Naming defined words must conform to following rules:

- name cannot exceed 16 characters

- first character must be a letter

- following characters can be letters, digits or underscore ('_') character

Warning: A defined word can not use a defined word in its definition, for example, you can not have :

PI	is	3.14159

PI2 	is	PI*2

write the complete equivalence using constants or variables and operations:

PI2 	is	6.28318


 IL language

Instruction List, or IL is a low level language. It is highly effective for smaller applications or for optimizing parts of an application. Instructions always relate to the current result (or IL register). The operator indicates the operation that must be made between the current value and the operand. The result of the operation is stored again in the current result.

IL main syntax

IL operators


IL main syntax

An IL program is a list of instructions. Each instruction must begin on a new line, and must contain an operator, completed with optional modifiers and, if necessary, for the specific operation, one or more operands, separated with commas (','). A label followed by a colon (':') may precede the instruction. If a comment is attached to the instruction, it must be the last component of the line. Comments always begin with '(*' and ends with '*)'. Empty lines may be entered between instructions. Comments may be put on empty lines.

Labels

Operator modifiers

Delayed operations

Below are examples of instruction lines:

Label	Operator	Operand	Comments

Start:	LD	IX1	(* push button *)

ANDN	MX5	(* command is not forbidden *)

ST	QX2	(* start motor *)


Labels

A label followed by a colon (':') may precede the instruction. A label can be put on an empty line. Labels are used as operands for some operations such as jumps. Naming labels must conform to the following rules:

- name cannot exceed 16 characters

- first character must be a letter

- following characters must be letters, digits or '_' character

The same name cannot be used for more than one label in the same IL program. A label can have the same name as a variable.


Operator modifiers

The available operator modifiers are shown below. The modifier character must complete the name of the operator, with no blank characters between them:

N	boolean negation of the operand

(	delayed operation

C	conditional operation

The 'N' modifier indicates a boolean negation of the operand. For example, the instruction ORN IX12 is interpreted as: result := result OR NOT (IX12).

The parenthesis '(' modifier indicates that the evaluation of the instruction must be delayed until the closing parenthesis ')' operator is encountered.

The 'C' modifier indicates that the attached instruction must be executed only if the current result has the boolean value TRUE (different than 0 for non-boolean values). The 'C' modifier can be combined with the 'N' modifier to indicate that the instruction must be executed only if the current result has the boolean value FALSE (or 0 for non-boolean values).


Delayed operations

Because there is only one IL register (current result), some operations may have to be delayed, so that the execution order or the instructions can be changed. Parentheses are used to indicate delayed operations:

'('	is a modifier	indicates the operation to be delayed

')'	is an operator	executes the delayed operation

The opening parenthesis '(' modifier indicates that the evaluation of the instruction must be delayed until the closing parenthesis ')' operator is encountered. For example, following sequence:

AND(	IX12

OR	IX35

)

is interpreted as:

result := result AND ( IX12 OR IX35 )


IL operators

  The following table summarizes the standard operators of the IL language:

Operator	Modifiers	Operand	Description

LD	N	Variable, constant	Loads operand

ST	N	Variable	Stores current result

S	BOO variable	Sets to TRUE

R	BOO variable	Resets to FALSE

CAL	C   N	FB instance name	Calls a function block

JMP	C   N	Label	Jumps to label

RET	C   N	Returns from sub-program

 ) 	Executes delayed operation

Function	Call function or sub-program

AND	N   (	BOO	boolean AND

&	N   (	BOO	boolean AND

OR	N   (	BOO	boolean OR

XOR	N   (	BOO	exclusive OR

ADD	(	variable, constant	Addition

SUB	(	variable, constant	Subtraction

MUL	(	variable, constant	Multiplication

DIV	(	variable, constant	Division

GT	(	variable, constant	Test: >

GE	(	variable, constant	Test: >=

EQ	(	variable, constant	Test: =

LE	(	variable, constant	Test: <=

LT	(	variable, constant	Test: <

NE	(	variable, constant	Test: <>

In the next section, only operators which are specific to the IL language are described, other standard operators can be found in the section "standard operators, function blocks and functions".


LD operator

Operation	loads a value in the current result

Allowed modifiers	N

Operand	constant expression

internal, input or output variable

Example:

(* EXAMPLES OF LD OPERATIONS *)

LDex:	LD	false	(* result := FALSE boolean constant *)

LD	true	(* result := TRUE boolean constant *)

LD	123	(* result := integer constant *)

LD	123.1	(* result := real constant *)

LD	t#3ms	(* result := time constant *)

LD	boo_var1	(* result := boolean variable *)

LD	ana_var1	(* result := analog variable *)

LD	tmr_var1	(* result := timer variable *)

LDN	boo_var2	(* result := NOT ( boolean variable ) *)


ST operator

Operation	stores the current result in a variable

the current result is not modified by this operation

Allowed modifiers	N

Operand	internal or output variable

Example:

(* EXAMPLES OF ST OPERATIONS *)

STboo:	LD	false

ST	boo_var1	(* boo_var1 := FALSE *)

STN	boo_var2	(* boo_var2 := TRUE *)

STana:	LD	123

ST	ana_var1	(* ana_var1 := 123 *)

STtmr:	LD	t#12s

ST	tmr_var1	(* tmr_var1 := t#12s *)


S operator

Operation:	stores the boolean value TRUE in a boolean variable, if the current result has the boolean value TRUE. No operation is processed if current result is FALSE. The current result is not modified by this operation

Allowed modifiers:	(none)

Operand:	output or internal boolean variable

Example:

(* EXAMPLES OF S OPERATIONS *)

SETex:	LD	true	(* current result := TRUE *)

S	boo_var1	(* boo_var1 := TRUE *)

(* current result is not modified *)

LD	false	(* current result := FALSE *)

S	boo_var1	(* nothing done - boo_var1 unchanged *)


R operator

Operation	stores the boolean value FALSE in a boolean variable, if the current result has the boolean value TRUE. No operation is processed if current result is FALSE. The current result is not modified by this operation

Allowed modifiers	(none)

Operand	output or internal boolean variable

Example:

(* EXAMPLES OF R OPERATIONS *)

RESETex:	LD	true	(* current result := TRUE *)

R	boo_var1	(* boo_var1 := FALSE *)

(* current result is not modified *)

ST	boo_var2	(* boo_var2 := TRUE *)

LD	false	(* current result := FALSE *)

R	boo_var1	(* nothing done - boo_var1 unchanged *)


JMP operator

Operation	jumps to the specified label

Allowed modifiers	C   N

Operand	label defined in the same IL program

Example:

(* the following example tests the value of an analog selector (0 or 1 or 2) 	*)

(* to set one from 3 output booleans. Test "is equal to 0" is made with	*)

(* the JMPC operator 	*)

JMPex:	LD	selector	(* selector is 0 or 1 or 2 *)

BOO	(* conversion to boolean *)

JMPC	test1	(* if selector = 0 then *)

LD	true

ST	bo0	(* bo0 := true *)

JMP	JMPend	(* end of the program *)

test1:	LD 	selector

SUB	1	(* decrease selector:  is now 0 or 1 *)

BOO	(* conversion to boolean *)

JMPC	test2	(* if selector = 0 then *)

LD	true

ST	bo1	(* bo1 := true *)

JMP	JMPend	(* end of the program *)

test2:	LD	true	(* last possibility *)

ST	bo2	(* bo2 := true *)

JMPend:	(* end of the IL program *)


RET operator

Operation	ends the current instruction list. If the IL sequence is a sub-program, the current result is returned to the calling program

Allowed modifiers	C   N

Operand	(none)

Example:

(* the following example tests the value of an analog selector (0 or 1 or 2)	*)

(* to set one from 3 output booleans. Test "is equal to 0" is made with	*)

(* the JMPC operator	 	*)

JMPex:	LD	selector	(* selector is 0 or 1 or 2 *)

BOO	(* conversion to boolean *)

JMPC	test1	(* if selector = 0 then *)

LD	true

ST	bo0	(* bo0 := true *)

RET	(* end - return 0 *)

(* decrease selector *)

test1:	LD 	selector

SUB	1	(* selector is now 0 or 1 *)

BOO	(* conversion to boolean *)

JMPC	test2	(* if selector = 0 then *)

LD	true

ST	bo1	(* bo1 := true *)

LD	1	(* load real selector value *)

RET	(* end - return 1 *)

(* last possibility *)

test2:	RETNC	(* returns if the selector has *)

(* an invalid value *)

LD	true

ST	bo2	(* bo2 := true *)

LD	2	(* load real selector value *)

 	(* end - return 2 *)


")" operator

Operation	executes a delayed operation. The delayed operation was notified by '('

Allowed modifiers	(none)

Operand	(none)

Example:

(* The following program interleaves delayed operations: *)

(* res := a1 + (a2 * (a3 - a4) * a5) + a6; *)

Delayed:	LD	a1	(* result := a1; *)

ADD(	a2	(* delayed ADD - result := a2; *)

MUL(	a3	(* delayed MUL - result := a3; *)

SUB	a4	(* result := a3 - a4; *)

)	(* execute delayed MUL - result := a2 * (a3-a4); *)

MUL	a5	(* result := a2 * (a3 - a4) * a5; *)

)	(* execute delayed ADD *)

(* result := a1 + (a2 * (a3 - a4) * a5); *)

ADD	a6	(* result := a1 + (a2 * (a3 - a4) * a5) + a6; *)

ST	res	(* store current result in variable res *)


Calling sub-programs or functions

A sub-program or a function (written in any of the IL, ST, LD, FBD or "C" language) is called from the IL language, using its name as an operator.

Operation	executes a sub-program or a function - the value returned by the sub-program or function is stored into the IL current result

Allowed modifiers	(none)

Operand	The first calling parameter must be stored in the current result before the call. The following ones are expressed in the operand field, separated by comas.

Example:

(* Calling program : converts an analog value into a time value *)

Main:	LD	bi0

SUBPRO	bi1,bi2	(* call sub-program to get analog value *)

ST	result	(* result := value returned by sub-program *)

GT	vmax	(* test value overflow *)

RETC	(* return if overflow *)

LD	result

MUL	1000	(* converts seconds in milliseconds *)

TMR	(* converts to a timer *)

ST	tmval	(* stores converted value in a timer *)

(* Called sub-program named 'SUBPRO' : evaluates the analog value *)

(* given as a binary value on three boolean inputs: in0, in1, in2 are the three boolean input parameters of the sub-program *)

LD	in2

ANA	(* result = ana (in2); *)

MUL	2	(* result := 2*ana (in2); *)

ST	temporary	(* temporary := result *)

LD	in1

ANA

ADD 	temporary	(* result := 2*ana (in2) + ana (in1); *)

MUL	2	(* result := 4*ana (in2) + 2*ana (in1); *)

ST	temporary	(* temporary := result *)

LD	in0

ANA

ADD	temporary	(* result := 4*ana (in2) + 2*ana (in1)+ana (in0); *)

ST	SUBPRO	(* return current result to calling program *)


Calling function blocks: CAL operator

Operation	calls a function block

Allowed modifiers	C   N

Operand	Name of the function block instance.

The input parameters of the blocks must be assigned before the call using LD/ST operations sequence.

Output parameters are known if used.

Example1:

(* Calling function block SR : SR1 is an instance of SR *)

LD	auto_mode

AND	start_cmd

ST	SR1.set1

LD	stop_cmd

ST	SR1.reset

CAL	SR1

LD	SR1.Q1

ST	command

(* FBD equivalent : *)

Example 2

(*We suppose R_TRIG1 is an instance of R_TRIG block and CTU1 is an instance of CTU block*)

LD	command

ST	R_TRIG1.clk

CAL	R_TRIG1

LD	R_TRIG1.Q

ST	CTU1.cu

LDN	auto_mode

ST	CTU1.reset

LD	100

ST	CTU1.pv

CAL	CTU1

LD	CTU1.Q

ST	overflow

LD	CTU1.cv

ST	result

(* FBD equivalent: *)


 ST language

ST (Structured Text) is a high level structured language designed for automation processes. This language is mainly used to implement complex procedures that cannot be easily expressed with graphic languages. ST is the default language for the description of the actions within the steps and conditions attached to the transitions of the SFC language.

ST main syntax

Expression and parentheses

Function or function block calls

ST specific boolean operators

ST basic statements

ST extensions


ST main syntax

An ST program is a list of ST statements. Each statement ends with a semi-colon (";") separator. Names used in the source code (variable identifiers, constants, language keywords...) are separated with inactive separators (space character, end of line or tab stops) or by active separators, which have a well defined significance (for example, the ">" separator indicates a "greater than" comparison. Comments may be freely inserted into the text. A comment must begin with "(*" and ends with "*)". Each statement terminates with a semi-colon (";") separator. These are basic types of ST statements:

- assignment statement (variable := expression;)

- sub-program or function call

- function block call

- selection statements (IF, THEN, ELSE, CASE...)

- iteration statements (FOR, WHILE, REPEAT...)

- control statements (RETURN, EXIT...)

- special statements for links with other languages such as SFC

Inactive separators may be freely entered between active separators, constant expressions and identifiers. ST inactive separators are: Space (blank) character, Tabs and End of line character. Unlike line-formatted languages such as IL, end of lines may be entered anywhere in the program. The rules shown below should be followed when using inactive separators to increase ST program readability:

- Do not write more than one statement on one line

- Use tabs to indent complex statements

- Insert comments to increase readability of lines or paragraphs

Source readability - examples:

Low readability	High readability
imax := max_ite; cond := X12; if not(cond (* alarm *) then return; end_if; for i (* index *) := 1 to max_ite do if i <> 2 then Spcall(); end_if; end_for; (* no effect if alarm *)	(* imax : number of iterations *) (* i: FOR statement index *) (* cond: process validity *) imax := max_ite; cond := X12; if not (cond) then     return; end_if; (* process loop *) for i := 1 to max_ite do     if i <> 2 then         Spcall ();     end_if; end_for;


Expression and parentheses

ST expressions combine ST operators and variable or constant operands. For each single expression (combining operands with one ST operator), the type of the operands must be the same. This single expression has the same type as its operands, and can be used in a more complex expression. For example :

(boo_var1 AND boo_var2)	has BOO type

not (boo_var1)	has BOO type

(sin (3.14) + 0.72)	has REAL ANALOG type

(t#1s23 + 1.78)	is an invalid expression

Parentheses are used to isolate sub parts of the expression, and to explicitly order the priority of the operations. When no parentheses are given for a complex expression, the operation sequence is implicitly given by the default priority between ST operators. For example:

2 + 3 * 6 	equals 2+18=20	because multiplication operator has a higher priority

(2+3) * 6	equals 5*6=30	priority is given by parenthesis

Warning: A maximum number of 8 levels of parentheses can be nested within an expression.


Function or function block calls

Standard ST function calls may be used for each of following objects:

- Sub-programs

- Library functions and function blocks written in IEC languages

- "C" functions and function blocks

- Type conversion functions

Calling sub-programs or functions

Calling function blocks


Calling sub-programs or functions

Name:	name of the called sub-program

or library function written in IEC language or in "C"

Meaning:	calls a ST, IL, LD or FBD sub-program or function or a "C" function

and gets its return value

Syntax:	<variable> := <subprog> (<par1>, ... <parN> );

Operands:	The type of return value and calling parameters must follow

the interface defined for the sub-program.

Return value:	value returned by the sub-program

Sub-program calls may be used in any expression. They also may be used in an SFC transition.

Example1: Sub-program call

(* Main ST program *)

(* gets an analog value and converts it into a limited time value *)

ana_timeprog := SPlimit ( tprog_cmd );

appl_timer := tmr (ana_timeprog * 100);

(* Called FBD program named 'SPlimit' *)

Example2: Function call

(* functions used in complex expressions: min, max, right, mlen and left are standard "C" functions *)

limited_value := min (16, max (0, input_value) );

rol_msg := right (message, mlen (message) - 1) + left (message, 1);


Calling function blocks

Name:	name of the function block instance

Meaning:	calls a function block from the ISaGRAF library or from the user's library and accesses its return parameters

Syntax:	(* call of the function block *)

<blockname> ( <p1>, <p2> ... );

(gets its return parameters *)

<result> := <blockname>. <ret_param1>;

...

<result> := <blockname>. <ret_paramN>;

Operands:	parameters are expressions which match the type

of the parameters specified for that function block

Return value:	See Syntax to get the return parameters.

Consult the ISaGRAF library to find the meaning and type of each function block parameter. The function block instance (name of the copy) must be declared in the dictionary

Example :

(* ST program calling a function block *)

(* declare the instance of the block in the dictionary: *)

(* trigb1 : block R_TRIG - rising edge detection *)

(* function block activation from ST  language *)

trigb1 (b1);

(* return parameters access *)

If (trigb1.Q) Then nb_edge := nb_edge + 1; End_if;


ST specific boolean operators

The following boolean operators are specific to the ST language:

REDGE	rising edge detection

FEDGE	falling edge detection

Other standard boolean operators such as:

NOT	boolean negation

AND (&)	logical AND

OR	logical OR

XOR	logical exclusive OR

can be used. Their description is to be found in the section 'Standard operators, function blocks and functions'.


"REDGE" operator

Name:	REDGE

Meaning:	evaluates the rising edge of a complete boolean expression

Syntax:	<edge> := REDGE ( <boo_expression>,<memo_variable> );

Operands:	first operand is any boolean variable or complex expression

second operand is an internal boolean variable used to store the last state of the expression

Return value:	TRUE when the expression changes from FALSE to TRUE

FALSE for all other cases

The rising edge of an expression cannot be detected more than once in the same execution cycle, using the REDGE operator. This operator can be used to describe the condition attached to an SFC transition.

Warning: The "memory" boolean variable used to store the last state of the expression cannot be used as a trigger for edges of different expressions.

When the expression is a boolean variable named "xxx", a unique internal variable named "EDGE_xxx" should be declared and used it in the REDGE expressions for this variable. This method ensures that the memory variable is not overwritten during other REDGE evaluations.

Example:

(* ST program using REDGE operator *)

(* this program counts the rising edges of a boolean input *)

(* Bi120 is an input boolean variable *)

(* Edge_Bi120 is the memory of the Bi120 variable state *)

If REDGE (Bi120, Edge_Bi120) Then

Counter := Counter + 1;

End_if;

Note: this operator is not in the IEC1131-3 norm. You may prefer the use of R_TRIG standard block. It has been kept for compatibility reasons.


"FEDGE" operator

Name:	FEDGE

Meaning:	evaluates the falling edge of a boolean expression

Syntax:	<edge> := FEDGE ( <boo_expression>, <memo_variable> );

Operands:	first operand is any boolean variable or complex expression

second operand is an internal boolean variable used to store

the last state of the expression

Return value:	TRUE when the expression changes from TRUE to FALSE

FALSE for all other cases

The falling edge of an expression cannot be detected more than once in the same execution cycle, using the REDGE operator. The operator can be used to describe the condition attached to an SFC transition.

Warning: The "memory" boolean variable used to store the last state of the expression cannot be used as a trigger for edges of different expressions.

When the expression is a boolean variable named "xxx", a unique internal variable named "EDGE_xxx" should be declared and used it in the FEDGE expressions for this variable. This method ensures that the memory variable is not overwritten during other FEDGE evaluations.

Example:

(* ST program using FEDGE operator *)

(* this program counts the falling edges of a boolean input *)

(* Bi120 is an input boolean variable *)

(* Edge_Bi120 is the memory of the Bi120 variable state *)

If FEDGE (Bi120, Edge_Bi120) Then

Counter := Counter + 1;

End_if;

Note: this operator is not in the IEC1131-3 norm. You may prefer the use of F_TRIG standard block. It has been kept for compatibility reasons.


ST basic statements

The basic statements of the ST language are:

Assignment

RETURN statement

IF-THEN-ELSIF-ELSE structure

CASE statement

WHILE iteration statement

REPEAT iteration statement

FOR iteration statement

EXIT statement


Assignment

Name:	:=

Meaning:	assigns a variable to an expression

Syntax:	<variable> := <any_expression> ;

Operands:	variable must be internal or output

variable and expression must have the same type

The expression can be a call to a sub-program or a function from the ISaGRAF library

Example:

(* ST program with assignments *)

(* variable <<= variable *)

bo23 := bo10;

(* variable <<= expression *)

bo56 := bx34 OR alrm100 & (level >= over_value);

result := (100 * input_value) / scale;

(* assignment with sub-program return value *)

rc := PSelect ( );

(* assignment with function call *)

limited_value := min (16, max (0, input_value) );


RETURN statement

Name:	RETURN

Meaning:	terminates the execution of the current program

Syntax:	RETURN ;

Operands:	(none)

In an SFC action block, the RETURN statement indicates the end of the execution of that block only.

Example:

(* FBD specification of the program: programmable counter *)

(* ST implementation of the program, using RETURN statement *)

If not (CU) then

Q := false;

CV := 0;

RETURN;   (* terminates the program *)

end_if;

if R then

CV := 0;

else

if (CV < PV) then

CV := CV + 1;

end_if;

end_if;

Q := (CV >= PV);


IF-THEN-ELSIF-ELSE statement

Name:	IF ... THEN ... ELSIF ... THEN ... ELSE ... END_IF

Meaning:	executes one of two lists of ST statements

selection is made according to the value

of a boolean expression

Syntax:	IF <boolean_expression> THEN

   <statement> ;

   <statement> ;

   ...

ELSIF <boolean_expression> THEN

   <statement> ;

   <statement> ;

   ...

ELSE

   <statement> ;

   <statement> ;

   ...

END_IF;

The ELSE and ELSIF statements are optional. If the ELSE statement is not written, no instruction is executed when the condition is FALSE.

Example:

(* ST program using IF statement *)

IF manual AND not (alarm) THEN

level := manual_level;

bx126 := bi12 OR bi45;

ELSIF over_mode THEN

level := max_level;

ELSE

level := (lv16 * 100) / scale;

END_IF;

(* IF structure without ELSE *)

If overflow THEN

alarm_level := true;

END_IF;


CASE statement

Name:	CASE ... OF ... ELSE ... END_CASE

Meaning:	executes one of several lists of ST statements

selection is made according to an integer expression

Syntax:	CASE <integer_expression> OF

   <value> : <statements> ;

   <value> , <value> : <statements> ;

   ...

ELSE

   <statements> ;

END_CASE;

Case values must be integer constant expressions. Several values, separated by comas, can lead to the same list of statements. The ELSE statement is optional.

Example:

(* ST program using CASE statement *)

CASE error_code OF

255:	err_msg := 'Division by zero';

fatal_error := TRUE;

1:	err_msg := 'Overflow';

2, 3:	err_msg := 'Bad sign';

ELSE

err_msg := 'Unknown error';

END_CASE;


WHILE statement

Name:	WHILE ... DO ... END_WHILE

Meaning:	iteration structure for a group of ST statements

the "continue" condition is evaluated BEFORE any iteration

Syntax:	WHILE <boolean_expression> DO

   <statement> ;

   <statement> ;

   ...

END_WHILE ;

Warning: Because ISaGRAF is a synchronous system, input variables are not refreshed during WHILE iterations. The change of state of an input variable cannot be used to describe the condition of a WHILE statement.

Example:

(* ST program using WHILE statement *)

(* this program uses specific "C" functions to read characters *)

(* on a serial port *)

string := ''; (* empty string *)

nbchar := 0;

WHILE ((nbchar < 16) & ComIsReady ( )) DO

string := string + ComGetChar ( );

nbchar := nbchar + 1;

END_WHILE;


REPEAT statement

Name:	REPEAT ... UNTIL ... END_REPEAT

Meaning:	iteration structure for a group of ST statements

the "continue" condition is evaluated AFTER any iteration

Syntax:	REPEAT

   <statement> ;

   <statement> ;

  ...

UNTIL <boolean_condition>

END_REPEAT ;

Warning: Because ISaGRAF is a synchronous system, input variables are not refreshed during REPEAT iterations. The change of state of an input variable cannot be used to describe the ending condition of a REPEAT statement.

Example:

(* ST program using REPEAT statement *)

(* this program uses specific "C" functions to read characters *)

(* on a serial port *)

string := ''; (* empty string *)

nbchar := 0;

IF ComIsReady ( ) THEN

REPEAT

string := string + ComGetChar ( );

nbchar := nbchar + 1;

UNTIL ( (nbchar >= 16) OR NOT (ComIsReady ( )) )

END_REPEAT;

END_IF;


FOR statement

Name:	FOR ... TO ... BY ... DO ... END_FOR

Meaning:	executes a limited number of iterations,

using an integer analog index variable

Syntax:	FOR <index> := <mini> TO <maxi> BY <step> DO

   <statement> ;

   <statement> ;

END_FOR;

Operands:	index:	internal analog variable increased at any loop

mini:	initial value for index (before first loop)

maxi:	maximum allowed value for index

step:	index increment at each loop

The [ BY step ] statement is optional. If not specified, the increment step is 1

Warning: Because ISaGRAF is a synchronous system, input variables are not refreshed during FOR iterations.

This is the "while" equivalent of a FOR statement:

index := mini;

while (step <= maxi) do

   <statement> ;

   <statement> ;

   index := index + step;

end_while;

Example:

(* ST program using FOR statement *)

(* this program extracts the digit characters of a string *)

length := mlen (message);

target := ''; (* empty string *)

FOR index := 1 TO length BY 1 DO

code := ascii (message, index);

IF (code >= 48) & (code <= 57) THEN

target := target + char (code);

END_IF;

END_FOR;


EXIT statement

Name:	EXIT

Meaning:	exit from a FOR, WHILE or REPEAT iteration statement

Syntax:	EXIT;

Operands:	(none)

The EXIT is commonly used within an IF statement, inside a FOR, WHILE or REPEAT block.

Example:

(* ST program using EXIT statement *)

(* this program searches for a character in a string *)

length := mlen (message);

found := NO;

FOR index := 1 TO length BY 1 DO

code := ascii (message, index);

IF (code  = searched_char) THEN

found := YES;

EXIT;

END_IF;

END_FOR;


ST extensions

The following functions are extensions of the ST language:

TSTART - TSTOP: timer control

The following statements and functions are available to control the execution of the SFC child programs. They may be used inside ACTION(): ... END_ACTION; blocks in SFC steps.

GSTART	starts an SFC program

GKILL	kills an SFC program

GFREEZE	freezes an SFC program

GRST	restarts a frozen SFC program

GSTATUS	gets current status of an SFC program

Warning: These functions are not in the IEC 1131-3 norm.

Easy equivalent can be found for GSTART and GKILL using the following syntax in the SFC step:

child_name(S); (* equivalent to GSTART(child_name); *)

child_name(R); (* equivalent to GKILL(child_name); *)

The following fields can be used to access the status of an SFC step:

GSnnn.x	boolean value that represents the activity of the step

GSnnn.t	time elapsed since the last activation of the step

("nnn" is the reference number of the SFC step)

It is also possible to test the activity of a step declared in another SFC program, by using the following syntax:

GSnnn(progname).x

Warning: referencing a step of an other program, using this syntax is not in the IEC 1131-3 norm. An easy way to do the same respecting IEC rules, is to declare a global boolean variable in the dictionary which will represent the step activity to be tested (for example ref_step_X). Then you insert in the step, the variable with the N qualifier (ref_step_X(N);). Then in the program which wants to test the activity of the step, you use the variable.

Prog program	the other program which needs step activity of Prog program


TSTART statement

Name:	TSTART

Meaning:	starts the counting of a timer variable

timer value is not modified by the TSTART command, i.e. the counting starts from the current value of the timer.

Syntax:	TSTART ( <timer_variable> );

Operands:	any inactive timer variable

Return value:	(none)

Example:

(* SFC program using TSTART and TSTOP statements *)

Time diagram if bi100 is always FALSE:

The timer keeps the same value during one cycle.


TSTOP statement

Name:	TSTOP

Meaning:	stops updating a timer variable

timer value is not modified by the TSTOP command

Syntax:	TSTOP ( <timer_variable> );

Operands:	any active timer variable

Return value:	(none)

Example: See TSTART (the function is described above)


GSTART statement

Name:	GSTART

Meaning:	starts a child SFC program by putting a token

into each of its initial steps

Syntax:	GSTART ( <child_program> );

Operands:	the specified SFC program must be a child of the one

in which the statement is written

Return value:	(none)

Children of the child program are not automatically started by the GSTART statement.

Note: As GSTART is not in the IEC 1131-3 norm, prefer the use of the S qualifier, with the following syntax to start a child SFC:

Child_name(S);

Example: Use of GSTART and GKILL

(* Sequence 'Sfather' *)	(* Sequence 'Schild' *)


GKILL statement

Name:	GKILL

Meaning:	kills a child SFC program by removing the tokens

currently existing in its steps

Syntax:	GKILL ( <child_program> );

Operands:	the specified SFC program must be a child of the one

in which the statement is written

Return value:	(none)

Children of the child program are automatically killed  with the specified program.

Note: As GKILL is not in the IEC 1131-3 norm, prefer the use of the R qualifier, with the following syntax to kill a child SFC:

Child_name(R);

Example: See GSTART (function described above)


GFREEZE statement

Name:	GFREEZE

Meaning:	Suspends the execution of a child SFC program

Frozen program can be restarted by the GRST statement.

Syntax:	GFREEZE ( <child_program> );

Operands:	the specified SFC program must be a child of the one

in which the statement is written

Return value:	(none)

Children of the child program are automatically frozen along with the specified program.

Note: GFREEZE is not in the IEC 1131-3 norm.

Example:


GRST statement

Name:	GRST

Meaning:	restarts a child SFC program frozen by the GFREEZE

statement

Syntax:	GRST ( <child_program> );

Operands:	the specified SFC program must be a child of the one

in which the statement is written

Return value:	(none)

Children of the child program are automatically restarted by the GRST statement

Note: GRST is not in the IEC 1131-3 norm.

Example: See GFREEZE (function described above)


GSTATUS statement

Name:	GSTATUS

Meaning:	returns the current status of an SFC program

Syntax:	<ana_var> := GSTATUS ( <child_program> );

Operands:	the specified SFC program must be a child of the one

in which the statement is written

Return value:	0 = program is inactive (killed)

1 = program is active (started)

2 = program is frozen

Note: GFREEZE is not in the IEC 1131-3 norm.

Example:


 FBD language

The Functional Block Diagram (FBD) is a graphic language. It allows the programmer to build complex procedures by taking existing functions from the ISaGRAF library and wiring them together in the graphic diagram area.

FBD diagram main format

RETURN statement

Jumps and labels

Boolean negation

Calling function or function blocks from the FBD


FBD diagram main format

FBD diagram describes a function between input variables and output variables. A function is described as a set of elementary function blocks. Input and output variables are connected to blocks by connection lines. An output of a function block may also be connected to an input of another block.

An entire function operated by an FBD program is built with standard elementary function blocks from the ISaGRAF library. Each function block has a fixed number of input connection points and a fixed number of output connection points. A function block is represented by a single rectangle. The inputs are connected on its left border. The outputs are connected on its right border. An elementary function block performs a single function between its inputs and its outputs. The name of the function to be performed by the block is written in its rectangle symbol. Each input or output of a block has a well defined type.

Input variables of an FBD program must be connected to input connection points of function blocks. The type of each variable must be the same as the type expected for the associated input. An Input for FBD diagram can be a constant expression, any internal or input variable, or an output variable.

Output variables of an FBD program must be connected to output connection points of function blocks. The type of each variable must be the same as the type expected for the associated block output. An Output for FBD diagram can be any internal or output variable, or the name of the program (for sub-programs only). When an output is the name of the currently edited sub-program, it represents the assignment of the return value for the sub-program (returned to the calling program).

Input and output variables, inputs and outputs of the function blocks are wired together with connection lines. Single lines may be used to connect two logical points of the diagram:

- An input variable and an input of a function block

- An output of a function block and an input of another block

- An output of a function block and an output variable

The connection is oriented, meaning that the line carries associated data from the left extremity to the right extremity. The left and right extremities of the connection line must be of the same type.

Multiple right connection can be used to broadcast an information from its left extremity to each of its right extremities. All the extremities of the connection must be of the same type.


RETURN statement

The "<RETURN>" keyword may occur as a diagram output. It must be connected to a boolean output connection point of a function block. The RETURN statement represents a conditional end of the program: if the output of the box connected to the statement has the boolean value TRUE, the end (remaining part) of the diagram is not executed.

(* Example of an FBD program using RETURN statement *)

(* ST equivalence: *)

If auto_mode OR alarm Then

Return;

End_if;

bo67 := (bi10 AND bi23) OR x_cmd;


Jumps and labels

Labels and jumps are used to control the execution of the diagram. No other object may be connected on the right of a jump or label symbol. The following notations are used:

>>LAB	jump to a label (label name is "LAB")

LAB:	definition of a label (label name is "LAB")

If the connection line on the left of the jump symbol has the boolean state TRUE, the execution of the program directly jumps after the corresponding label symbol.

(* Example of an FBD program using labels and jumps *)

(* IL Equivalence: *)

ld	manual

and	b1

jmpc	NOMODIF

ld	input1

or	input2

st	result

NOMODIF:	ld	result

and	valid

st	cmd10


Boolean negation

A single connection line with its right extremity connected to an input of a function block can be terminated by a boolean negation. The negation is represented by a small circle. When a boolean negation is used, the left and right extremities of the connection line must have the BOOLEAN type.

(* Example of an FBD program using a boolean negation *)

(* ST equivalence: *)

output1 := input1 AND NOT (input2);


Calling function or function blocks from the FBD

The FBD language enables the calling of sub-programs, functions or function blocks. A sub-program, or function or function block is represented by a function box. The name written in the box is the name of  the sub-program or function or function blocks.

In case of a sub-program or a function, the return value is the only output of the function box.

A function blocks can have more than one outputs.

(* Example of an FBD program using SUB PROGRAM block *)

(* ST Equivalence *)

net_weight := Weighing (mode, delta); (* call sub-program *)

If (net_weight = 0) Then Return; End_if;

weight := net_weight + tare_weight;


 SFC language

Sequential Function Chart (SFC) is a graphic language used to describe sequential operations. The process is represented as a set of well defined steps, linked by transitions. A boolean condition is attached to each transition. Actions within the steps are detailed by using other languages (ST, IL, LD and FDB).

SFC chart main format

SFC basic components

Divergences and convergences

Macro steps

Actions within the steps

Conditions attached to transitions

SFC dynamic rules

SFC program hierarchy


SFC chart main format

An SFC program is a graphic set of steps and transitions, linked together by oriented links. Multiple connection links are used to represent divergences and convergences. Some parts of the complete program may be separated and represented in the main chart by a single symbol, called macro steps. The basic graphic rules of the SFC  are:

- A step cannot be followed by another step

- A transition cannot be followed by another transition


SFC basic components

The basic components (graphic symbols) of the SFC language are: steps and initial steps, transitions, oriented links, and jumps to a step.

Steps and initial steps

Transitions

Oriented links

Jump to a step


Steps and initial steps

A step is represented by a single square.  Each step is referenced by a number, written in the step square symbol. A main description of the step is written in a rectangle linked to the step symbol. This description is a free comment (not part of the programming language). The above information is called the Level 1 of the step:

At run time, a token indicates that the step is active:

Active step:	Inactive step:

The initial situation of an SFC program is expressed with initial steps. An initial step has a double bordered graphic symbol. A token is automatically placed in each initial step when the program is started.

Initial step:

An SFC program must contain at least one initial step. These are the attributes of a step. Such fields may be used in any of the other languages:

GSnnn.x	activity of the step (boolean value)

GSnnn.t	activation duration of the step (time value)

(where nnn is the reference number of the step)


Transitions

Transitions are represented by a small horizontal bar that crosses the connection link.  Each transition is referenced by a number, written next to the transition symbol. A main description of the transition is written on the right side of the transition symbol. This description is a free comment (not part of the programming language). The above information is called the Level 1 of the transition:


Oriented links

Single lines are used to link steps and transitions. These are oriented links. When the orientation is not explicitly given, the link is oriented from the top to the bottom.


Jump to a step

Jump symbols may be used to indicate a connection link from a transition to a step, without having to draw the connection line. The jump symbol must be referenced with the number of the destination step:

A jump symbol cannot be used to represent a link from a step to a transition. Example of jumps - the following charts are equivalent:


Divergences and convergences

Divergences are multiple connection links from one SFC symbol (step or transition) to many other SFC symbols. Convergences are multiple connection links from more than one SFC symbols to one other symbol. Divergences and convergences can be single or double.

Single divergences

Double divergences


Single divergences

A single divergence is a multiple link from one step to many transitions. It allows the active token to pass into one of a number of branches. A single convergence is a multiple link from many transitions to the same step. A single convergence is generally used to group the SFC branches which were started on a single divergence. Single divergences and convergences are represented by single horizontal lines.

Warning: The conditions attached to the different transitions at the beginning of a single divergence are not implicitly exclusive. The exclusivity has to be explicitly detailed in the conditions of the transitions to ensure that only one token progresses in one branch of the divergence at run time. Below is an example of single divergence and convergence:

(* SFC program with single divergence and convergence *)


Double divergences

A double divergence is a multiple link from one transition to many steps. It corresponds to parallel operations of the process. A double convergence is a multiple link from many steps to the same transition. A double convergence is generally used to group the SFC branches started on a double divergence. Double divergences and convergences are represented by double horizontal lines.

Example of double divergence and convergence:

(* SFC program with double divergence and convergence *)


Macro steps

A macro step is a unique representation of a unique group of steps and transitions. The body of the macro step is described separately, elsewhere in the same SFC program. It appears as a single symbol in the main SFC chart. This is the symbol used for a macro step :

The reference number written in the macro step symbol is the reference number of the first step in the body of the macro step. The macro step body must begin with a beginning step and terminate with an ending step. The chart must be self-contained. A beginning step has no upper link (no backward transition). An ending step has no lower link (no forward transition). A macro step symbol may be put in the body of another macro step.

Warning: Because macro step is a unique set of steps and transitions, the same macro step cannot be used more than once in an SFC program.

Example of macro step:

(* Main chart *)	(* Body of the macro step *)


Actions within the steps

The level 2 of an SFC step is the detailed description of the actions executed during the step activity. This description is made by using SFC literal features, and other languages such as Structured Text (ST). The basic types of actions are:

Boolean actions

Pulse actions

Non-stored actions

SFC actions

Several actions (with same or different types) can be described in the same step. The special features that enable the use of any of the other languages are:

Calling function and function blocks from an action

IL convention


Boolean actions

Boolean actions assign a boolean variable with the activity of the step. The boolean variable can be an output or an internal. It is assigned each time the step activity starts or stops. This is the syntax of the basic boolean actions:

<boolean_variable> (N) ;	assigns the step activity signal to the variable

<boolean_variable> ;	same effect (N attribute is optional)

/ <boolean_variable> ;	assigns the negation of the step activity signal to the variable

Other features are available to set or reset a boolean variable, when the step becomes active. This is the syntax of set and reset boolean actions:

<boolean_variable> (S) ;	sets the variable to TRUE when the step activity signal becomes TRUE

<boolean_variable> (R) ;	resets the variable to FALSE when the step activity signal becomes TRUE

The boolean variable must be an OUTPUT or an INTERNAL. The following SFC programming leads to the following behavior:

Example of boolean actions:

(* SFC program using BOOLEAN actions *)


Pulse actions

A pulse action is a list of ST or IL instructions, which are executed only once at the activation of the step. Instructions are written according to the following SFC syntax:

ACTION (P) :

(* ST statements *)

END_ACTION ;

The following shows the results of a pulse action:

Example of pulse action:


Non-stored actions

A non-stored (normal) action is a list of ST or IL instructions which are executed at each cycle during the whole active period of the step. Instructions are written according to the following SFC syntax:

ACTION (N) :

(* ST statements *)

END_ACTION ;

The following is the results of a non-stored action:

Example of non-stored action:


SFC actions

An SFC action is a child SFC sequence, started or killed according to the change of the step activity signal. An SFC action can have the N (Non stored), S (Set), or R (Reset) qualifier. This is the syntax of the basic SFC actions:

<child_prog> (N);	starts the child sequence when the step becomes active, and kills the child sequence when the step becomes inactive

<child_prog> ;	same effect (N attribute is optional)

<child_prog> (S);	starts the child sequence when the step becomes active.  nothing is done when the step becomes inactive

<child_prog> (R);	kills the child sequence when the step becomes active. nothing is done when the step becomes inactive

The SFC sequence specified as an action must be a child SFC program of the program currently being edited. Note that using the S (Set) or R (Reset) qualifiers for an SFC action has exactly the same effect as the GSTART and GKILL statements, programmed in an ST pulse action.

Below is an example of an SFC action. The main SFC program is named Father. It has two SFC children, called SeqMlx and SeqPump. The SFC programming of the father SFC program is:

(* SFC program using SFC actions *)


Calling function and function blocks from an action

Sub-programs, functions or function blocks (written in ST, IL, LD or FBD language) or "C" functions and "C" function blocks, can be directly called from an SFC action block, based on the following syntax :

For sub-programs, functions and "C" functions:

ACTION (P) :

result := sub_program ( ) ;

END_ACTION;

or

ACTION (N) :

result := sub_program ( ) ;

END_ACTION;

For function blocks in "C" or in ST, IL, LD, FBD:

ACTION (P) :

Fbinst(in1, in2);

result1 := Fbinst.out1;

result2 := Fbinst.out2;

END_ACTION;

or

ACTION (N) :

Fbinst(in1, in2);

result1 := Fbinst.out1;

result2 := Fbinst.out2;

END_ACTION;

Detailed syntax can be found in the ST language section.

Example of a sub-program call in action blocks:

(* SFC program with a sub-program call in an action block *)


IL convention

Instruction List (IL) programming may be directly entered in an SFC action block, based on the following syntax:

ACTION (P) :	(* or N *)

#info=IL

     <instruction>

     <instruction>

     ....

#endinfo

END_ACTION;

The special "#info=IL" and "#endinfo" keywords must be entered exactly this way, and are case sensitive. Space or tab characters cannot be inserted into, after or before the keywords. Below is an example of an IL program in an action block:

(* SFC program with an IL sequence in an action block *)


Conditions attached to transitions

At each transition, a boolean expression is attached that conditions the clearing of the transition. The condition is usually expressed with ST language or using the LD language (Quick LD editor). This is the Level 2 of the transition. Other structures may, however, be used:

ST convention

LD convention

IL convention

Calling functions from a transition

Warning: When no expression is attached to the transition, the default condition is TRUE.


ST convention

The Structured Text (ST) language can be used to describe the condition attached to a transition. The complete expression must have boolean type and must be terminated by a semi colon, according to the following syntax:

< boolean_expression > ;

The expression may be a TRUE or FALSE constant expression, a single input or an internal boolean variable, or a combination of variables that leads to a boolean value. Below is an example of ST programming for transitions:

(* SFC program with ST programming for transitions *)


LD convention

The Ladder Diagram (LD) language can be used to describe the condition attached to a transition. The diagram is composed of only one rung with one coil. The coil value represents the transitions value.

Below is an example of LD programming for transitions:


IL convention

Instruction List (IL) programming may be directly used to describe an SFC transition, according to the following syntax:

#info=IL

<instruction>

<instruction>

....

#endinfo

The value contained by the current result (IL register) at the end of the IL sequence causes the resulting of the condition to be attached to the transition:

current result = 0 	 	condition is FALSE

current result <> 0	condition is TRUE

The special "#info=IL" and "#endinfo" keywords must be entered exactly this way, and are case sensitive. Space or tab characters cannot be inserted into, after or before the keywords. Below is an example of IL programming for transitions:

(* SFC program with an IL program for transitions *)


Calling functions from a transition

Any sub-program or a function (written in FBD, LD, ST or IL language), or a "C" function can be called to evaluate the condition attached to a transition, according to the following syntax:

< sub_program > ( ) ;

The value returned by the sub-program or the function must be boolean and yields the resulting condition:

return value = 0	condition is FALSE

return value <> 0	condition is TRUE

Below is and example of a sub-program called in a transition:

(* SFC program with sub-program call for transitions *)


SFC dynamic rules

The five dynamic rules of the SFC language are:

 Initial situation

The initial situation is characterized by the initial steps which are, by definition, in the active state at the beginning of the operation. At least one initial step must be present in each SFC program.

 Clearing of a transition

A transition is either enabled or disabled. It is said to be enabled when all immediately preceding steps linked to its corresponding transition symbol are active, otherwise it is disabled. A transition cannot be cleared unless:

   - it is enabled, and

   - the associated transition condition is true.

 Changing of state of active steps

The clearing of a transition simultaneously leads to the active state of the immediately following steps and to the inactive state of the immediately preceding steps.

 Simultaneous clearing of transitions

Double lines may be used to indicate transitions which have to be cleared simultaneously. If such transitions are shown separately, the activity state of preceding steps (GSnnn.x) can be used to express their conditions.

 Simultaneous activation and deactivation of a step

If, during operation, a step is simultaneously activated and deactivated, priority is given to the activation.


SFC program hierarchy

The ISaGRAF system enables the description of the vertical structure of SFC programs. SFC programs are organized in a hierarchy tree. Each SFC program can control (start, kill...) other SFC programs. Such programs are called children of the SFC program which controls them. SFC programs are linked together into a main hierarchy tree, using a "father - child" relation.

The basic rules implied by the hierarchy structure are:

- SFC programs which have no father are called "main" SFC programs

- Main SFC programs are activated by the system when the application starts

- A program can have several child programs

- A child of a program cannot have more than one father

- A child program can only be controlled by its father

- A program cannot control the children of one of its own children

The basic actions that a father SFC program can take to control its child program are:

Start	(GSTART) Starts the child program: activates each of its initial steps. Children of this child program are not automatically started.

Kill	(GKILL) Kills the child program by deactivating each of its active steps. All the children of the child program are also killed.

Freeze	(GFREEZE) Suspends the execution of the program (deactivates actions of each of the active steps and suspend transition calculation), and memorizes the status of the program steps so the program can be restarted. All the children of the child program are also frozen.

Restart	(GRST) Restarts a frozen SFC program by reactivating all the suspended steps. Children of the program are not automatically restarted.

Get status	(GSTATUS) Gets the current status (active, inactive or frozen) of a child program.


 LD language

Ladder Diagram (LD) is a graphic representation of boolean equations, combining contacts (input arguments) with coils (output results). The LD language enables the description of tests and modifications of boolean data by placing graphic symbols into the program chart. LD graphic symbols are organized within the chart exactly as an electric contact diagram. LD diagrams are connected on the left side and on the right side to vertical power rails.

Power rails and connection lines

Multiple connection

Basic LD contacts and coils

RETURN statement

Jumps and labels

Blocks in LD

These are basic graphic components of an LD diagram:

Left vertical power rail

Right vertical power rail

Horizontal connection line

Vertical connection line

Multiple connection lines (all connected together)

Contact associated with a variable

Coil associated to an output or to an internal variable


Power rails and connection lines

An LD diagram is limited on the left and right side by vertical lines, named left power rail and right power rail respectively.

LD diagram graphic symbols are connected to power rails or to other symbols by connection lines. Connection lines are horizontal or vertical.

Each line segment has a boolean state FALSE or TRUE. The boolean state is the same for all the segments directly linked together. Any horizontal line connected to the left vertical power rail has the TRUE state.


Multiple connection

The boolean state given to a single horizontal connection line is the same on the left and on the right extremities of the line. Combining horizontal and vertical connection lines enables the building of multiple connections. The boolean state of the extremities of a multiple connection follows logic rules.

A multiple connection on the left combines more than one horizontal lines connected on the left side of a vertical line, and one line connected on its right side. The boolean state of the right extremity is the LOGICAL OR between all the left extremities.

(* Example of multiple LEFT connection *)

(* right extremity state is (v1 OR v2 OR v3) *)

A multiple connection on the right combines one horizontal line connected on the left side of a vertical line, and more than one line connected on its right side. The boolean state of the left extremity is propagated into each of the right extremities.

(* Example of multiple RIGHT connection *)

(* ST equivalence: *)

output1 := input1;

output2 := input1;

A multiple connection on the left and on the right combines more than one horizontal line connected on the left side of a vertical line, and more than one line connected on its right side. The boolean state of each of the right extremities is the LOGICAL OR between all the left extremities

(* Example of multiple LEFT and RIGHT connection *)

(* ST Equivalence: *)

output1 := input1 OR input2;

output2 := input1 OR input2;

output3 := input1 OR input2;


Basic LD contacts and coils

There are several symbols available for input contacts:

Direct contact

Inverted contact

Contacts with rising edge detection

Contacts with falling edge detection

There are several symbols available for output coils:

Direct coil

Inverted coil

SET coil

RESET coil

Coils with rising edge detection

Coils with falling edge detection

The name of the variable is written above any of these graphic symbols:


Direct contact

A direct contact enables a boolean operation between a connection line state and a boolean variable.

The state of the connection line on the right of the contact is the LOGICAL AND between the state of the left connection line and the value of the variable associated with the contact.

(* Example using DIRECT contacts *)

(* ST Equivalence: *)

output1 := input1 AND input2;


Inverted contact

An inverted contact enables a boolean operation between a connection line state and the boolean negation of a boolean variable.

The state of the connection line on the right of the contact is the LOGICAL AND between the state of the left connection line and the boolean negation of the value of the variable associated with the contact.

(* Example using INVERTED contacts *)

(* ST Equivalence: *)

output1 := NOT (input1) AND NOT (input2);


Contact with rising edge detection

This contact (positive) enables a boolean operation between a connection line state and the rising edge of a boolean variable.

The state of the connection line on the right of the contact is set to TRUE when the state of the connection line on the left is TRUE, and the state of the associated variable rises from FALSE to TRUE. It is reset to FALSE in all other cases.

(* Example using RISING EDGE contacts *)

(* ST Equivalence: *)

output1 := input1 AND (input2 AND NOT (input2prev));

(* input2prev is the value of input2 at the previous cycle *)


Contact with falling edge detection

This contact (negative) enables a boolean operation between a connection line state and the falling edge of a boolean variable.

The state of the connection line on the right of the contact is set to TRUE when the state of the connection line on the left is TRUE, and the state of the associated variable falls from TRUE to FALSE. It is reset to FALSE in all other cases.

(* Example using FALLING EDGE contacts *)

(* ST Equivalence: *)

output1 := input1 AND (NOT (input2) AND input2prev);

(* input2prev is the value of input2 at the previous cycle *)


Direct coil

Direct coils enable a boolean output of a connection line boolean state.

The associated variable is assigned with the boolean state of the left connection. The state of the left connection is propagated into the right connection. The right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

The associated name can be the name of the program (for sub-programs only). This corresponds to the assignment of the return value of the sub-program.

(* Example using DIRECT coils *)

(* ST Equivalence: *)

output1 := input1;

output2 := input1;


Inverted coil

Inverted coils enable a boolean output according to the boolean negation of a connection line state.

The associated variable is assigned with the boolean negation of the state of the left connection. The state of the left connection is propagated into the right connection. Right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

The associated name can be the name of the program (for sub-programs only). This corresponds to the assignment of the return value of the sub-program.

(* Example using INVERTED coils *)

(* ST Equivalence: *)

output1 := NOT (input1);

output2 := input1;


SET coil

"Set" coils enable a boolean output of a connection line boolean state.

The associated variable is SET TO TRUE when the boolean state of the left connection becomes TRUE. The output variable keeps this value until an inverse order is made by a "RESET" coil. The state of the left connection is propagated into the right connection. Right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

(* Example using "SET" and "RESET" coils *)

(* ST Equivalence: *)

IF input1 THEN

   output1 := TRUE;

END_IF;

IF input2 THEN

   output1 := FALSE;

END_IF;


RESET coil

"Reset" coils enable boolean output of a connection line boolean state.

The associated variable is RESET TO FALSE when the boolean state of the left connection becomes TRUE. The output variable keeps this value until an inverse order is made by a "SET" coil. The state of the left connection is propagated into the right connection. Right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

(* Example using "SET" and "RESET" coils *)

(* ST Equivalence: *)

IF input1 THEN

   output1 := TRUE;

END_IF;

IF input2 THEN

   output1 := FALSE;

END_IF;


Coil with rising edge detection

"Positive" coils enable boolean output of a connection line boolean state. This type of coils are only available using the Quick ladder editor.

The associated variable is set to TRUE when the boolean state of the left connection rises from FALSE to TRUE. The output variable resets to FALSE in all other cases. The state of the left connection is propagated into the right connection. Right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

(* Example using a "Positive" coil *)

(* ST Equivalence: *)

IF (input1 and NOT(input1prev)) THEN

   output1 := TRUE;

ELSE

   output1 := FALSE;

END_IF;

(* input1prev is the value of input1 at the previous cycle *)


Coil with falling edge detection

"Negative" coils enable boolean output of a connection line boolean state. This type of coils are only available using the Quick ladder editor.

The associated variable is set to TRUE when the boolean state of the left connection falls from TRUE to FALSE. The output variable resets to FALSE in all other cases. The state of the left connection is propagated into the right connection. Right connection may be connected to the right vertical power rail.

The associated boolean variable must be OUTPUT or INTERNAL.

(* Example using a "Positive" coil *)

(* ST Equivalence: *)

IF (NOT(input1) and input1prev) THEN

   output1 := TRUE;

ELSE

   output1 := FALSE;

END_IF;

(* input1prev is the value of input1 at the previous cycle *)


RETURN statement

The RETURN label can be used as an output to represent a conditional end of the program. No connection can be put on the right of a RETURN symbol.

If the left connection line has the TRUE boolean state, the program ends without executing the equations entered on the following lines of the diagram.

Note: When the LD program is a sub-program, its name has to be associated with an output coil to set the return value (returned to the calling program).

(* Example using RETURN symbol *)

(* ST Equivalence: *)

If Not (manual_mode) Then RETURN; End_if;

result := (input1 OR input3) AND input2;


Jumps and labels

Labels, conditional and unconditional JUMPS symbols, can be used to control the execution of the diagram. No connection can be put on the right of the label and jump symbol. The following notations are used:

>>LAB	jump to label named "LAB"

LAB:	definition of the label named "LAB"

If the connection on the left of the jump symbol has the TRUE boolean state, the program execution is driven after the label symbol.

(* Example using JUMP and LABEL symbols *)

(* IL Equivalence: *)

ldn	manual_mode

jmpc	other

ld	input1

st	result

jmp	END

OTHER:	ld	input2

st	result

END:	(* end of program *)


Blocks in LD

Using the Quick LD editor, you connect function boxes to boolean lines. A function can actually be an operator, a function block or a function. As all blocks do not have always a boolean input and/or a boolean output, inserting blocks in an LD diagram leads to the addition of new parameters EN, ENO to the block interface. The EN, ENO parameters are not added if you use the FBD/LD editor as you can connect the variable with the required type.

The "EN" input

The "ENO" output

Using both "EN" and "ENO"


The "EN" input

On some operators, functions or function blocks, the first input does not have boolean data type. As the first input must always be connected to the rung, another input is automatically inserted at the first position, called "EN". The block is executed only if the EN input is TRUE. Below is the example of a comparison operator, and the equivalent code expressed in ST:

	IF rung_state THEN    q := (value1 > value 2); ELSE    q := FALSE; END_IF; (* continue rung with q state *)


The "ENO" output

On some operators, functions or function blocks, the first output does not have boolean data type. As the first output must always be connected to the rung, another output is automatically inserted at the first position, called "ENO". The ENO output always takes the same state as the first input of the block. Below is an example with AVERAGE function block, and the equivalent code expressed in ST:

	AVERAGE(rung_state, Signal, 100); OutSignal := AVERAGE.XOUT; eno := rung_state; (* continue rung with eno state *)


Using both "EN" and "ENO"

On some cases, both EN and ENO are required. Below is an example with an arithmetic operator, and the equivalent code expressed in ST:

	IF rung_state THEN    result := (value1 + value2); END_IF; eno := rung_state; (* continue rung with eno state *)


 Standard operators, function blocks and functions

Standard operators

Standard function blocks

Standard functions

Alphabetical index


Standard operators

The following are standard operators of the IEC languages.

Data manipulation:

1 gain	Assignment

Neg	Analog negation

Boolean operations:

& (AND)	Boolean AND

>=1 (OR)	Boolean OR

=1 (XOR)	Boolean Exclusive OR

Arithmetic operations:

 + 	Addition

 - 	Subtraction

 * 	Multiplication

 / 	Division

Logic operations:

AND_MASK	Analog bit to bit AND mask

OR_MASK	Analog bit to bit OR mask

XOR_MASK	Analog bit to bit Exclusive OR mask

NOT_MASK	Bit to bit negation

Comparison tests:

 < 	Less than

 <= 	Less or equal to

 > 	Greater than

 >= 	Greater or equal to

 = 	Is equal to

 <> 	Is not equal to

Data conversion:

BOO	Convert to Boolean

ANA	Convert to Integer Analog

REAL	Convert to Real Analog

TMR	Convert to Timer

MSG	Convert to Message

Other:

CAT	Message concatenation

SYSTEM	System access

OPERATE	Operate I/O channel


1 gain

Arguments:

IN	any type

Q	any type

Description:

assignment of one variable into another one

This block is very useful to directly link a diagram input and a diagram output. It can also be used (with a boolean negation line) to invert the state of a line connected to a diagram output.

(* FBD example with assignment Blocks *)

(* ST equivalence: *)

ao23 := ai10;

bo100 := NOT (bi1 AND bi2);

(* IL equivalence: *)

LD	ai10

ST 	ao23

LD	bi1

AND	bi2

STN	bo100


NEG

Arguments:

IN	INT-REAL	input and output must have same format

Q	INT-REAL

Description:

Assignment of the negation of a variable.

(* FBD example with negation Blocks *)

(* ST equivalence: *)

ao23 := - (ai10);

ro100 := - (ri1 + ri2);

(* IL equivalence: *)

LD	ai10

MUL	-1

ST 	ao23

LD	ri1

ADD	ri2

MUL	-1.0

ST	ro100


& AND

Note: For this operator, the number of its inputs can be extended to more than two.

Arguments:

(inputs)	BOOLEAN

output	BOOLEAN	boolean AND of the input terms

Description:

Boolean AND between two or more terms.

(* FBD example with "AND" Blocks *)

(* ST equivalence: *)

bo10 := bi101 AND NOT (bi102);

bo5 := (bi51 AND bi52) AND bi53;

(* IL equivalence *)

LD	bi101	(* current result := bi101 *)

ANDN	bi102	(* current result := bi101 AND not(bi102) *)

ST	bo10	(* bo10 := current result *)

LD	bi51	(* current result := bi51;

&	bi52	(* current result := bi51 AND bi52 *)

&	bi53	(* current result := (bi51 AND bi52) AND bi53 *)

ST	bo5	(* bo5 := current result *)


>=1 OR

Note: For this operator, the number of its inputs can be extended to more than two.

Arguments:

(inputs)	BOOLEAN

output	BOOLEAN	boolean OR of the input terms

Description:

Boolean OR of two or more terms.

(* FBD example with "OR" Blocks *)

(* ST equivalence: *)

bo10 := bi101 OR NOT (bi102);

bo5 := (bi51 OR bi52) OR bi53;

(* IL equivalence: *)

LD	bi101

ORN	bi102

ST	bo10

LD	bi51

OR	bi52

OR	bi53

ST	bo5


=1 XOR

Arguments:

IN1	BOOLEAN

IN2	BOOLEAN

Q	BOOLEAN	boolean exclusive OR of the 2 input terms

Description:

Boolean exclusive OR between two terms.

(* FBD example with "XOR" Blocks *)

(* ST equivalence: *)

bo10 := bi101 XOR NOT (bi102);

bo5 := (bi51 XOR bi52) XOR bi53;

(* IL equivalence: *)

LD	bi101

XORN	bi102

ST	bo10

LD	bi51

XOR	bi52

XOR	bi53

ST	bo5


+

Note: For this operator, the number of its inputs can be extended to more than two.

Arguments:

(inputs)	INT-REAL	can be INTEGER or REAL

(all inputs must have the same format)

output	INT-REAL	signed addition of the input terms

Description:

Addition of two or more analog variables.

(* FBD example with Addition Blocks *)

(* ST equivalence: *)

ao10 := ai101 + ai102;

ao5 := (ai51 + ai52) + ai53;

(* IL equivalence: *)

LD	ai101

ADD	ai102

ST	ao10

LD	ai51

ADD	ai52

ADD	ai53

ST	ao5


-

Arguments:

IN1	INT-REAL	can be INTEGER or REAL

IN2	INT-REAL	(IN1 and IN2 must have the same format)

Q	INT-REAL	subtraction (first - second)

Description:

Subtraction of two analog variables (first - second).

(* FBD example with Subtraction Blocks *)

 (* ST equivalence: *)

ao10 := ai101 - ai102;

ao5 := (ai51 - 1) - ai53;

(* IL equivalence: *)

LD	ai101

SUB	ai102

ST	ao10

LD	ai51

SUB	1

SUB	ai53

ST	ao5


*

Note: For this operator, the number of its inputs can be extended to more than two.

Arguments:

(inputs)	INT-REAL	can be INTEGER or REAL

(all inputs must have the same format)

output	INT-REAL	signed multiplication of the input terms

Description:

Multiplication of two or more analog variables.

(* FBD example with Multiplication blocks *)

(* ST equivalence *)

ao10 := ai101 * ai102;

ao5 := (ai51 * ai52) * ai53;

(* IL equivalence: *)

LD	ai101

MUL	ai102

ST	ao10

LD	ai51

MUL	ai52

MUL	ai53

ST	ao5


/

Arguments:

IN1	INT-REAL	can be INTEGER or REAL (operand)

IN2	INT-REAL	non-zero analog value (divisor)

(IN1 and IN2 must have the same format)

Q	INT-REAL	signed integer or real division of IN1 by IN2

Description:

Division of two analog variables (the first divided by the second).

(* FBD example with Division blocks *)

(* ST Equivalence: *)

ao10 := ai101 / ai102;

ao5 := (ai5 / 2) / ai53;

(* IL equivalence: *)

LD	ai101

DIV	ai102

ST	ao10

LD	ai51

DIV	2

DIV	ai53

ST	ao5


AND_MASK

Arguments:

IN	INT	must have integer format

MSK	INT	must have integer format

Q	INT	bit to bit logical AND between IN and MSK

Description:

Integer analog AND bit to bit mask.

(* FBD example with Analog AND_MASK blocks *)

(* ST Equivalence: *)

parity := AND_MASK (xvalue, 1); (* 1 if xvalue is odd *)

result := AND_MASK (16#abc, 16#f0f); (* equals 16#a0c *)

(* IL equivalence: *)

LD	xvalue

AND_MASK	1

ST	parity

LD	16#abc

AND_MASK	16#f0f

ST	result


OR_MASK

Arguments:

IN	INT	must have integer format

MSK	INT	must have integer format

Q	INT	bit to bit logical OR between IN and MSK

Description:

Integer analog OR bit to bit mask.

(* FBD example with Analog OR_MASK blocks *)

(* ST Equivalence: *)

is_odd := OR_MASK (xvalue, 1); (* makes value always odd *)

result := OR_MASK (16#abc, 16#f0f); (* equals 16#fbf *)

(* IL equivalence: *)

LD	xvalue

OR_MASK	1

ST	is_odd

LD	16#abc

OR_MASK	16#f0f

ST	result


XOR_MASK

Arguments:

IN	INT	must have integer format

MSK	INT	must have integer format

Q	INT	bit to bit logical Exclusive OR between IN and MSK

Description:

Integer analog exclusive OR bit to bit mask

(* FBD example with XOR_MASK blocks *)

(* ST Equivalence: *)

crc32 := XOR_MASK (prevcrc, nextc);

result := XOR_MASK (16#012, 16#011); (* equals 16#003 *)

(* IL equivalence: *)

LD	prevcrc

XOR_MASK	nextc

ST	crc32

LD	16#012

XOR_MASK	16#011

ST	result


NOT_MASK

Arguments :

IN	INT	must have integer format

Q	INT	bit to bit negation on 32 bits of IN

Description:

Integer analog bit to bit negation mask

(* FBD example with NOT_MASK blocks *)

(*ST equivalence: *)

result := NOT_MASK (16#1234);

(* result is 16#FFFF_EDCB *)

(* IL equivalence: *)

LD	16#1234

NOT_MASK

ST	result


<

Arguments:

IN1	INT-REAL-

TMR-MSG

IN2	INT-REAL-

TMR-MSG	both inputs must have the same type

Q	BOOLEAN	TRUE if IN1 < IN2

Description:

Test if one value is LESS THAN another one (on analog, timer or messages)

(* FBD example with "Less than" blocks *)

(* ST Equivalence: *)

aresult := (10 < 25); (* aresult is TRUE *)

mresult := ('z' < 'B'); (* mresult is FALSE *)

(* IL equivalence: *)

LD	10

LT	25

ST	aresult

LD	'z'

LT	'B'

ST	mresult


<=

Arguments:

IN1	INT-REAL-MSG

IN2	INT-REAL-MSG	both inputs must have the same type

Q	BOOLEAN	TRUE if IN1 <= IN2

Description:

Test if one value is LESS THAN or EQUAL TO another one (on analog, or messages)

(* FBD example with "Less or equal to" blocks *)

(* ST Equivalence: *)

aresult := (10 <= 25); (* aresult is TRUE *)

mresult := ('ab' <= 'ab'); (* mresult is TRUE *)

(* IL equivalence: *)

LD	10

LE	25

ST	aresult

LD	'ab'

LE	'ab'

ST	mresult


>

Arguments:

IN1	INT-REAL-

TMR-MSG

IN2	INT-REAL-

TMR-MSG 	both inputs must have the same type

Q	BOOLEAN	TRUE if IN1 > IN2

Description:

Test if one value is GREATER THAN another one (on analog, timer or messages)

(* FBD example with "Greater than" blocks *)

(* ST Equivalence: *)

aresult := (10 > 25); (* aresult is FALSE *)

mresult := ('ab' > 'a'); (* mresult is TRUE *)

(* IL equivalence: *)

LD	10

GT	25

ST	aresult

LD	'ab'

GT	'a'

ST	mresult


>=

Arguments:

IN1	INT-REAL-MSG

IN2	INT-REAL-MSG 	both inputs must have the same type

Q	BOOLEAN	TRUE if IN1 >= IN2

Description:

Test if one value is GREATER THAN or EQUAL TO another one (on analog, or messages)

(* FBD example with "Greater or Equal to" blocks *)

(* ST Equivalence: *)

aresult := (10 >= 25); (* aresult is FALSE *)

mresult := ('ab' >= 'ab'); (* mresult is TRUE *)

(* IL equivalence: *)

LD	10

GE	25

ST	aresult

LD	'ab'

GE	'ab'

ST	mresult


=

Arguments:

IN1	INT-REAL-MSG

IN2	INT-REAL-MSG 	both inputs must have the same type

Q	BOOLEAN	TRUE if IN1 = IN2

Description:

Test if one value is EQUAL TO another one (on analog, or messages)

(* FBD example with "Is Equal to" blocks *)

(* ST Equivalence: *)

aresult := (10 = 25); (* aresult is FALSE *)

mresult := ('ab' = 'ab'); (* mresult is TRUE *)

(* IL equivalence: *)

LD	10

EQ	25

ST	aresult

LD	'ab'

EQ	'ab'

ST	mresult


<>

Arguments:

IN1	INT-REAL-MSG

IN2	INT-REAL-MSG 	both inputs must have the same type

Q	BOOLEAN	TRUE if first <> second

Description:

Test if one value is NOT EQUAL TO another one (on analog, or messages)

(* FBD example with "Is Not Equal to" blocks *)

(* ST Equivalence: *)

aresult := (10 <> 25); (* aresult is TRUE *)

mresult := ('ab' <> 'ab'); (* mresult is FALSE *)

(* IL equivalence: *)

LD	10

NE	25

ST	aresult

LD	'ab'

NE	'ab'

ST	mresult


BOO

Arguments:

IN	ANY	any non-boolean value

Q	BOO	TRUE for non-zero numerical value

FALSE for zero numerical value

TRUE for 'TRUE' message

FALSE for 'FALSE' message

Description:

Convert any variable to a boolean one

(* FBD example with "Convert to Boolean" blocks *)

(* ST Equivalence: *)

ares := BOO (10);	(* ares is TRUE *)

tres := BOO (t#0s);	(* tres is FALSE *)

mres := BOO ('false');	(* mres is FALSE *)

(* IL equivalence: *)

LD	10

BOO

ST	ares

LD	t#0s

BOO

ST	tres

LD	'false'

BOO

ST	mres


ANA

Arguments:

IN	ANY	any non-integer analog value

Q	INT	0 if IN is FALSE / 1 if IN is TRUE

number of milliseconds for a timer

integer part for real analog

decimal number represented by a string

Description:

Convert any variable to an integer one

(* FBD example with "Convert to Analog" blocks *)

(* ST Equivalence: *)

bres := ANA (true);	(* bres is 1 *)

tres := ANA (t#1s46ms);	(* tres is 1046 *)

mres := ANA ('0198');	(* mres is 198 *)

(* IL equivalence: *)

LD	true

ANA

ST	bres

LD	t#1s46ms

ANA

ST	tres

LD	'0198'

ANA

ST	mres


REAL

Arguments:

IN	BOO-INT-

TMR	any non-real analog value (no message)

Q	REAL	0.0 if IN is FALSE / 1.0 if IN is TRUE

number of milliseconds for a timer

equivalent number for integer analog

Description:

Convert any variable to a real one

(* FBD example with "Convert to Real" blocks *)

(* ST Equivalence: *)

bres := REAL (true);	(* bres is 1.0 *)

tres := REAL (t#1s46ms);	(* tres is 1046.0 *)

ares := REAL (198);	(* ares is 198.0 *)

(* IL equivalence: *)

LD	true

REAL

ST	bres

LD	t#1s46ms

REAL

ST	tres

LD	198

REAL

ST	ares


TMR

Arguments:

IN	INT-REAL	any non-timer value

IN (or integer part of IN if it is real)

is the number of milliseconds

Q	TIMER	time value represented by IN

Description:

Convert any analog variable to a timer one

(* FBD example with "Convert to Timer" blocks *)

 (* ST Equivalence: *)

ares := TMR (1256);	(* ares := t#1s256ms *)

rres := TMR (1256.3);	(*rres := t#1s256ms *)

(* IL equivalence: *)

LD	1256

TMR

ST	ares

LD	1256.3

TMR

ST	rres


MSG

Arguments:

IN	BOO-

INT-REA	any non-message value

Q	MSG	'false' or 'true' if IN is a boolean

decimal representation if IN is an analog

Description:

Convert any variable to a message one

(* FBD example with "Convert to Message" blocks *)

(* ST Equivalence: *)

bres := MSG (true); (* bres is 'TRUE' *)

ares := MSG (125); (* ares is '125' *)

(* IL equivalence: *)

LD	true

MSG

ST	bres

LD	125

MSG

ST	ares


CAT

Note: For this operator, the number of its inputs can be extended to more than two.

Arguments:

(inputs)	MSG	(addition of all message length must not exceed output message capacity)

output	MSG	concatenation of the input messages

Description:

Concat several messages into one

(* FBD example with "Message Concatenation" blocks *)

(* ST Equivalence: use the + operator *)

myname := ('Mr' + ' ') + 'Jones';

(* means: myname := 'Mr Jones' *)

(* IL equivalence: *)

LD	'Mr'

ADD	' '

ADD	'Jones'

ST	myname


SYSTEM

Arguments:

Mode	INT	identifies the system parameter and the access mode

Arg	INT-TMR	new value for a "write" access

Param	INT	value of the accessed parameter

Description:

Access to the system parameters

The following is the list of available commands (pre-defined keywords) for the SYSTEM function:

command	meaning

SYS_TALLOWED	read allowed cycle timing

SYS_TCURRENT	read current cycle timing

SYS_TMAXIMUM	read maximum cycle timing

SYS_TOVERFLOW	read cycle timing overflows

SYS_TRESET	reset timing counters

SYS_TWRITE	change cycle timing

SYS_ERR_TEST	check for run time errors

SYS_ERR_READ	read oldest run time error

These are expected arguments for pre-defined functions of the SYSTEM function:

command	argument	return value

SYS_TALLOWED	0	allowed cycle timing

SYS_TCURRENT	0	current cycle timing

SYS_TMAXIMUM	0	maximum detected timing

SYS_TOVERFLOW	0	number of timing overflows

SYS_TRESET	0	0

SYS_TWRITE	new allowed	written time

cycle timing

SYS_ERR_TEST	0	0 if no error detected

SYS_ERR_READ	0	oldest error code

(* FBD example with "System" blocks *)

(* ST Equivalence: *)

alarm := (SYSTEM (SYS_TOVERFLOW, 0) <> 0);

If (alarm) Then

nb_err := nb_err + 1;

rc := SYSTEM (SYS_TRESET, 0);

End_If;


OPERATE

Arguments:

IO	ANY	input or output variable

Funct	INT	action to be operated

Arg	INT	argument for I/O action

Q	INT	return check

Description:

Access to an I/O channel

The meaning of OPERATE arguments depends on the I/O interface implementation. Refer to your hardware manual or corresponding I/O board technical note to learn more about OPERATE capabilities.


Standard function blocks

These are standard function blocks supported by the ISaGRAF system. Such function blocks are pre-defined and do not have to be declared in the library.

Booleans:

SR	Set dominant bistable

RS	Reset dominant bistable

R_TRIG	Rising edge detection

F_TRIG	Falling edge detection

SEMA	Semaphore

Counting:

CTU	Up counter

CTD	Down counter

CTUD	Up-down counter

Timers:

TON	On-delay timing

TOF	Off-delay timing

TP	Pulse timing

Integer analogs:

CMP	Full comparison function block

STACKINT	Stack of integer analogs

Real analogs:

AVERAGE	Running average over N samples

HYSTER	Boolean hysteresis on difference of reals

LIM_ALRM	High/low limit alarm with hysteresis

INTEGRAL	Integration over time

DERIVATE	Differentiation according to time

Signal generation:

BLINK	Blinking boolean signal

SIG_GEN	Signal generator

Note: When new "C" function blocks are created, they can be called from the FBD language.


SR

Arguments:

SET1	BOO	if TRUE, sets Q1 to TRUE (dominant)

RESET	BOO	if TRUE, resets Q1 to FALSE

Q1	BOO	boolean memory state

Description:

Set dominant bistable: See True table below:

Set1 	Reset	Q1	result Q1

0 	0	0	0

0	0	1	1

0	1	0	0

0	1	1	0

1	0	0	1

1	0	1	1

1	1	0	1

1	1	1	1

(* FBD program using "SR" block *)

(* ST Equivalence: We suppose SR1 is an instance of SR block *)

SR1((auto_mode & start_cmd), stop_cmd);

command := SR1.Q1;

(* IL Equivalence: *)

LD	auto_mode

AND	start_cmd

ST	SR1.set1

LD	stop_cmd

ST	SR1.reset

CAL	SR1

LD	SR1.Q1

ST	command


RS

Arguments:

SET	BOO	if TRUE, sets Q1 to TRUE

RESET1	BOO	if TRUE, resets Q1 to FALSE (dominant)

Q1	BOO	boolean memory state

Description:

Reset dominant bistable: See True table below:

Set 	Reset1	Q1	result Q1

0 	0	0	0

0	0	1	1

0	1	0	0

0	1	1	0

1	0	0	1

1	0	1	1

1	1	0	0

1	1	1	0

(* FBD program using "RS" block *)

(* ST Equivalence: We suppose RS1 is an instance of RS block *)

RS1(start_cmd, (stop_cmd OR alarm));

command := RS1.Q1;

(* IL Equivalence: *)

LD	start_cmd

ST	RS1.set

LD	stop_cmd

OR	alarm

ST	RS1.reset1

CAL	RS1

LD	RS1.Q1

ST	command


R_TRIG

Arguments:

CLK	BOO	any boolean variable

Q	BOO	TRUE when CLK rises from FALSE to TRUE

FALSE if all other cases

Description:

Detects a rising edge of a boolean variable

(* FBD program using "R_TRIG" block *)

(* ST Equivalence: We suppose R_TRIG1 is an instance of R_TRIG block *)

R_TRIG1(cmd);

nb_edge := ANA(R_TRIG1.Q) + nb_edge;

(* IL Equivalence: *)

LD	cmd

ST	R_TRIG1.clk

CAL	R_TRIG1

LD	R_TRIG1.Q

ANA

ADD	nb_edge

ST	nb_edge


F_TRIG

Arguments:

CLK	BOO	any boolean variable

Q	BOO	TRUE when CLK changes from TRUE to FALSE

FALSE if all other cases

Description:

Detects a falling edge of a boolean variable

(* FBD program using "F_TRIG" block *)

(* ST Equivalence: We suppose F_TRIG1 is an instance of F_TRIG block *)

F_TRIG1(cmd);

nb_edge := ANA(F_TRIG1.Q) + nb_edge;

(* IL Equivalence: *)

LD	cmd

ST	F_TRIG1.clk

CAL	F_TRIG1

LD	F_TRIG1.Q

ANA

ADD	nb_edge

ST	nb_edge


SEMA

Arguments:

CLAIM	BOOLEAN	"test and set" command

RELEASE	BOOLEAN	releases the semaphore

BUSY	BOOLEAN	state of the semaphore

Description:

(* "x" is a boolean variable initialized to FALSE *)

busy := x;

If claim Then

x := True;

Else

If release Then

busy := False;

x := False;

End_if;

End_if;


CTU

Arguments:

CU	BOO	counting input (counting when CU is TRUE)

RESET	BOO	reset command (dominant)

PV	INT	programmed maximum value

Q	BOO	overflow: TRUE when CV = PV

CV	INT	counter result

Warning: The CTU block does not detect the rising or falling edges of the counting input (CU). It must be associated with an "R_TRIG" or "F_TRIG" block to create a pulse counter.

Description:

Count (integer) from 0 up to a given value 1 by 1

(* FBD program using "CTU" block *)

(* ST Equivalence: We suppose R_TRIG1 is an instance of R_TRIG block and CTU1 is an instance of CTU block*)

CTU1(R_TRIG1(command),NOT(auto_mode),100);

overflow := CTU1.Q;

result := CTU1.CV;

(* IL Equivalence: *)

LD	command

ST	R_TRIG1.clk

CAL	R_TRIG1

LD	R_TRIG1.Q

ST	CTU1.cu

LDN	auto_mode

ST	CTU1.reset

LD	100

ST	CTU1.pv

CAL	CTU1

LD	CTU1.Q

ST	overflow

LD	CTU1.cv

ST	result


CTD

Arguments:

CD	BOO	counting input

(down-counting when CD is TRUE)

LOAD	BOO	load command (dominant)

(CV = PV when LOAD is TRUE)

PV	INT	programmed initial value

Q	BOO	underflow: TRUE when CV = 0

CV	INT	counter result

Warning: The CTD block does not detect the rising or falling edges of the counting input (CD). It must be associated with an "R_TRIG" or "F_TRIG" block to create a pulse counter.

Description:

Count (integer) from a given value down to 0 1 by 1

(* FBD program using "CTD" block *)

 (* ST Equivalence: We suppose F_TRIG1 is an instance of F_TRIG block and CTD1 is an instance of CTD block*)

CTD1(F_TRIG1(command),load_cmd,100);

underflow := CTD1.Q;

result := CTD1.CV;

(* IL Equivalence: *)

LD	command

ST	F_TRIG1.clk

CAL	F_TRIG1

LD	F_TRIG1.Q

ST	CTD1.cd

LD	load_cmd

ST	CTD1.load

LD	100

ST	CTD1.pv

CAL	CTD1

LD	CTD1.Q

ST	underflow

LD	CTD1.cv

ST	result


CTUD

Arguments:

CU	BOO	up-counting (when CU is TRUE)

CD	BOO	down-counting (when CD is TRUE)

RESET	BOO	reset command (dominant)

(CV = 0 when RESET is TRUE)

LOAD	BOO	load command (CV = PV when LOAD is TRUE)

PV	INT	programmed maximum value

QU	BOO	overflow: TRUE when CV = PV

QD	BOO	underflow: TRUE when CV = 0

CV	INT	counter result

Warning: The CTUD block does not detect the rising or falling edges of the counting inputs (CU and CD). It must be associated with an "R_TRIG" or "F_TRIG" block to create a pulse counter.

Description:

Count (integer) from 0 up to a given value 1 by 1

or from a given value down to 0 1 by 1

(* FBD program using "CTUD" block *)

(* ST Equivalence: We suppose R_TRIG1 and R_TRIG2 are two instances of R_TRIG block and CTUD1 is an instance of CTUD block*)

CTUD1(R_TRIG1(add_elt), R_TRIG2(sub_elt), reset_cmd, load_cmd,100);

full := CTUD1.QU;

empty := CTUD1.QD;

nb_elt := CTUD1.CV;

(* IL Equivalence: *)

LD	add_elt

ST	R_TRIG1.clk

CAL	R_TRIG1

LD	R_TRIG1.Q

ST	CTUD1.cu

LD	sub_elt

ST	R_TRIG2.clk

CAL	R_TRIG2

LD	R_TRIG2.Q

ST	CTUD1.cd

LD	reset_cmd

ST	CTUD1.reset

LD	load_cmd

ST	CTUD1.load

LD	100

ST	CTUD1.pv

CAL	CTUD1

LD	CTUD1.QU

ST	full

LD	CTUD1.QD

ST	empty

LD	CTUD1.CV

ST	nb_elt


TON

Arguments:

IN	BOO	If Rising edge, starts increasing internal timer

If Falling Edge, stops and resets internal timer

PT	TMR	maximum programmed time

Q	BOO	If TRUE, programmed time is elapsed

ET	TMR	current elapsed time

Description:

Increase an internal timer up to a given value.

Timing diagram:


TOF

Arguments:

IN	BOO	If Falling edge, starts increasing internal timer

If Rising edge, stops and resets internal timer

PT	TMR	maximum programmed time

Q	BOO	If TRUE: total time is not elapsed

ET	TMR	current elapsed time

Description:

Increase an internal timer up to a given value.

Timing diagram:


TP

Arguments:

IN	BOO	If Rising edge, starts increasing internal timer (if not already increasing)

If FALSE and only if timer is elapsed, resets the internal timer

Any change on IN during counting has no effect.

PT	TMR	maximum programmed time

Q	BOO	If TRUE: timer is counting

ET	TMR	current elapsed time

Description:

Increase an internal timer up to a given value.

Timing diagram:


CMP

Arguments:

VAL1	INT	any signed integer analog value

VAL2	INT	any signed integer analog value

LT	BOO	TRUE if val1 is Less Than val2

EQ	BOO	TRUE if val1 is Equal to val2

GT	BOO	TRUE if val1 is Greater Than val2

Description:

Compare two values: tell if they are equal, or if the first is less or greater than the second one.

(* FBD program using "CMP" block *)

(* ST Equivalence: We suppose CMP1 is an instance of CMP block *)

CMP1(level, max_level);

pump_cmd := CMP1.LT OR CMP1.EQ;

alarm := CMP1.GT AND NOT(manual_mode);

(* IL Equivalence: *)

LD	level

ST	CMP1.val1

LD	max_level

ST	CMP1.val2

CAL	CMP1

LD	CMP1.LT

OR	CMP1.EQ

ST	pump_cmd

LD	CMP1.GT

ANDN	manual_mode

ST	alarm


STACKINT

Arguments:

PUSH	BOO	push command (on rising edge only)

add the IN value on the top of the stack

POP	BOO	pop command (on rising edge only)

delete in the stack the last value pushed (top of the stack)

R1	BOO	resets the stack to its empty state

IN	INT	pushed value

N	INT	application defined stack size

EMPTY	BOO	TRUE if the stack is empty

OFLO	BOO	overflow: TRUE if the stack is full

OUT	INT	value at the top of the stack

Description:

Manage a stack of integer values.

The "STACKINT" function block includes a rising edge detection for both PUSH and POP commands. The maximum size of the stack is 128. The application defined stack size N cannot be less than 1 or greater than 128.

Note that OFLO value is valid only after a reset (R1 has been set to TRUE at least once and back to FALSE).

(* FBD program using "STACKINT" block: error management *)

(* ST Equivalence: We suppose STACKINT1 is an instance of STACKINT block *)

STACKINT1(err_detect, acknoledge, manual_mode, err_code, max_err);

appli_alarm := auto_mode AND NOT(STACKINT1.EMPTY);

err_alarm := STACKINT1.OFLO;

last_error := STACKINT1.OUT;

(* IL Equivalence: *)

LD	err_detect

ST	STACKINT1.push

LD	acknoledge

ST	STACKINT1.pop

LD	manual_mode

ST	STACKINT1.r1

LD	err_code

ST	STACKINT1.IN

LD	max_err

ST	STACKINT1.N

CAL	STACKINT1

LD	auto_mode

ANDN	STACKINT1.empty

ST	appli_alarm

LD	STACKINT1.OFLO

ST	err_alarm

LD	STACKINT1.OUT

ST	last_error


AVERAGE

Arguments:

RUN	BOO	TRUE=run / FALSE=reset

XIN	REAL	any real analog variable

N	INT	application defined number of samples

XOUT	REAL	running average of XIN value

Description:

Stores a value at each cycle and calculates the average value of all already stored values. Only the N last values are stored.

The number of samples N cannot exceed 128.

If the "RUN" command is FALSE (reset mode), the output value is equal to the input value.

When the maximum N of stored values is reached, the first stored value is erased by the last one.

(* FBD program using "AVERAGE" block: *)

(* ST Equivalence: AVERAGE1 instance of AVERAGE block *)

AVERAGE1((auto_mode & store_cmd), sensor_value, 100);

ave_value := AVERAGE1.XOUT;

(* IL Equivalence: *)

LD	auto_mode

AND	store_cmd

ST	AVERAGE1.run

LD	sensor_value

ST	AVERAGE1.xin

LD	100

ST	AVERAGE1.N

CAL	AVERAGE1

LD	AVERAGE1.XOUT

ST	ave_value


HYSTER

Arguments:

XIN1	REAL	any real analog value

XIN2	REAL	to test if XIN1 has overpassed XIN2+EPS

EPS	REAL	hysteresis value (must be greater than zero)

Q	BOO	TRUE if XIN1 has overpassed XIN2+EPS and is not yet below XIN2-EPS

Description:

Hysteresis on a real value for a high limit.

Example of timing diagram:


LIM_ALRM

Arguments:

H	REAL	high limit value

X	REAL	input: any real analog value

L	REAL	low limit value

EPS	REAL	hysteresis value (must be greater than zero)

QH	BOO	"high" alarm: TRUE if X above high limit H

Q	BOO	alarm output: TRUE if X out of limits

QL	BOO	"low" alarm: TRUE if X below low limit L

Description:

Hysteresis on a real value for high and low limits.

An hysteresis is applied on high and low limits. The hysteresis delta used for either high or low limit is one half of the EPS parameter. Below is an example of timing diagram:


INTEGRAL

Arguments:

RUN	BOO	mode: TRUE=integrate / FALSE=hold

R1	BOO	overriding reset

XIN	REAL	input: any real analog value

X0	REAL	initial value

CYCLE	TMR	sampling period

Q	BOO	Not R1

XOUT	REAL	integrated output

Description:

Integration of a real value.

If the "CYCLE" parameter value is less than the cycle timing of the ISaGRAF application, the sampling period is the cycle timing of the application.

(* FBD program using "INTEGRAL" block: *)

(* ST Equivalence: INTEGRAL1 instance of INTEGRAL block *)

INTEGRAL1(manual_mode, NOT(manual_mode), sensor_value, init_value, t#100ms);

controlled_value := INTEGRAL1.XOUT;

(* IL Equivalence: *)

LD	manual_mode

ST	INTEGRAL1.run

STN	INTEGRAL1.R1

LD	sensor_value

ST	INTEGRAL1.XIN

LD	init_value

ST	INTEGRAL1.X0

LD	t#100ms

ST	INTEGRAL1.CYCLE

CAL	INTEGRAL1

LD	INTEGRAL1.XOUT

ST	controlled_value


DERIVATE

Arguments:

RUN	BOO	mode: TRUE=normal / FALSE=reset

XIN	REAL	input: any real analog value

CYCLE	TMR	sampling period

XOUT	REAL	differentiated output

Description:

Differentiation of a real value.

If the "CYCLE" parameter value is less than the cycle timing of the ISaGRAF application, the sampling period is the cycle timing of the application.

(* FBD program using "DERIVATE" block: *)

(* ST Equivalence: DERIVATE1 instance of DERIVATE block *)

DERIVATE1(manual_mode, sensor_value, t#100ms);

derivated_value := DERIVATE1.XOUT;

(* IL Equivalence: *)

LD	manual_mode

ST	DERIVATE1.run

LD	sensor_value

ST	DERIVATE1.XIN

LD	t#100ms

ST	DERIVATE1.CYCLE

CAL	DERIVATE1

LD	DERIVATE1.XOUT

ST	derivated_value


BLINK

Arguments:

RUN	BOO	mode: TRUE=blinking / FALSE=reset the output to false

CYCLE	TMR	blinking period

Q	BOO	output blinking signal

Description:

Generates a blinking signal.

Timing diagram:


SIG_GEN

Arguments:

RUN	BOO	mode: TRUE=running / FALSE=reset to false

PERIOD	TMR	duration of one sample

MAXIMUM	INT	maximum counting value

PULSE	BOO	inverted after each sample

UP	INT	up-counter, increased on each sample

END	BOO	TRUE when up-counting ends

SINE	REAL	sine signal (period = counting duration)

Description:

Generates various signal: blink on a boolean, a integer counter-up, and real sine wave.

When counting reaches maximum value, it restarts from 0 (zero). So END keeps the TRUE value only during 1 PERIOD.

Timing diagram:


Standard functions

These are standard functions supported by the ISaGRAF system. Such functions are pre-defined and do not have to be declared in the library.

Math:

ABS	Absolute value

EXPT	Exponent

LOG	Logarithm

POW	Power calculation

SQRT	Square root

TRUNC	Truncate decimal part

Trigonometric:

ACOS	Arc cosine

ASIN	Arc sine

ATAN	Arc tangent

COS	Cosine

SIN	Sine

TAN	Tangent

Register control:

ROL	Rotate Left

ROR	Rotate Right

SHL	Shift Left

SHR	Shift Right

Data manipulation:

MIN	Minimum

MAX	Maximum

LIMIT	Limit

MOD	Modulo

MUX4	Multiplexer (4 entries)

MUX8	Multiplexer (8 entries)

ODD	Odd parity

RAND	Random value

SEL	Binary selector

Data conversion:

ASCII	Character  ASCII code

CHAR	ASCII code  Character

String management

DELETE	Delete sub-string

INSERT	Insert string

FIND	Find sub-string

MLEN	Get string length

LEFT	Extract left

MID	Extract middle

REPLACE	Replace sub-string

RIGHT	or right of a string

DAY_TIME	Time of day

Array manipulation:

ARCREATE	Create array of integer values

ARREAD	Read array element

ARWRITE	Write array element

Binary file management:

F_ROPEN	Open a binary file in Read mode

F_WOPEN	Open a binary file in Write mode

F_CLOSE	Close a binary file

F_EOF	Test the end of a binary file

FA_READ	Read an analog value in a binary file

FA_WRITE	Write an analog value to a binary file

FM_READ	Read a message string in a binary file

FM_WRITE	Write a message string to a binary file


ABS

Arguments:

IN	REAL	any signed real analog value

Q	REAL	absolute value (always positive)

Description:

Gives the absolute (positive) value of a real value.

(* FBD program using "ABS" block *)

(* ST Equivalence: *)

over := (ABS (delta) > range);

(* IL Equivalence: *)

LD	delta

ABS

GT 	range

ST	over


EXPT

Arguments:

IN	REAL	any signed real analog value

EXP	INT	integer analog exponent

Q	REAL	(IN EXP)

Description:

Gives the real result of the operation: (base exponent) 'base' being the first argument and 'exponent' the second one.

(* FBD program using "EXPT" block *)

(* ST Equivalence: *)

tb_size := ANA (EXPT (2.0, range) );

(* IL Equivalence: *)

LD	2.0

EXPT	range

ANA

ST	tb_size


LOG

Arguments:

IN	REAL	must be greater than zero

Q	REAL	logarithm (base 10) of the input value

Description:

Calculates the logarithm (base 10) of a real value.

(* FBD program using "LOG" block *)

(* ST Equivalence: *)

xpos := ABS (xval);

xlog := LOG (xpos);

(* IL Equivalence: *)

LD	xval

ABS

ST	xpos

LOG

ST	xlog


POW

Arguments:

IN	REAL	real analog number to be raised

EXP	REAL	power (exponent)

Q	REAL	(IN EXP)

1.0 if IN is not 0.0 and EXP is 0.0

0.0 if IN is 0.0 and EXP is negative

0.0 if both IN and EXP are 0.0

0.0 if IN is negative and Y does not correspond to an integer

Description:

Gives the real result of the operation: (base exponent) 'base' being the first argument and 'exponent' the second one. The exponent is a real value.

(* FBD program using "POW" block *)

(* ST Equivalence: *)

result := POW (xval, power);

(* IL Equivalence: *)

LD	xval

POW	power

ST	result


SQRT

Arguments:

IN	REAL	must be greater than or equal to zero

Q	REAL	square root of the input value

Description:

Calculates the square root of a real value.

(* FBD program using "SQRT" block *)

(* ST Equivalence: *)

xpos := ABS (xval);

xroot := SQRT (xpos);

(* IL Equivalence: *)

LD	xval

ABS

ST	xpos

SQRT

ST	xrout


TRUNC

Arguments:

IN	REAL	any REAL analog value

Q	REAL	if IN>0, biggest integer less or equal to the input

if IN<0, least integer greater or equal to the input

Description:

Truncates a real value to have just the integer part

(* FBD program using "TRUNC" block *)

(* ST Equivalence: *)

result := TRUNC (+2.67) + TRUNC (-2.0891);

(* means: result := 2.0 + (-2.0) := 0.0; *)

(* IL Equivalence: *)

LD	2.67

TRUNC

ST	temporary	(* temporary result of first TRUNC *)

LD	-2.0891

TRUNC

ADD	temporary

ST	result


ACOS

Arguments:

IN	REAL	must be in set [-1.0 .. +1.0]

Q	REAL	arc-cosine of the input value (in set [0.0 .. PI])

= 0.0 for invalid input

Description:

Calculates the Arc cosine of a real value.

(* FBD program using "COS" and "ACOS" blocks *)

(* ST Equivalence: *)

cosine := COS (angle);

result := ACOS (cosine); (* result is equal to angle *)

(* IL Equivalence: *)

LD	angle

COS

ST	cosine

ACOS

ST	result


ASIN

Arguments:

IN	REAL	must be in set [-1.0 .. +1.0]

Q	REAL	arc-sine of the input value (in set [-PI/2 .. +PI/2])

= 0.0 for invalid input

Description:

Calculates the Arc sine of a real value.

(* FBD program using "SIN" and "ASIN" blocks *)

(* ST Equivalence: *)

sine := SIN (angle);

result := ASIN (sine); (* result is equal to angle *)

(* IL Equivalence: *)

LD	angle

SIN

ST	sine

ASIN

ST	result


ATAN

Arguments:

IN	REAL	any real analog value

Q	REAL	arc-tangent of the input value (in set [-PI/2 .. +PI/2])

= 0.0 for invalid input

Description:

Calculates the Arc tangent of a real value.

(* FBD program using "TAN" and "ATAN" block *)

(* ST Equivalence: *)

tangent := TAN (angle);

result := ATAN (tangent); (* result is equal to angle*)

(* IL Equivalence: *)

LD	angle

TAN

ST	tangent

ATAN

ST	result


COS

Arguments:

IN	REAL	any REAL analog value

Q	REAL	cosine of the input value (in set [-1.0 .. +1.0])

Description:

Calculates the Cosine of a real value.

(* FBD program using "COS" and "ACOS" blocks *)

(* ST Equivalence: *)

cosine := COS (angle);

result := ACOS (cosine); (* result is equal to angle *)

(* IL Equivalence: *)

LD	angle

COS

ST	cosine

ACOS

ST	result


SIN

Arguments:

IN	REAL	any REAL analog value

Q	REAL	sine of the input value (in set [-1.0 .. +1.0])

Description:

Calculates the Sine of a real value.

(* FBD program using "SIN" and "ASIN" blocks *)

(* ST Equivalence: *)

sine := SIN (angle);

result := ASIN (sine); (* result is equal to angle *)

(* IL Equivalence: *)

LD	angle

SIN

ST	sine

ASIN

ST	result


TAN

Arguments:

IN	REAL	cannot be equal to PI/2 modulo PI

Q	REAL	tangent of the input value

= 1E+38 for invalid input

Description:

Calculates the Tangent of a real value.

(* FBD program using "TAN" and "ATAN" block *)

(* ST Equivalence: *)

tangent := TAN (angle);

result := ATAN (tangent); (* result is equal to angle*)

(* IL Equivalence: *)

LD	angle

TAN

ST	tangent

ATAN

ST	result


ROL

Arguments:

IN	INT	any integer analog value

NbR	INT	number of 1 bit rotations (in set [1..31])

Q	INT	left rotated value

no effect if NbR <= 0

Description:

Make the bits of an integer rotate to the left. Rotation is made on 32 bits:

(* FBD program using "ROL" block *)

(* ST Equivalence: *)

result := ROL (register, 1);

(* register = 2#0100_1101_0011_0101*)

(* result    = 2#1001_1010_0110_1010*)

(* IL Equivalence: *)

LD	register

ROL	1

ST	result


ROR

Arguments:

IN	INT	any integer analog value

NbR	INT	number of 1 bit rotations (in set [1..31])

Q	INT	right rotated value

no effect if NbR <= 0

Description:

Make the bits of an integer rotate to the right. Rotation is made on 32 bits:

(* FBD program using "ROR" block *)

(* ST Equivalence: *)

result := ROR (register, 1);

(* register = 2#0100_1101_0011_0101 *)

(* result    = 2#1010_0110_1001_1010 *)

(* IL Equivalence: *)

LD	register

ROR	1

ST	result


SHL

Arguments:

IN	INT	any integer analog value

NbS	INT	number of 1 bit shifts (in set [1..31])

Q	INT	left shifted value

no effect if NbS <= 0

0 is used to replace lowest bit

Description:

Make the bits of an integer shift to the left. Shift is made on 32 bits:

(* FBD program using "SHL" block *)

(* ST Equivalence: *)

result := SHL (register,1);

(* register = 2#0100_1101_0011_0101 *)

(* result    = 2#1001_1010_0110_1010 *)

(* IL Equivalence: *)

LD	register

SHL	1

ST	result


SHR

Arguments:

IN	INT	any integer analog value

NbS	INT	number of 1 bit shifts (in set [1..31])

Q	INT	right shifted value

no effect if NbS <= 0

highest bit is copied at each shift

Description:

Make the bits of an integer shift to the right. Shift is made on 32 bits:

(* FBD program using "SHR" block *)

(* ST Equivalence: *)

result := SHR (register,1);

(* register = 2#1100_1101_0011_0101 *)

(* result    = 2#1110_0110_1001_1010 *)

(* IL Equivalence: *)

LD	register

SHR	1

ST	result


MIN

Arguments:

IN1	INT	any signed integer analog value

IN2	INT	(cannot be REAL)

Q	INT	minimum of both input values

Description:

Gives the minimum of two integer values.

(* FBD program using "MIN" and "MAX" block *)

(* ST Equivalence: *)

new_value := MAX (MIN (max_value, value), min_value);

(* bounds the value to the [min_value..max_value] set *)

(* IL Equivalence: *)

LD	max_value

MIN	value

MAX	min_value

ST	new_value


MAX

Arguments:

IN1	INT	any signed integer analog value

IN2	INT	(cannot be REAL)

Q	INT	maximum of both input values

Description:

Gives the maximum of two integer values.

(* FBD program using "MIN" and "MAX" block *)

(* ST Equivalence: *)

new_value := MAX (MIN (max_value, value), min_value);

(* bounds the value to the [min_value..max_value] set *)

(* IL Equivalence: *)

LD	max_value

MIN	value

MAX	min_value

ST	new_value


LIMIT

Arguments:

MIN	INT	minimum allowed value

IN	INT	any signed integer analog value

MAX	INT	maximum allowed value

Q	INT	input value bounded to allowed range

Description:

Limits an integer value into a given interval. Whether it keeps its value if it is between minimum and maximum, or it is changed to maximum if it is above, or it is changed to minimum if it is below.

(* FBD program using "LIMIT" block *)

(* ST Equivalence: *)

new_value := LIMIT (min_value, value, max_value);

(* bounds the value to the [min_value..max_value] set *)

(* IL Equivalence: *)

LD	min_value

LIMIT	value, max_value

ST	new_value


MOD

Arguments:

IN	INT	any signed INTEGER analog value

Base	INT	must be greater than zero

Q	INT	modulo calculation (input MOD base)

returns -1 if Base <= 0

Description:

Calculates the modulo of an integer value.

(* FBD program using "MOD" block *)

(* ST Equivalence: *)

division_result := (value / divider); (* integer division *)

rest_of_division := MOD (value, divider); (* rest of the division *)

(* IL Equivalence: *)

LD	value

DIV	divider

ST	division_result

LD	value

MOD	divider

ST	rest_of_division


MUX4

Arguments:

SEL	INT	selector integer value (must be in set [0..3])

IN1..IN4	INT	any integer analog values

Q	INT	= value1 if SEL = 0

= value2 if SEL = 1

= value3 if SEL = 2

= value4 if SEL = 3

= 0 for all other values of the selector

Description:

Multiplexer with 4 entries: selects a value between 4 integer values.

(* FBD program using "MUX4" block *)

(* ST Equivalence: *)

range := MUX4 (choice, 1, 10, 100, 1000);

(* select from 4 predefined ranges, for example, if choice is 1, range will be 10 *)

(* IL Equivalence: *)

LD	choice

MUX4	1,10,100,1000

ST	range


MUX8

Arguments:

SEL	INT	selector integer value (must be in set [0..7])

IN1..IN8	INT	any integer analog values

Q	INT	= value1 if selector = 0

= value2 if selector = 1

...

= value8 if selector = 7

= 0 for all other values of the selector

Description:

Multiplexer with 8 entries: selects a value between 8 integer values.

(* FBD program using "MUX8" block *)

(* ST Equivalence: *)

range := MUX8 (choice, 1, 5, 10, 50, 100, 500, 1000, 5000);

(* select from 8 predefined ranges, for example, if choice is 3, range will be 50 *)

(* IL Equivalence: *)

LD	choice

MUX8	1,5,10,50,100,500,1000,5000

ST	range


ODD

Arguments:

IN	INT	any signed integer analog value

Q	BOO	TRUE if input value is odd

FALSE if input value is even

Description:

Tests the parity of an integer: result is odd or even.

(* FBD program using "ODD" block *)

(* ST Equivalence: *)

If Not (ODD (value)) Then Return; End_if;

value := value + 1;

(* makes value always even *)

(* IL Equivalence: *)

LD	value

ODD

RETNC

LD	value

ADD	1

ST	value


RAND

Arguments:

base	INT	defines the allowed set of number

Q	INT	random value in set [0..base-1]

Description:

Gives a random integer value in a given range.

(* FBD program using "RAND" block *)

(* ST Equivalence: *)

selected := MUX4 ( RAND (4), 1, 4, 8, 16 );

(*

random selection of 1 of 4 pre-defined values

the value issued of RAND call is in set [0..3],

so 'selected' issued from MUX4, will get 'randomly' the value

1 if 0 is issued from RAND,

or 4 if 1 is issued from RAND,

or 8 if 2 is issued from RAND,

or 16 if 3 is issued from RAND,

*)

(* IL Equivalence: *)

LD	4

RAND

MUX4	1,4,8,16

ST	selected


SEL

Arguments:

SEL	BOO	indicates the chosen value

IN1, IN2	INT	any integer analog values

Q	INT	= value1 if SEL is FALSE

= value2 if SEL is TRUE

Description:

Binary selector: selects a value between 2 integer values.

(* FBD program using "SEL" block *)

(* ST Equivalence: *)

ProCmd := SEL (AutoMode, ManuCmd, InpCmd);

(* process command selection *)

(* IL Equivalence: *)

LD	AutoMode

SEL	ManuCmd,InpCmd

ST	ProCmd


ASCII

Arguments:

IN	MSG	any non-empty string

Pos	INT	position of the selected character

in set [1.. len] (len is the length of the IN message)

Code	INT	code of the selected character

(in set [0 .. 255])

returns 0 is Pos is out of the string

Description:

Gives the ASCII code of one character in a message string.

(* FBD program using "ASCII" block *)

(* ST Equivalence: *)

FirstChr := ASCII (message, 1);

(* FirstChr is the Ascii code of the first character of the string *)

(* IL Equivalence: *)

LD	message

ASCII	1

ST	FirstChr


CHAR

Arguments:

Code	INT	code in set [0 .. 255]

Q	MSG	one character string

the character has the ASCII code given in input Code

(ASCII code is used modulo 256)

Description:

Gives a one character message string from a given ASCII code.

(* FBD program using "CHAR" block *)

(* ST Equivalence: *)

Display := CHAR ( value + 48 );

(* value is in set [0..9] *)

(* 48 is the ascii code of '0' *)

(* result is one character string from '0' to '9' *)

(* IL Equivalence: *)

LD	value

ADD	48

CHAR

ST	Display


DELETE

Arguments:

IN	MSG	any non-empty message

NbC	INT	number of characters to be deleted

Pos	INT	position of the first deleted character

(first character of the string has position 1)

Q	MSG	modified string

empty string if Pos < 1

initial string if Pos > IN string length

initial string if NbC <= 0

Description:

Deletes a part of a message string.

(* FBD program using "DELETE" block *)

(* ST Equivalence: *)

complete_string := 'ABCD' + 'EFGH'; (* complete_string is 'ABCDEFGH' *)

sub_string := DELETE (complete_string, 4, 3); (* sub_string is 'ABGH' *)

(* IL Equivalence: *)

LD	'ABCD'

ADD	'EFGH'

ST	complete_string

DELETE	4,3

ST 	sub_string


INSERT

Arguments:

IN	MSG	initial string

Str	MSG	string to be inserted

Pos	INT	position of the insertion

the insertion is done before the position

(first valid position is 1)

Q	MSG	modified string

empty string if Pos <= 0

concatenation of both strings if Pos is greater than the length of the IN string

Description:

Inserts a sub-string in a message string at a given position.

(* FBD program using "INSERT" block *)

(* ST Equivalence: *)

MyName := INSERT ('Mr JONES', 'Frank ', 4);

(* MyName is 'Mr Frank JONES' *)

(* IL Equivalence: *)

LD	'Mr JONES'

INSERT	'Frank ',4

ST 	MyName


FIND

Arguments:

In	MSG	any message string

Pat	MSG	any non-empty string (Pattern)

Pos	INT	= 0 if sub string Pat not found

= position of the first character of the first occurrence of the sub-string Pat

(first position is 1)

this function is case sensitive

Description:

Finds a sub-string in a message string. Gives the position in the string of the sub-string.

(* FBD program using "FIND" block *)

(* ST Equivalence: *)

complete_string := 'ABCD' + 'EFGH'; (* complete_string is 'ABCDEFGH' *)

found := FIND (complete_string, 'CDEF'); (* found is 3 *)

(* IL Equivalence: *)

LD	'ABCD'

ADD	'EFGH'

ST	complete_string

FIND	'CDEF'

ST 	found


MLEN

Arguments:

IN	MSG	any string message

NbC	INT	number of characters in the IN string

Description:

Calculates the length of a message string.

(* FBD program using "MLEN" block *)

(* ST Equivalence: *)

nbchar := MLEN (complete_string);

If (nbchar < 3) Then Return; End_if;

prefix := LEFT (complete_string, 3);

(* this program extracts the 3 characters on the left of the string and put the result in the prefix message variable

nothing is done if the string length is less than 3 characters *)

(* IL Equivalence: *)

LD	complete_string

MLEN

ST	nbchar

LT	3

RETC

LD	complete_string

LEFT	3

ST	prefix


LEFT

Arguments:

IN	MSG	any non-empty string

NbC	INT	Number of characters to be extracted

cannot be greater than the length of the IN string

Q	MSG	left part of the IN string (its length = NbC)

empty string if NbC <= 0

complete IN string if NbC >= IN string length

Description:

Extracts the left part of a message string. The number of characters to be extracted is given.

(* FBD program using "LEFT" and "RIGHT" blocks *)

(* ST Equivalence: *)

complete_string := RIGHT ('12345678', 4) + LEFT ('12345678', 4);

(* complete_string is '56781234'

the value issued from RIGHT call is '5678'

the value issued from LEFT call is '1234'

*)

(* IL Equivalence: First done is call to LEFT *)

LD	'12345678'

LEFT	4

ST	sub_string 	(* intermediate result *)

LD	'12345678'

RIGHT	4

ADD	sub_string

ST 	complete_string


MID

Arguments:

IN	MSG	any non-empty string

NbC	INT	number of characters to be extracted

cannot be greater than the length of the IN string

Pos	INT	position of the sub-string

the sub-string first character will be the one pointed to by Pos

(first valid position is 1)

Q	MSG	middle part of the string (its length = NbC)

empty string if parameters are not valid

Description:

Extracts a part of a message string. The number of characters to be extracted and the position of the first character are given.

(* FBD program using "MID" block *)

(* ST Equivalence: *)

sub_string := MID ('abcdefgh', 2, 4);

(* sub_string is 'de' *)

(* IL Equivalence: *)

LD	'abcdefgh'

MID	2,4

ST	sub_string


REPLACE

Arguments:

IN	MSG	any string

Str	MSG	string to be inserted (to replace NbC chars)

NbC	INT	number of characters to be deleted

Pos	INT	position of the first modified character

(first valid position is 1)

Q	MSG	modified string:

- NbC characters are deleted at position Pos

- then substring Str is inserted at this position

returns empty string if Pos <= 0

returns strings concatenation (IN+Str) if Pos is greater than the length of the IN string

returns initial string IN if NbC <= 0

Description:

Replaces a part of a message string by a new set of characters.

(* FBD program using "REPLACE" block *)

(* ST Equivalence: *)

MyName := REPLACE ('Mr X JONES, 'Frank', 1, 4);

(* MyName is 'Mr Frank JONES' *)

(* IL Equivalence: *)

LD	'Mr X JONES'

REPLACE	'Frank',1,4

ST	MyName


RIGHT

Arguments:

IN	MSG	any non-empty string

NbC	INT	cannot be greater than the length of the IN string

Q	MSG	right part of the string (length = NbC)

empty string if NbC <= 0

complete string if NbC >= string length

Description:

Extracts the right part of a message string. The number of characters to be extracted is given.

(* FBD program using "LEFT" and "RIGHT" blocks *)

(* ST Equivalence: *)

complete_string := RIGHT ('12345678', 4) + LEFT ('12345678', 4);

(* complete_string is '56781234'

the value issued from RIGHT call is '5678'

the value issued from LEFT call is '1234'

*)

(* IL Equivalence: First done is call to LEFT *)

LD	'12345678'

LEFT	4

ST	sub_string 	(* intermediate result *)

LD	'12345678'

RIGHT	4

ADD	sub_string

ST 	complete_string


DAY_TIME

Arguments:

SEL	INT	output selection

0= get current date

1= get current time

2= get day of week

Q	MSG	time/date expressed on a character string

'YYYY/MM/DD' if SEL = 0

'HH:MM:SS' if SEL = 1

day name if SEL = 2 (ex: 'Monday')

Description:

Gives date or time of the day as a message string.

(* FBD program using "DAY_TIME" block *)

(* ST Equivalence: *)

Display := Day_Time (0) + ' ; ' + Day_Time (1);

(* Display text format is: 'YYYY/MM/DD ; HH:MM:SS' *)

(* IL Equivalence: First done is call to day_time(1) *)

LD	1

DAY_TIME

ST	hour_str 	(* intermediate result *)

LD	0

DAY_TIME

ADD	' ; '

ADD	hour_str

ST 	Display


ARCREATE

Arguments:

ID	INT	identifier of the array (must be in set [0..15])

Size	INT	number of elements in the array

ok	INT	execution status :

1 = if array has been successfully created

2 = invalid array identifier or array already created

3 = invalid size

4 = not enough memory

Description:

Creation of an array of integers.

Warning: There are at most 16 arrays in an application. Arrays contain integer analog values. As dynamic memory allocation is performed, this function may cause a system error if the array size is too close to the size of the available memory.

(* FBD program creating an array of integers *)

(* ST Equivalence: *)

array_error := (ARCREATE (ident, 16) <> 1));

(* IL Equivalence: *)

LD	ident

ARCREATE	16

NE 	1

ST	array_error


ARREAD

Arguments:

ID	INT	identifier of the array (must be in set [0..15])

Pos	INT	position of the element in the array

must be in set [0 .. size-1]

value	INT	value of the element read

0 if the arguments are not valid

Description:

Reads an element in an array of integers.

(* FBD program using array management blocks *)

(* ST Equivalence: *)

If (array_error) Then Return; End_if;

read_value := ARREAD (ident, index);

(* array_error comes from the ARCREATE call *)

(* IL Equivalence: *)

LD	array_error

RETC

LD	ident

ARREAD	index

ST	read_value


ARWRITE

Arguments:

ID	INT	identifier of the array (must be in set [0..15])

Pos	INT	position of the element in the array

must be in set [0 .. size-1]

IN	INT	new value for the element

ok	INT	execution status

1 = writing has succeeded

2 = invalid array identifier

3 = invalid index

Description:

Stores (writes) a value in an array of integers.

(* FBD program using array management blocks *)

(* ST Equivalence: *)

If (array_error) Then Return; End_if;

write_status := ARWRITE (Ident, Index, value);

(* array_error comes from the ARCREATE call *)

(* IL Equivalence: *)

LD	array_error

RETC

LD	ident

ARWRITE	index,value

ST	write_status


F_ROPEN

Arguments:

Path	MSG	file name

It may include the access path to the file using the \ or / symbol to specify a directory. To ease application portability, / or \ is equivalent.

ID	INT	file number

0 if an error occurs: file does not exists.

Description:

Opens a binary file in read mode. To be used with FX_READ and F_CLOSE.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_ROPEN('c:\data \data.bin');

error := (file_id=0);

(* IL Equivalence: *)

LD	'c:\data\data.bin'

F_ROPEN

ST	file_id

EQ	0

ST	error


F_WOPEN

Arguments:

Path	MSG	file name

It may include the access path to the file using the \ or / symbol to specify a directory. To ease application portability, / or \ is equivalent.

ID	INT	file number

0 if an error occurs. If the file already exists, it is overwritten.

Description:

Opens a binary file in write mode. To be used with FX_WRITE and F_CLOSE.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_WOPEN('c:\data \data.bin');

error := (file_id=0);

(* IL Equivalence: *)

LD	'c:\data\data.bin'

F_WOPEN

ST	file_id

EQ	0

ST	error


F_CLOSE

Arguments:

ID	INT	file number: returned by F_ROPEN or F_WOPEN.

ok	BOO	return status

TRUE  if file close is OK

FALSE if an error occurred

Description:

Closes a binary file open with functions F_ROPEN or F_WOPEN.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_ROPEN('data.bin');

ok := F_CLOSE(file_id);

(* IL Equivalence: *)

LD	'data.bin'

F_ROPEN

ST	file_id

F_CLOSE	(* file_id is already in the current IL result *)

ST 	ok


F_EOF

Arguments:

ID	INT	file number: returned by F_ROPEN or F_WOPEN.

ok	BOO	end of file indicator

TRUE  if end of file has been reached at the last read or write procedure call.

With FM_READ, the last message read from a file may not be correct, if the last character is not a string terminator.

Description:

Tests if end of file has been reached.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_ROPEN('data.bin');

WHILE not(F_EOF(file_id))

VAL := FA_READ(file_id);

END_WHILE;

MESSAGE := 'last val = ' + msg(VAL);

ok := F_CLOSE(file_id);

(* IL Equivalence: *)

LD	'data.bin'

F_ROPEN

ST	file_id

LD 	file_id

F_EOF

JMPC	END_OF_FILE

NOT_EOF:	LD 	file_id

FA_READ

ST	VAL

LD 	file_id

F_EOF

JMPNC	NOT_EOF 	(* if not eof, go on reading *)

END_OF_FILE:	LD	VAL

MSG

ST	val_msg	(* conversion of VAL into a message *)

LD	'last val = '

ADD	val_msg

ST	MESSAGE

LD 	file_id

F_CLOSE

ST	ok


FA_READ

Arguments:

ID	INT	file number: returned by F_ROPEN.

Q	INT	integer analog value read from file

Description:

Reads ANALOG variables from a binary file. To be used with F_ROPEN and F_CLOSE.

This procedure makes a sequential access to the file, from the previous position.

The first call after F_ROPEN reads the first 4 bytes of the file,

each call pushes the reading pointer.

To check if the end of file is reached, use F_EOF.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_ROPEN('voltramp.bin');

vstart := FA_READ(file_id);

vend := FA_READ(file_id);

vinc := FA_READ(file_id);

delta_tim := tmr(FA_READ(file_id));

ok := F_CLOSE(file_id);

(* IL Equivalence: *)

LD	'voltramp.bin'

F_ROPEN

ST	file_id

FA_READ	(* read vstart *)

ST	vstart

LD 	file_id

FA_READ	(* read vend *)

ST	vend

LD 	file_id

FA_READ	(* read vinc *)

ST	vinc

LD 	file_id

FA_READ	(* read delta_tim *)

TMR	(* conversion into a timer *)

ST	delta_tim

LD 	file_id

F_CLOSE

ST	ok


FA_WRITE

Arguments:

ID	INT	file number: returned by F_WOPEN.

IN	INT	integer analog value To be written in the file

OK	BOO	execution status: TRUE if ok

Description:

Writes ANALOG variables to a binary file.

This procedure makes a sequential access to the file, from the previous position.

The first call after F_WOPEN writes the first 4 bytes of the file,

each call pushes the writing pointer.

This function is not included in the ISaGRAF simulator.

(* FBD program *)

(* ST Equivalence: *)

file_id := F_WOPEN('voltramp.bin');

nb_written  := 0;

nb_written := nb_written + ana(FA_WRITE(file_id,vstart));

nb_written := nb_written + ana(FA_WRITE(file_id,vend));

nb_written := nb_written + ana(FA_WRITE(file_id,vinc));

nb_written := nb_written + ana(FA_WRITE(file_id,ana(delta_tim)));

ok := F_CLOSE(file_id);

IF ( nb_written <> 4) THEN

ERROR := ERR_FILE;

END_IF;

(* IL Equivalence: *)

LD	'voltramp.bin'

F_ROPEN

ST	file_id

LD	0

ST	nb_written

LD 	file_id	(* write vstart *)

FA_WRITE	vstart

ANA

ADD	nb_written

ST	nb_written

LD 	file_id	(* write vend *)

FA_WRITE	vend

ANA

ADD	nb_written

ST	nb_written

LD 	file_id	(* write vinc *)

FA_WRITE	vinc

ANA

ADD	nb_written

LD	(* write delta_tim *)

ANA	(* convert it to an integer *)

ST	ana_delta_tim

LD 	file_id

FA_WRITE	ana_delta_tim

ANA

ADD	nb_written

ST	nb_written

F_CLOSE

ST	ok

LD	nb_written

EQ	4

RETC	(* return if equal 4 *)

LD	ERR_FILE	(* else error *)

ST	ERROR


FM_READ

Arguments:

ID	INT	file number: returned by F_ROPEN.

Q	MSG	message value read from file

Description:

Reads MESSAGE variables from a binary file.

To be used with F_ROPEN and F_CLOSE.

This procedure makes a sequential access to the file, from the previous position.

The first call after F_ROPEN reads the first string of the file,

each call pushes the reading pointer.

A string is a terminated by null (0), end of line ('\n') or return ('\r');

To check if the end of file is reached, use F_EOF.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_ROPEN('voltramp.bin');

status1 := FM_READ(file_id);

status2 := FM_READ(file_id);

IF (F_EOF(file_id)) THEN

ERROR := ERR_FILE;

unused_eof_mes := FM_READ(file_id);

END_IF;

ok := F_CLOSE(file_id);

(* IL Equivalence: *)

LD	'voltramp.bin'

F_ROPEN

ST	file_id

FM_READ	(* read status1 *)

ST	status1

LD 	file_id

FM_READ	(* read status2 *)

ST	status2

LD 	file_id

F_EOF

JMPNC	CLOSE_FILE (* if end of file jump not done *)

LD	ERR_FILE

ST	ERROR

LD 	file_id

FM_READ	(* read unused_eof_mes *)

ST	unused_eof_mes

CLOSE_FILE	LD 	file_id

F_CLOSE

ST	ok


FM_WRITE

Arguments:

ID	INT	file number: returned by F_WOPEN.

IN	MSG	message value to be written in the file

ok	BOO	execution status

TRUE if succeeded

Description:

Writes MESSAGE variables to a binary file.

To be used with F_WOPEN and F_CLOSE.

A message is written in the file as a null terminated string.

This procedure makes a sequential access to the file, from the previous position.

The first call after F_WOPEN writes the first string to the file,

each call pushes the writing pointer.

This function is not included in the ISaGRAF simulator.

(* FBD program using file management blocks *)

(* ST Equivalence: *)

file_id := F_WOPEN('trace.txt');

ok := FM_WRITE(file_id,'First message');

ok := FM_WRITE(file_id,'Last message');

ok := F_CLOSE(file_id);

(* IL Equivalence: *)

LD	'trace.txt'

F_WOPEN

ST	file_id

FM_WRITE	'First message'	(* write first msg *)

ST	ok

LD 	file_id

FM_WRITE	'Last message'	(* write second msg *)

ST	ok

LD 	file_id

F_CLOSE

ST	ok


Alphabetical index

-	ARWRITE	F_ROPEN	MSG	SHR
& (AND)	ASCII	F_TRIG	MUX4	SIG_GEN
*	ASIN	F_WOPEN	MUX8	SIN
/	ATAN	FA_READ	Neg	SQRT
+	AVERAGE	FA_WRITE	NOT_MASK	SR
<	BLINK	FIND	ODD	STACKINT
<=	BOO	FM_READ	OPERATE	SYSTEM
<>	CAT	FM_WRITE	OR_MASK	TAN
=	CHAR	HYSTER	POW	TMR
=1 (XOR)	CMP	INSERT	R_TRIG	TOF
>	COS	INTEGRAL	RAND	TON
>=	CTD	LEFT	REAL	TP
>=1 (OR)	CTU	LIM_ALRM	REPLACE	TRUNC
1 gain	CTUD	LIMIT	RIGHT	XOR_MASK
ABS	DAY_TIME	LOG	ROL
ACOS	DELETE	MAX	ROR
ANA	DERIVATE	MID	RS
AND_MASK	EXPT	MIN	SEL
ARCREATE	F_CLOSE	MLEN	SEMA
ARREAD	F_EOF	MOD	SHL


 FC language

Flow Chart (FC) is a graphic language used to describe sequential operations. A Flow Chart diagram is composed of Actions and Tests. Between Actions and tests are oriented links representing data flow. Actions and Tests can be described with ST, LD or IL languages. Functions and Function blocks of any language (except SFC) can be called from actions and tests.A Flow Chart program can call another Flow Chart program. The called FC program is a sub-program of the calling FC program.

FC Basic components

FC complex structures examples

FC dynamic behavior

FC checking


FC components

Below are graphic components of the Flow Chart language:

Beginning of FC chart

Ending of FC chart

FC flow links

FC actions

FC conditions

FC sub-program

FC I/O specific action

FC connectors

FC comments


Beginning of FC chart

A "begin" symbol must appear at the beginning of a Flow Chart program. It is unique and cannot be omitted. It represents the initial state of the chart when it is activated. Below is the drawing of a "begin" symbol:

The "Begin" symbol always has a connection (on the bottom) to the other objects of the chart. A flow chart is not valid if no connection is drawn from "Begin" to another object.


Ending of FC chart

An "end" symbol must appear at the end of a Flow Chart program. It is unique and cannot be omitted. It is possible that no connection is drawn to the "End" symbol (always looping chart), but "End" symbol is still drawn anyway at the bottom of the chart. It represents the final state of the chart, when its execution has been completed. Below is the drawing of an "end" symbol:

The "End" symbol generally has a connection (on the top) to the other objects of the chart. A flow chart may have no connection to the "End" object (always looping chart). The "End" object is still visible at the bottom of the chart in this case.


FC flow links

A flow link is a line that represents a flow between two points of the diagram. A link is always terminated by an arrow. Below is the drawing of a flow link:

Two links cannot be connected to the same source connection point.


FC actions

An action symbol represents actions to be performed. An action is identified by a number and a name. Below is the drawing of an "action" symbol:

Two different objects of the same chart cannot have the same name or logical number. Programming language for an action can be ST, LD or IL. An action is always connected with links, one arriving to it, one starting from it.


FC conditions

A condition represents a boolean test. A condition is identified by a number and a name. According to the evaluation of attached ST, LD or IL expression, the flow is directed to "YES" or "NO" path. Below are the possible drawings for a condition symbol:

Two different objects of the same chart cannot have the same name or logical number. The programming of a test is either

- an expression in ST, or

- a single rung in LD, with no symbol attached to the unique coil, or

- several instructions in IL. The IL register (or current result) is used to evaluate the condition.

When programmed in ST text, the expression may optionally be followed by a semi-colon. When programmed in LD, the unique coil represents the condition value. A condition equal to:

- 0 or FALSE directs the flow to NO

- 1 or TRUE directs the flow to YES

A test is always connected with an arriving link, and both forward connections must be defined.


FC sub-program

The system enables the description of the vertical structure of FC programs. FC programs are organized in a hierarchy tree. Each FC program can call other FC programs. Such a program is called a child program of the FC program which calls them. FC programs which call FC sub-programs are called father program. FC programs are linked together into a main hierarchy tree, using a "father - child" relation:

A sub-program symbol in a Flow Chart represents a call to a Flow Chart sub-program. Execution of the calling FC program is suspended till the sub-program execution is complete. A Flow Chart sub-program is identified by a number and a name, as other programs, functions or function blocks. Below is the drawing of a "sub-program call" symbol:

Two different objects of the same chart cannot have the same logical number. The basic rules implied by the FC hierarchy structure are:

- FC programs which have no father are called main FC programs.

- Main FC programs are activated by the system when the application starts

- A program can have several child programs

- A child of a program cannot have more than one father

- A child program can be called only by its father

- A program cannot call the children of one of its own children

The same sub-program may appear several times in the father chart. A Flow Chart sub-program call represents the complete execution of the sub chart. The father chart execution is suspended during the child chart is performed. The sub-program calling blocks must follow the same connection rules as the ones defined for action.


FC I/O specific action

An I/O specific action symbol represents actions to be performed. As other actions, an I/O specific action is identified by a number and a name. The same semantic is used on standard actions and I/O specific actions. The aim of I/O specific actions is only to make the chart more readable and to give focus on non-portable parts of the chart. Using I/O specific actions is an optional feature. Below is the drawing of an "I/O specific action" symbol:

I/O specific blocks have exactly the same behavior as standard actions. This covers their properties, ST, LD or IL programming, and connection rules.


FC connectors

Connectors are used to represent a link between two points of the diagram without drawing it. A connector is represented as a circle and is connected to the source of the flow. The drawing of the connector is completed, on the appropriate side (depending on the direction of the data flow), by the identification of the target point (generally the name of the target symbol). Below is the standard drawing of a connector:

A connector always targets a defined Flow Chart symbol. The destination symbol is identified by its logical number.


FC comments

A comment block contains text that has no sense for the semantic of the chart. It can be inserted anywhere on an unused space of the Flow Chart document window, and is used to document the program. Below is the drawing of a "comment" symbol:


FC complex structures examples

This section shows complex structure examples that can be defined in a Flow Chart diagram. Such structures are combinations of basic objects linked together.

	IF / THEN / ELSE (1) place for "THEN" actions to be inserted (2) place for "ELSE" actions to be inserted
	REPEAT / UNTIL (3) place for repeated actions to be inserted
	WHILE / DO (4) place for repeated actions to be inserted


FC dynamic behavior

The execution of a Flow Chart diagram can be explained as follows:

- The Begin symbol takes one target cycle

- The End symbol takes one target cycle and ends the execution of the chart. After this symbol is reached, no action of the chart is executed anymore.

- The flow is broken each time an item (action, decision) is encountered that has already been reached in the same target cycle. In such a case the flow will continue on the next cycle.

Note: Contrary to SFC, an action is not a stable state. There is no repetition of instructions while the action symbol is highlighted.


FC checking

Apart of attached ST, LD or IL programming, some other syntactic rules apply to flow chart itself. Below is the list of main rules:

- All "connection" points of all symbols must be wired. (connection to "End" symbol may be omitted)

- All symbols must be linked together (no isolated part should appear)

- All connectors should have valid destination

Other minor syntax errors can be reported:

- Empty actions (no programming) are considered as steps during run time scheduling

- Empty tests (no programming) are considered as "always true"