Sie sind auf Seite 1von 435

INGESYS IC

Soft Reference.

User Manual.
IC6451IKH05 Rev.C1
Table of contents

Table of contents................................................................................................................ 2

1 Function Libraries of the INGESYS IC3 System ............................................... 7

1.1 Communications_01 .................................................................................................................................... 7


1.1.1 Functions ............................................................................................................................................... 7
1.1.1.1 ExtendedEthernetC30 ................................................................................................................. 7
1.1.1.2 ExtendedSerialC30 .................................................................................................................... 16
1.1.1.3 ICRemoteSerialComs ................................................................................................................ 24
1.1.1.4 SerialC30 ...................................................................................................................................... 31
1.1.1.5 SerialVMP..................................................................................................................................... 39
1.2 Communications_02 .................................................................................................................................. 43
1.2.1 Functions ............................................................................................................................................. 44
1.2.1.1 BRCV............................................................................................................................................. 44
1.2.1.2 BSEND .......................................................................................................................................... 57
1.2.1.3 CONNECT .................................................................................................................................... 70
1.2.1.4 ETHERNET_SEND_RCV........................................................................................................... 85
1.3 CPU_01 ......................................................................................................................................................... 92
1.3.1 Functions ............................................................................................................................................. 92
1.3.1.1 PLC_DIAGNOSTIC ..................................................................................................................... 92
1.3.1.2 PLC_TIME .................................................................................................................................... 98
1.3.1.3 READ_TASK_TIME ..................................................................................................................101
1.3.1.4 WRITE_CONFIGURATION .....................................................................................................101
1.3.1.5 WRITE_CONFIGURATIONv1 .................................................................................................104
1.3.1.6 WRITE_LOG ..............................................................................................................................108
1.4 DataLogger_02 ..........................................................................................................................................110
1.4.1 Functions ...........................................................................................................................................110
1.4.1.1 DIR_CREATE.............................................................................................................................110
1.4.1.2 DIR_REMOVE............................................................................................................................113
1.4.1.3 DIR_RENAME............................................................................................................................115
1.4.1.4 DIR_SCAN..................................................................................................................................117
1.4.1.5 FILE_CREATE ...........................................................................................................................120
1.4.1.6 FILE_DELETE............................................................................................................................124

Ingeteam Power Technology, S.A. 2015 All rights reserved. Rev. C1


1.4.1.7 FILE_READ ................................................................................................................................126
1.4.1.8 FILE_RENAME ..........................................................................................................................130
1.4.1.9 FILE_SET_POINTER................................................................................................................132
1.4.1.10 FILE_WRITE ............................................................................................................................138
1.4.1.11 LIST_CREATE.........................................................................................................................142
1.4.1.12 LIST_GET .................................................................................................................................146
1.4.1.13 LIST_INSERT...........................................................................................................................153
1.4.1.14 LIST_REMOVE........................................................................................................................160
1.5 IEC61131-3_01 ...........................................................................................................................................165
1.5.1 Functions ...........................................................................................................................................165
1.5.1.1 BCD_TO_INT .............................................................................................................................165
1.5.1.2 BLINK ..........................................................................................................................................166
1.5.1.3 DERIVATIVE ..............................................................................................................................168
1.5.1.4 HYSTERESIS .............................................................................................................................170
1.5.1.5 INTEGRAL..................................................................................................................................172
1.5.1.6 INT_TO_BCD .............................................................................................................................175
1.5.1.7 PID ...............................................................................................................................................176
1.6 IEC61131-3_02 ...........................................................................................................................................179
1.6.1 Functions ...........................................................................................................................................179
1.6.1.1 CTD..............................................................................................................................................179
1.6.1.2 CTU..............................................................................................................................................182
1.6.1.3 CTUD ...........................................................................................................................................185
1.6.1.4 F_TRIG ........................................................................................................................................190
1.6.1.5 RS ................................................................................................................................................191
1.6.1.6 RTC..............................................................................................................................................193
1.6.1.7 R_TRIG .......................................................................................................................................195
1.6.1.8 SR ................................................................................................................................................197
1.6.1.9 TOF ..............................................................................................................................................199
1.6.1.10 TON ...........................................................................................................................................201
1.6.1.11 TP...............................................................................................................................................203
1.7 Regulation_01............................................................................................................................................205
1.7.1 Functions ...........................................................................................................................................206
1.7.1.1 BLINK_SIGNAL.........................................................................................................................206
1.7.1.2 COUNTER_DOWN ...................................................................................................................207
1.7.1.3 COUNTER_UP ..........................................................................................................................209
1.7.1.4 COUNTER_UP_DOWN............................................................................................................211
1.7.1.5 DELAY_COUNTER...................................................................................................................214
1.7.1.6 DERIVATIVE_R .........................................................................................................................218
1.7.1.7 FALLING_TRIG .........................................................................................................................221

Ingeteam Power Technology, S.A. 2015 All rights reserved. Rev. C1


1.7.1.8 FREQUENCY_MEASURE .......................................................................................................222
1.7.1.9 GENERATION ...........................................................................................................................225
1.7.1.10 HYSTERESIS_REG ................................................................................................................228
1.7.1.11 INTEGRAL_R ..........................................................................................................................230
1.7.1.12 LIMIT_ALARM_REG ..............................................................................................................232
1.7.1.13 LINEAR_TRAFO_R ................................................................................................................235
1.7.1.14 PD_REG ...................................................................................................................................237
1.7.1.15 PERIOD_COUNTER...............................................................................................................240
1.7.1.16 PID_FIXCYCLE_REG.............................................................................................................244
1.7.1.17 PID_REG ..................................................................................................................................248
1.7.1.18 POSITION_COUNTER ...........................................................................................................251
1.7.1.19 RAMP_I .....................................................................................................................................258
1.7.1.20 RAMP_R ...................................................................................................................................261
1.7.1.21 READ_SSI_COUNTER ..........................................................................................................263
1.7.1.22 RISING_TRIG...........................................................................................................................267
1.7.1.23 RTC_TIMER .............................................................................................................................269
1.7.1.24 SPEED_COUNTER ................................................................................................................271
1.7.1.25 STATISTICS_I .........................................................................................................................275
1.7.1.26 STATISTICS_R........................................................................................................................277
1.7.1.27 TIMER_PULSE ........................................................................................................................279
1.7.1.28 TOF_ABSOLUTE....................................................................................................................281
1.7.1.29 TON_ABSOLUTE ...................................................................................................................284
1.7.1.30 VARIANCE_R ..........................................................................................................................286
1.8 Regulation_02............................................................................................................................................288
1.8.1 Functions ...........................................................................................................................................289
1.8.1.1 ASTAB_OFFON_ASYNC_DISC ............................................................................................289
1.8.1.2 ASTAB_OFFON_SYNC_DISC ...............................................................................................291
1.8.1.3 ASTAB_ONOFF_ASYNC_DISC ............................................................................................293
1.8.1.4 ASTAB_ONOFF_SYNC_DISC ...............................................................................................295
1.8.1.5 CHARCURVE_REAL ...............................................................................................................297
1.8.1.6 CONFIGURE_COUNTER ........................................................................................................300
1.8.1.7 COUNTER_DOWN ...................................................................................................................314
1.8.1.8 COUNTER_UP ..........................................................................................................................316
1.8.1.9 COUNTER_UP_DOWN............................................................................................................319
1.8.1.10 FALLING_TRIG .......................................................................................................................323
1.8.1.11 FILTER ......................................................................................................................................325
1.8.1.12 PULSE.......................................................................................................................................327
1.8.1.13 READ_COUNTER...................................................................................................................330
1.8.1.14 REARM_PULSE......................................................................................................................344

Ingeteam Power Technology, S.A. 2015 All rights reserved. Rev. C1


1.8.1.15 RISING_TRIG...........................................................................................................................346
1.8.1.16 RTC_TIMER .............................................................................................................................348
1.8.1.17 SP_GEN_REG_EMF_V .........................................................................................................350
1.8.1.18 SPEED_REGULATOR ...........................................................................................................352
1.8.1.19 TIMER_PULSE ........................................................................................................................355
1.8.1.20 TOF_ABSOLUTE....................................................................................................................357
1.8.1.21 TOF_RELATIVE ......................................................................................................................359
1.8.1.22 TON_ABSOLUTE ...................................................................................................................362
1.8.1.23 TON_RELATIVE......................................................................................................................364
1.8.1.24 TONOF_RELATIVE ................................................................................................................366
1.8.1.25 WRITE_COUNTER .................................................................................................................369
1.9 Standard_01 ...............................................................................................................................................388
1.9.1 Functions ...........................................................................................................................................388
1.9.1.1 BCD_BYTE_TO_INT ................................................................................................................388
1.9.1.2 DATE_AND_TOD_TO_stPLCTime .......................................................................................389
1.9.1.3 DT_TO_stPLCTime ..................................................................................................................391
1.9.1.4 EXTRACT_BL............................................................................................................................392
1.9.1.5 INT_TO_BCD_BYTE ................................................................................................................394
1.9.1.6 PACK_BL ...................................................................................................................................395
1.9.1.7 PUTBIT_DW ...............................................................................................................................396
1.9.1.8 RESET_SET ...............................................................................................................................398
1.9.1.9 SET_RESET ...............................................................................................................................400
1.9.1.10 stPLCTime_TO_DATE ..........................................................................................................402
1.9.1.11 stPLCTime_TO_DT ................................................................................................................404
1.9.1.12 stPLCTime_TO_TOD .............................................................................................................406
1.9.1.13 UNPACK_BY ...........................................................................................................................407
1.10 Standard_02 ...........................................................................................................................................409
1.10.1 Functions.......................................................................................................................................410
1.10.1.1 CONCAT_STR.........................................................................................................................410
1.10.1.2 DELETE_STR ..........................................................................................................................411
1.10.1.3 FIND_STR ................................................................................................................................412
1.10.1.4 FORMAT_STR.........................................................................................................................414
1.10.1.5 INSERT_STR ...........................................................................................................................418
1.10.1.6 LEFT_STR................................................................................................................................419
1.10.1.7 LEN_STR..................................................................................................................................420
1.10.1.8 MID_STR ..................................................................................................................................421
1.10.1.9 REPLACE_STR.......................................................................................................................422
1.10.1.10 RESET_SET ..........................................................................................................................424
1.10.1.11 RIGHT_STR ...........................................................................................................................426

Ingeteam Power Technology, S.A. 2015 All rights reserved. Rev. C1


1.10.1.12 SET_RESET ..........................................................................................................................427
1.10.1.13 XOR_BUFFER.......................................................................................................................429
1.11 Appendix I: enComsRet ......................................................................................................................431

Ingeteam Power Technology, S.A. 2015 All rights reserved. Rev. C1


1 Function Libraries of the INGESYS IC3 System

The INGESYS IC3 system is delivered with a powerful package of software libraries for the
development of PLC applications.

These libraries contain a large number of function blocks and functions that make program
development easier. For the sake of simplicity, throughout the description of the libraries the
name of the function will be used to refer to both function blocks and functions.

The functions have a clear parameter structure that is common to most of them. Thus, the
functions have input parameters for configuration and execution, output parameters to obtain
results, function status diagnostics and internal function variables that are user-transparent.

1.1 Communications_01

The following tables sumarize the entities contained in Communications_01:

Name Description
The function block ExtendedEthernetC30 allows to configure and implement a transparent
ExtendedEthernetC30
communication using the extended C30 Protocol.
The function block ExtendedSerialC30 allows to configure and implement a transparent
ExtendedSerialC30
communication using the extended C30 Protocol.
Function for communication with serial remote I/Os. This function is used to perform the cyclical
ICRemoteSerialComs
refresh of the IOs or to send and read the configuration parameters.
The function block SerialC30 allows to configure and implement a transparent communication using
SerialC30
the C30 Protocol.
The function block SerialVMP allows to configure and implement a transparent communication using
SerialVMP
the VMP Protocol.
Tbl. 1.1 Functions, Function Blocks, and Programs.

1.1.1 Functions

1.1.1.1 ExtendedEthernetC30

1.1.1.1.1 Description

The function block ExtendedEthernetC30 allows to configure and implement a transparent


communication using the extended C30 Protocol.

1.1.1.1.2 Syntax

FUNCTION_BLOCK ExtendedEthernetC30

VAR_INPUT

EnableComs_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 7


StationNum_US:USINT;

EnMultiStationRx_BL:BOOL;

NumMessageTx_US:USINT;

TxBuff_ADDR:DWORD;

NumBytesTx_US:USINT;

RxBuff_ADDR:DWORD;

Ip_STR:STRING;

ConnectionPort_I:INT;

ConnectionEstablishment_I:INT;

ConnectionNum_I:INT;

KeepAliveInhibition_I:INT;

END_VAR

VAR_OUTPUT

ConnectOK_BL:BOOL:=FALSE;

ConnectError_BL:BOOL;

TxOK_BL:BOOL;

TxError_BL:BOOL;

RxOK_BL:BOOL;

RxStationNum_US:USINT;

NumMessageRx_US:USINT;

NumBytesRx_US:USINT;

RxError_BL:BOOL;

CommStatus_enComsRet:enComsRet;

END_VAR

VAR_IN_OUT

FlagEnTx_BL:BOOL;

FlagEnRx_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 8


1.1.1.1.3 Input parameters

Input Parameter Name Type Description


Activation of the C30 comunications.
FALSE: The communications are disabled.
EnableComs_BL BOOL TRUE: The communications are enabled.
The serial port configuration is performed only on EnableComs_BL's transition
from FALSE to TRUE.
This parameter indicates the number of station.
StationNum_US USINT
A value of 0xFF means broadcast.
EnMultiStationRx_BL BOOL Enable the mode for communication with several stations.
NumMessageTx_US USINT Number of the message to send.
TxBuff_ADDR DWORD Memory address of the buffer containing the data to transmit.
Number of bytes to send.
NumBytesTx_US USINT
The C30 protocol supports a maximum of 253 bytes of user data per frame.
RxBuff_ADDR DWORD Memory address of the buffer where the received data is stored.
Ip_STR STRING Indicates the IP of the remote device.
ConnectionPort_I INT The remote device port to which the connection will be made.
ConnectionEstablishment_I INT Indicates the function if it has to establish(1) or accept (0) the connection.
ConnectionNum_I INT Shows which connections has to be used.
KeepAliveInhibition_I INT 1= without Keep alive in connection; 0= With KeepAlive.
Tbl. 1.2 Input parameters of function ExtendedEthernetC30.

Ingeteam Proprietary All Rights Reserved Pag. 9


1.1.1.1.4 Output parameters

Output Parameter Name Type Description


FALSE: There is no connection and therefore it is not possible to
communicate.
ConnectOK_BL BOOL
TRUE: A successful connection has been done and it is possible to start
communicating.
Indicates error in the connection:
ConnectError_BL BOOL FALSE: No error has occurred while connecting.
TRUE: An error occurred when trying to connect.
Indicates if the transmission was successful (TRUE).
TxOK_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Indicates if an error occurred during the transmission (TRUE).
TxError_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Indicates if the receiving was successful (TRUE).
RxOK_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
If the communication with several stations is enabled
RxStationNum_US USINT (EnMultiStationRx = TRUE)
then this parameter indicates the station from which the received data came.
NumMessageRx_US USINT Number of the received message.
NumBytesRx_US USINT Indicates the number of bytes of data received.
Indicates if an error occurred during the receiving (TRUE).
RxError_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Communication Status, the values of the enumeration are available in the
CommStatus_enComsRet enComsRet
Communications_02 library.
Tbl. 1.3 Output parameters of function ExtendedEthernetC30.

1.1.1.1.5 Input/Output parameters

Input/Output Parameter Name Type Description


The data transmission is controlled with this input parameter. You must set
FlagEnTx_BL BOOL this parameter to TRUE to perform a data transmission. The function resets
this flag to FALSE when the data transmission is complete.
The data receiving is controlled with this input parameter. You must set this
FlagEnRx_BL BOOL parameter to TRUE to perform a data receiving. The function resets this flag
to FALSE when the data receiving is complete.
Tbl. 1.4 Input/Output parameters of function ExtendedEthernetC30.

1.1.1.1.6 Data Types

1.1.1.1.6.1 enComsRet

( see Appendix I )

Ingeteam Proprietary All Rights Reserved Pag. 10


1.1.1.1.7 Remarks

The input parameter EnableComs_BL enables or disables the execution of the function block. If
EnableComs_BL is FALSE the conenction is closed and there are no communications.
EnableComs_BL must be TRUE to enable the function block.

The function block will try to establish a connection when it detects a rising edge in
EnableComs_BL. If the settings are correct, then ConnectOK_BL is set to TRUE and
ConnectError_BL is reset to FALSE . If an error occurs (ConnectError_BL = TRUE), the error
code is given in CommStatus_enComsRet. Another rising edge must occur to retry the
conenction.

Once the connection has been established, EnableComs_BL must stay TO TRUE, UNTIL a new
configuration OR the closing OF the connection is desired.

The C30 message includes the number OF destination station. Each station filters messages
AND processes only those which destination is such station. However the FUNCTION block
ExtendedEthernetC30 enables a mode OF operation which allows TO read messages
addressed TO other stations. This mode can be enabled setting EnMultiStationRx_BL TO TRUE.
RxStationNum_US indicates the number OF the message's destination station.

The transmission AND reception OF messages is controlled BY FlagEnTx_BL AND


FlagEnRx_BL. Set the corresponding flag TO TRUE TO send OR receive respectively. The
FUNCTION reset its state TO FALSE after the execution, correct OR incorrect.

In the CASE OF transmission, the amount OF data TO transmit must be indicated in


NumBytesTx_US (253 maximum). The location OF the data TO send must be pointed BY
TxBuff_ADDR. The station TO which send the data must also be indicated using the input
parameter StationNum_US.

In the CASE OF the receiving, the number OF bytes received is indicated in the output
parameter NumBytesRx_US. The location where the data received is stored is indicated BY
RxBuff_ADDR. In the CASE OF multi station mode, the output parameter RxStationNum_US
indicates from which station the data come. IF NOT working in multi station mode, the number
OF the station must be indicated in StationNum_US, so that the FUNCTION block filters the
messages AND returns only the ones destinated TO the station.

Check TxOK_BL, TxError_BL, RxOK_BL AND RxError_BL TO know when AND how the
sending/receiving finishes. The FUNCTION block resets these parameters in cycle next after the
completion OF the sending/receiving.

The output parameter CommStatus_enComsRet indicates the status OF the communications AT


any TIME. In CASE OF error provides additional information TO parameters ConnectOK_BL,
ConnectError_BL, TxOK_BL, TxError_BL, RxOK_BL AND RxError_BL.

The format OF the frame in the C30 extended protocol is shown below:

Ingeteam Proprietary All Rights Reserved Pag. 11


Byte1: 68h

Byte2: Length of the message

Byte3: Length of the message

Byte4: 68h

Byte5: Number of station

Byte6: 00h

Byte6+1: User Data1

Byte6+2: User Data2

: :

Byte6+X: UserDataX

Byte6+X+1: Checksum

Byte6+X+2: 16h

The maximum length of the user Data is 253Bytes

1.1.1.1.8 Example

PROGRAM C30ExampleProgram

(* This program first receives data and then sends data *)

VAR CONSTANT

(* Memory buffer size *)

buffer_size : USINT := 253;

END_VAR

VAR

(* ExtendedEthernetC30 FB *)

CommC30: ExtendedEthernetC30;

en : BOOL := TRUE;

(* Rx Tx control flags *)

flag_tx : BOOL;

flag_rx : BOOL;

sending : BOOL;

receiving : BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 12


(* Send and receive data buffers *)

rx_buffer : ARRAY [1..buffer_size] OF BYTE;

tx_buffer : ARRAY [1..buffer_size] OF BYTE;

(* Rising edge detection *)

connected : R_TRIG;

(* Statistical *)

rx_frame_num : DINT;

rx_err_num : DINT;

tx_frame_num : DINT;

tx_err_num : DINT;

END_VAR

(* Calling of the FB *)

CommC30(

EnableComs_BL:= en,

StationNum_US:= 1,

EnMultiStationRx_BL:= FALSE,

NumMessageTx_US := 1,

TxBuff_ADDR:= ADR(tx_buffer),

NumBytesTx_US:= buffer_size,

RxBuff_ADDR:= ADR(rx_buffer),

Ip_STR:= '10.100.1.176',

ConnectionPort_I:= 12345,

ConnectionEstablishment_I:= 1,

ConnectionNum_I:= 0,

KeepAliveInhibition_I:= 1,

FlagEnTx_BL:= flag_tx,

FlagEnRx_BL:= flag_rx,

ConnectOK_BL=> ,

ConnectError_BL=> ,

TxOK_BL=> ,

Ingeteam Proprietary All Rights Reserved Pag. 13


TxError_BL=> ,

RxOK_BL=> ,

RxStationNum_US=> ,

NumMessageRx_US =>,

RxError_BL=> ,

NumBytesRx_US=> ,

CommStatus_enComsRet=> );

(* Detect rising edge => connection established *)

connected(CLK:= CommC30.ConnectOK_BL, Q=> );

(* Start receiving after connection is established *)

IF connected.Q

THEN

receiving := TRUE;

END_IF

IF CommC30.ConnectOK_BL

THEN

(* If Received OK, then Send *)

IF CommC30.RxOK_BL

THEN

rx_frame_num := rx_frame_num + 1;

sending := TRUE;

END_IF

(* If Receive error, then retry *)

IF CommC30.RxError_BL

THEN

rx_err_num := rx_err_num + 1;

receiving := TRUE;

END_IF

(* If Sent OK, then receive *)

IF CommC30.TxOK_BL

Ingeteam Proprietary All Rights Reserved Pag. 14


THEN

tx_frame_num := tx_frame_num + 1;

receiving := TRUE;

END_IF

(* If Send error, then retry *)

IF CommC30.TxError_BL

THEN

tx_err_num := tx_err_num + 1;

sending := TRUE;

END_IF

END_IF

(* Set the flag for Sending *)

IF sending

THEN

flag_tx := TRUE;

END_IF

(* Set the flag for Receiving *)

IF receiving

THEN

flag_rx := TRUE;

END_IF

Ingeteam Proprietary All Rights Reserved Pag. 15


1.1.1.2 ExtendedSerialC30

1.1.1.2.1 Description

The function block ExtendedSerialC30 allows to configure and implement a transparent


communication using the extended C30 Protocol.

1.1.1.2.2 Syntax

FUNCTION_BLOCK ExtendedSerialC30

VAR_INPUT

EnableComs_BL:BOOL;

StationNum_US:USINT;

EnMultiStationRx_BL:BOOL;

NumMessageTx_US:USINT;

TxBuff_ADDR:DWORD;

NumBytesTx_US:USINT;

RxBuff_ADDR:DWORD;

RxTimeout_T:TIME;

SerialParam_stSerialPortParam:stSerialPortParam;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

ComPort_DI:DINT;

END_VAR

VAR_OUTPUT

ConnectOK_BL:BOOL:=FALSE;

ConnectError_BL:BOOL;

TxOK_BL:BOOL;

TxError_BL:BOOL;

RxOK_BL:BOOL;

RxStationNum_US:USINT;

NumMessageRx_US:USINT;

Ingeteam Proprietary All Rights Reserved Pag. 16


NumBytesRx_US:USINT;

RxError_BL:BOOL;

CommStatus_enComsRet:enComsRet;

END_VAR

VAR_IN_OUT

FlagEnTx_BL:BOOL;

FlagEnRx_BL:BOOL;

END_VAR

1.1.1.2.3 Input parameters

Input Parameter Name Type Description


Activation of the C30 comunications.
FALSE: The communications are disabled.
EnableComs_BL BOOL TRUE: The communications are enabled.
The serial port configuration is performed only on EnableComs_BL's
transition from FALSE to TRUE.
This parameter indicates the number of station.
StationNum_US USINT
A value of 0xFF means broadcast.
EnMultiStationRx_BL BOOL Enable the mode for communication with several stations.
NumMessageTx_US USINT Number of the message to send.
TxBuff_ADDR DWORD Memory address of the buffer containing the data to transmit.
Number of bytes to send.
NumBytesTx_US USINT The C30 protocol supports a maximum of 253 bytes of user data per
frame.
RxBuff_ADDR DWORD Memory address of the buffer where the received data is stored.
RxTimeout_T TIME Timeout for receiving.
SerialParam_stSerialPortParam stSerialPortParam This structure contains fields for the serial port settings.
ChassisNum_DI DINT Number of the chassis where the communications card is installed.
SlotNum_DI DINT Number of the slot where the communications card is installed.
Serial Port Indicates the communications port to use for the
ComPort_DI DINT
connection.
Tbl. 1.5 Input parameters of function ExtendedSerialC30.

Ingeteam Proprietary All Rights Reserved Pag. 17


1.1.1.2.4 Output parameters

Output Parameter Name Type Description


FALSE: There is no connection and therefore it is not possible to
communicate.
ConnectOK_BL BOOL TRUE: A successful connection has been done (opening and configuring the
port) and it is possible to start communicating. This parameter remains TRUE
while EnableComs_BL is TRUE and the port was configured correctly.
Indicates erron in the connection:
FALSE: No error has occurred while connecting.
ConnectError_BL BOOL
TRUE: An error occurred when trying to connect (open and configure the
port).
Indicates if the transmission was successful (TRUE).
TxOK_BL BOOL This flag retains its TRUE value during a cycle. The next function call resets it
to FALSE.
Indicates if an error occurred during the transmission (TRUE). This flag
TxError_BL BOOL retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Indicates if the receiving was successful (TRUE).
RxOK_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
If the communication with several stations is enabled (EnMultiStationRx =
RxStationNum_US USINT TRUE) then this parameter indicates the station from which the received data
came.
NumMessageRx_US USINT Number of the received message.
NumBytesRx_US USINT Indicates the number of bytes of data received.
Indicates if an error occurred during the receiving (TRUE).
RxError_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Communication Status, the values of the enumeration are available in the
CommStatus_enComsRet enComsRet
Communications_02 library.
Tbl. 1.6 Output parameters of function ExtendedSerialC30.

1.1.1.2.5 Input/Output parameters

Input/Output Parameter Name Type Description


The data transmission is controlled with this input parameter. You must set
this parameter to TRUE to perform a data transmission.
FlagEnTx_BL BOOL
The function resets this flag to FALSE when the data transmission is
complete.
The data receiving is controlled with this input parameter.
FlagEnRx_BL BOOL You must set this parameter to TRUE to perform a data receiving.
The function resets this flag to FALSE when the data receiving is complete.
Tbl. 1.7 Input/Output parameters of function ExtendedSerialC30.

Ingeteam Proprietary All Rights Reserved Pag. 18


1.1.1.2.6 Data Types

1.1.1.2.6.1 enComsRet

( see Appendix I )

1.1.1.2.6.2 stSerialPortParam

Field Name Type Description


ChannelType_STR STRING(20) Channel type:. 'RS232'. 'MODEM'. 'RS485FULL'. 'RS485HALF'.
Data transmission speed(Baud):. '110B' = Link speed is 110 bauds. '300B'
= Link speed is 300 bauds. '600B" = Link speed is 600 bauds.
'1200B' = Link speed is 1200 bauds. '2400B' = Link speed is 2400 bauds -
Valid CPU USART-. '4800B' = Link speed is 4800 bauds -Valid CPU
USART-. '9600B' = Link speed is 9600 bauds -Valid CPU USART-.
RxTxSpeed_STR STRING(20)
'19200B' = Link speed is 19200 bauds -Valid CPU USART-. '38400B' =
Link speed is 38400 bauds -Valid CPU USART-. '48000B' = Link speed is
48000 bauds. '64000B' = Link speed is 64000 bauds. '96000B' = Link
speed is 96000 bauds. '192000B' = Link speed is 192000 bauds. '250000B'
= Link speed is 250000 bauds. '500000B' = Link speed is 500000 bauds.
Type of parity to be used:. 'NO PARITY' = No parity. 'ODD' = Odd parity.
Parity_STR STRING(20)
'EVEN' = Even parity.
Number of stop bits.:. 0 = 1 stop bit. 1 = 1+1/2 if CharBitsNum_STR= 5. 1 = 2 if
StopBitNum_DI DINT
CharBitsNum_STR<> 5.
The number of bits per character.:. '5BITS' = 5 bits per char. '6BITS' = 6 bits
CharBitsNum_STR STRING(20)
per char. '7BITS' = 7 bits per charr. '8BITS' = 8 bits per char.
Tbl. 1.8 Fields of the stSerialPortParam structure.

1.1.1.2.7 Remarks

The ExtendedSerialC30 functions provides two aditional parameter compared to SerialC30


function: NumMessageTx_US and NumMessageRx_US. The ExtendedSerialC30 function is
used both for opening and configuring of the serial port, as well as sending and receiving of data.

The input parameter EnableComs_BL enables or disables the execution of the function block. If
EnableComs_BL is FALSE the port is closed and there are no communications.
EnableComs_BL must be TRUE to enable the function block.

The function block opens the port and configures it when it detects a rising edge in
EnableComs_BL. If the settings are correct, then ConnectOK_BL is set to TRUE and
ConnectError_BL is reset to FALSE . If an error occurs (ConnectError_BL = TRUE), the error
code is given in CommStatus_enComsRet. Another rising edge must occur to retry configuring.

Once the port has been successfully opened and configured, EnableComs_BL must stay to
TRUE, until a new configuration or the closing of the port is desired.

The C30 message includes the number of destination station. Each station filters messages and
processes only those which destination is such station. However the function block SerialC30
enables a mode of operation which allows to read messages addressed to other stations. This

Ingeteam Proprietary All Rights Reserved Pag. 19


mode can be enabled setting EnMultiStationRx_BL to TRUE. RxStationNum_US indicates the
number of the message's destination station.

The transmission and reception of messages is controlled by FlagEnTx_BL and FlagEnRx_BL.


Set the corresponding flag to TRUE to send or receive respectively. The function reset its state
to FALSE after the execution, correct or incorrect.

In the case of transmission, the amount of data to transmit must be indicated in NumBytesTx_US
(253 maximum). The location of the data to send must be pointed by TxBuff_ADDR. The station
to which send the data must also be indicated using the input parameter StationNum_US.

In the case of the receiving, the number of bytes received is indicated in the output parameter
NumBytesRx_US. The location where the data received is stored is indicated by RxBuff_ADDR.
In the case of multi station mode, the output parameter RxStationNum_US indicates from which
station the data come. If not working in multi station mode, the number of the station must be
indicated in StationNum_US, so that the function block filters the messages and returns only the
ones destinated to the station.

Check TxOK_BL, TxError_BL, RxOK_BL and RxError_BL to know when and how the
sending/receiving finishes. The function block resets these parameters in cycle next after the
completion of the sending/receiving.

The output parameter CommStatus_enComsRet indicates the status of the communications at


any time. In case of error provides additional information to parameters ConnectOK_BL,
ConnectError_BL, TxOK_BL, TxError_BL, RxOK_BL and RxError_BL.

The format of the frame in the C30 extended protocol is shown below:

Byte1: 68h

Byte2: Length of the message

Byte3: Length of the message

Byte4: 68h

Byte5: Number of station

Byte6: 00h

Byte6+1: User Data1

Byte6+2: User Data2

: :

Byte6+X: UserDataX

Byte6+X+1: Checksum

Byte6+X+2: 16h

The maximum length of the user Data is 253Bytes

Ingeteam Proprietary All Rights Reserved Pag. 20


1.1.1.2.8 Example

PROGRAM C30ExampleProgram

(* This program first receives data and then sends data *)

VAR CONSTANT

(* Memory buffer size *)

buffer_size : USINT := 253;

END_VAR

VAR

(* SerialC30 FB *)

CommC30: ExtendedSerialC30;

en : BOOL := TRUE;

(* RS232 port configuration *)

port_conf : stSerialPortParam := (ChannelType_STR:= 'RS232',

RxTxSpeed_STR:= '38400B',

Parity_STR:= 'EVEN',

StopBitNum_DI := 0,

CharBitsNum_STR:= '8BITS');

(* Rx Tx control flags *)

flag_tx : BOOL;

flag_rx : BOOL;

sending : BOOL;

receiving : BOOL;

(* Send and receive data buffers *)

rx_buffer : ARRAY [1..buffer_size] OF BYTE;

tx_buffer : ARRAY [1..buffer_size] OF BYTE;

(* Rising edge detection *)

connected : R_TRIG;

(* Statistical *)

rx_frame_num : DINT;

rx_err_num : DINT;

Ingeteam Proprietary All Rights Reserved Pag. 21


tx_frame_num : DINT;

tx_err_num : DINT;

END_VAR

(* Calling of the FB *)

CommC30(

EnableComs_BL:= en,

StationNum_US:= 1,

EnMultiStationRx_BL:= FALSE,

NumMessageTx_US := 1,

TxBuff_ADDR:= ADR(tx_buffer),

NumBytesTx_US:= buffer_size,

RxBuff_ADDR:= ADR(rx_buffer),

RxTimeout_T:= t#500ms,

SerialParam_stSerialPortParam:= port_conf,

ChassisNum_DI:= 0,

SlotNum_DI:= 1,

ComPort_DI:= 0,

FlagEnTx_BL:= flag_tx,

FlagEnRx_BL:= flag_rx,

ConnectOK_BL=> ,

ConnectError_BL=> ,

TxOK_BL=> ,

TxError_BL=> ,

RxOK_BL=> ,

RxStationNum_US=> ,

NumMessageRx_US =>,

RxError_BL=> ,

NumBytesRx_US=> ,

CommStatus_enComsRet=> );

(* Detect rising edge => connection established *)

Ingeteam Proprietary All Rights Reserved Pag. 22


connected(CLK:= CommC30.ConnectOK_BL, Q=> );

(* Start receiving after connection is established *)

IF connected.Q

THEN

receiving := TRUE;

END_IF

IF CommC30.ConnectOK_BL

THEN

(* If Received OK, then Send *)

IF CommC30.RxOK_BL

THEN

rx_frame_num := rx_frame_num + 1;

sending := TRUE;

END_IF

(* If Receive error, then retry *)

IF CommC30.RxError_BL

THEN

rx_err_num := rx_err_num + 1;

receiving := TRUE;

END_IF

(* If Sent OK, then receive *)

IF CommC30.TxOK_BL

THEN

tx_frame_num := tx_frame_num + 1;

receiving := TRUE;

END_IF

(* If Send error, then retry *)

IF CommC30.TxError_BL

THEN

tx_err_num := tx_err_num + 1;

Ingeteam Proprietary All Rights Reserved Pag. 23


sending := TRUE;

END_IF

END_IF

(* Set the flag for Sending *)

IF sending

THEN

flag_tx := TRUE;

END_IF

(* Set the flag for Receiving *)

IF receiving

THEN

flag_rx := TRUE;

END_IF

1.1.1.3 ICRemoteSerialComs

1.1.1.3.1 Description

Function for communication with serial remote I/Os. This function is used to perform the cyclical
refresh of the IOs or to send and read the configuration parameters.

1.1.1.3.2 Syntax

FUNCTION_BLOCK ICRemoteSerialComs

VAR_INPUT

EnComs_BL:BOOL;

SlaveAddr_DI:DINT;

ConfSerial_stRIO_ComSerialConf_ADDR:DWORD;

InputData_ADDR:DWORD;

InputDataBufferSizeBy_DI:DINT;

OutputData_ADDR:DWORD;

OutputDataBufferSizeBy_DI:DINT;

Param_ADDR:DWORD;

Ingeteam Proprietary All Rights Reserved Pag. 24


ParamBufferSizeBy_DI:DINT;

END_VAR

VAR_IN_OUT

Action_enRIO_Act:enRIO_Act;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Error_BL:BOOL;

RetSlaveAddr_DI:DINT;

RetAction_enRIO_Act:enRIO_Act;

Status_enComsRet:enComsRet;

END_VAR

1.1.1.3.3 Input parameters

Input Parameter Name Type Description


This variable is used for enabling execution of the function
EnComs_BL BOOL
block.
SlaveAddr_DI DINT Indicates the ID of the requested slave (0 to 7).
Address of the buffer containing the connection
configuration parameters.
ConfSerial_stRIO_ComSerialConf_ADDR DWORD
It has to be a pointer to a stRIOComSerialConf type
structure.
Address of the buffer containing the input data structure
InputData_ADDR DWORD
received from the RIO.
InputDataBufferSizeBy_DI DINT Size in bytes of the Input data buffer.
Address of the buffer containing the output data structure to
OutputData_ADDR DWORD
send to the RIO.
OutputDataBufferSizeBy_DI DINT Size in bytes of the output data buffer.
Address of the buffer containing the structure of
parameters.
With the SEND_PARAMS action, these parameters are
Param_ADDR DWORD
sent to the RIO.
With the READ_PARAMS action, parameters are read from
the RIO and stored in this address.
ParamBufferSizeBy_DI DINT Size in bytes of the parameter buffer.
Tbl. 1.9 Input parameters of function ICRemoteSerialComs.

Ingeteam Proprietary All Rights Reserved Pag. 25


1.1.1.3.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL TRUE if the requested action Action_enRIOAct is done.
TRUE if there has been an error in the execution.
Error_BL BOOL
The error status will be given in the variable Status_enComsRet.
If Done_BL or Error_BL is TRUE.
RetSlaveAddr_DI DINT This parameter indicates the slave ID to which the performed command
was requested.
If Done_BL or Error_BL is TRUE.
RetAction_enRIO_Act enRIO_Act
This parameter indicates the command requested which was performed.
The function returns a code indicating possible errors.
Status_enComsRet enComsRet
See related status in enComsRet data type.
Tbl. 1.10 Output parameters of function ICRemoteSerialComs.

1.1.1.3.5 Input/Output parameters

Input/Output Parameter Name Type Description


Action to be done:
PERFORM_CYCLE: Perform the data read/write cycle
SEND_PARAMS: Send configuration parameters to the RIO.
To perform a parameter sending is necesary set the value of
Action_enRIO_Act enRIO_Act SEND_PARAMS a single cycle and the function will automatically change
the value TO PERFORM_CYCLE after sending.
READ_PARAMS: Read the configuration parameters from the RIO.
To perform a parameter reading is necesary set the value of
READ_PARAMS a single cycle and the function will automatically change
the value to PERFORM_CYCLE after reading.
Tbl. 1.11 Input/Output parameters of function ICRemoteSerialComs.

1.1.1.3.6 Data Types

1.1.1.3.6.1 enRIO_Act

Value Description
PERFORM_CYCLE (0) Perform the data read/write cycle
SEND_PARAMS (1) Send configuration parameters to the IC3401
READ_PARAMS (2)
Tbl. 1.12 Enumerator enRIO_Act.

1.1.1.3.6.2 stRIO_ComSerialConf

Field Name Type Description


ChassisNum_DI DINT Chassis number of the IO module.
SlotNum_DI DINT Slot number of the IO module.
ComPort_DI DINT Port number.
Communications baudrate. Valid values are:.
'192000B' = 192000 bauds
RxTxSpeed_STR STRING(20)
'250000B' = 250000 bauds
'500000B' = 500000 bauds ..
Tbl. 1.13 Fields of the stRIO_ComSerialConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 26


1.1.1.3.6.3 enComsRet

( see Appendix I )

1.1.1.3.6.4 stSSICounterConf

Field Name Type Description


Number of bits from SSI channel. This value has to be between 8 and 32.
EncoderBitNumber_SI SINT
Otherwise, the configuration is incorrect.
The period of encoder clock in microseconds and has to be between 1us and
EncoderClockPeriodUS_SI SINT
31us. If period=0 the configuration is incorrect.
Minimun time between the end of one reading and the beginning of the next
TminBetweenReadingsUS_I INT one in microseconds. this value has to be between 1us and 255us, otherwise
the configuration is incorrect.
Tbl. 1.14 Fields of the stSSICounterConf structure.

1.1.1.3.7 Example

PROGRAM Example_ComsRIO

VAR

ComunicationRIO: ICRemoteSerialComs;(*Function to communicate with the RIO*)

EnComs: BOOL:=TRUE;(*Variable to enable the comunications with the RIO*)

EnReadParams: BOOL;(*Variable to activate the read of parameters*)

EnSendParams: BOOL;(*Variable to activate the send of parameters*)

SlaveAddr: DINT := 2;(*Slave number of RIO*)

ReqAction: enRIO_Act:=SEND_PARAMS;(*Action to be perform*)

(*Serial configuration parameters definition*)

ConfSerial:stRIO_ComSerialConf:=(ChassisNum_DI:=0,(*Chassis number of the


communication module*)

SlotNum_DI:=0,(*Slot number of the communication module*)

ComPort_DI:=0,(*Port number of the communication module*)

RxTxSpeed_STR:='500000B');(*Speed of the communication*)

Params_ADDR: DINT;(*Auxiliar variable for communication with RIO*)

Params_SIZEOF: DINT;(*Auxiliar variable for communication with RIO*)

RIO_Input: stRIO_InputData;(*Buffer of inputs from RIO*)

RIO_Output: stRIO_OutputData;(*Buffer of output to RIO*)

ParamsWrite: stRIO_Param;(*Buffer of parameters to write to the RIO*)

Ingeteam Proprietary All Rights Reserved Pag. 27


ParamsRead: stRIO_Param;(*Buffer of parameters readed from the RIO*)

TimerSendParam: TON_RELATIVE;(*Timer function*)

END_VAR

(*To use these example the user must define following STRUCTS:

TYPE stRIO_InputData:(*Struct of input data from RIO*)

STRUCT

DigitalInput_W: WORD;

Reserved_W: WORD;

AnalogInput_ARR: ARRAY [0..11] OF REAL;

PitchControlCurrent_ARR: ARRAY [0..2] OF REAL;

PitchCylinderPosition_ARR: ARRAY [0..2] OF DWORD;

PT100_ARR: ARRAY [0..3] OF REAL;

PitchAngle_ARR: ARRAY [0..2] OF REAL;

Status_W: WORD;

Diagnostics_ARR: ARRAY [0..3] OF WORD;

END_STRUCT

END_TYPE

TYPE stRIO_OutputData:(*Struct of output data to RIO*)

STRUCT

DigitalOutput_W: WORD;

Reserved_W: WORD;

BladePitchDemand_ARR: ARRAY [0..2] OF REAL;

AnalogOutput_R: REAL;

ServoCurrentDemand_ARR: ARRAY [0..2] OF REAL;

ServoGainCompensation_W: WORD;

ControlWord_W: WORD;

END_STRUCT

END_TYPE

TYPE stRIO_Param: (*Struct of the parameters of RIO*)

STRUCT

Ingeteam Proprietary All Rights Reserved Pag. 28


Version_DW: DWORD;

ServoGainTableX_ARR: ARRAY [0..3] OF REAL;

ServoGainTableY_ARR: ARRAY [0..3] OF REAL;

NullData_ARR: ARRAY [0..2] OF REAL;

MinBitValueOfCilinderLength_ARR: ARRAY [0..2] OF REAL;

MaxBitValueOfCilinderLength_ARR: ARRAY [0..2] OF REAL;

TrunnionRadius_R: REAL;

LengthConstant_R: REAL;

AngleConstant_R: REAL;

MinCylinderLength_R: REAL;

MaxCylinderLength_R: REAL;

Kraw_ARR: ARRAY [0..4] OF REAL;

Kcomp_ARR: ARRAY [0..3] OF REAL;

AOCurrentMax_R: REAL;

AOCurrentMin_R: REAL;

MovingAverageTimes_W: WORD;

TimeoutCycles_W: WORD;

AngleLargeAlarm_R: REAL;

TimeLargeAlarm_R: REAL;

AngleLimitOverAlarm_R: REAL;

TimeAngleLimitAlarm_R: REAL;

UsedAnalogInputs_W: WORD;

UsedAnalogOutputs_W: WORD;

UsedPT100_W: WORD;

AnalogInputConfiguration_W: WORD;

SSIEncodersConfiguration_stSSIEncodersConf: stSSICounterConf;

PT100CableLength_ARR: ARRAY [0..3] OF REAL;

PT100CableCopperSection_ARR: ARRAY [0..3] OF REAL;

END_STRUCT

END_TYPE*)

Ingeteam Proprietary All Rights Reserved Pag. 29


(*Timer of 1 sec to activate the sending of parameters, the timer will give 1 pulse of a single
cycle.*)

TimerSendParam(Input_BL:=EnComs AND RIO_Input.Status_W.1 AND NOT


TimerSendParam.Output_BL ,(*RIO_Input.Status_W.1 is Not parameterized BIT from RIO*)

ActivationDelay_T:= T#1s ,

Output_BL=> ,

Status_DI=> );

(*Activation for sending parameters*)

IF TimerSendParam.Output_BL OR EnSendParams

THEN

ReqAction:=SEND_PARAMS;

Params_ADDR:=ADR(ParamsWrite);

Params_SIZEOF:=SIZEOF(ParamsWrite);

EnSendParams:=FALSE;

END_IF

(*Activation for reading parameters*)

IF EnReadParams

THEN

ReqAction:=READ_PARAMS;

Params_ADDR:=ADR(ParamsRead);

Params_SIZEOF:=SIZEOF(ParamsRead);

EnReadParams:=FALSE;

END_IF

(*Call to function to communicate with the RIO*)

ComunicationRIO(

EnComs_BL:=EnComs ,

SlaveAddr_DI:=SlaveAddr ,

ConfSerial_stRIO_ComSerialConf_ADDR:=ADR(ConfSerial) ,

InputData_ADDR:=ADR(RIO_Input) ,

InputDataBufferSizeBy_DI:=SIZEOF (RIO_Input) ,

Ingeteam Proprietary All Rights Reserved Pag. 30


OutputData_ADDR:=ADR(RIO_Output) ,

OutputDataBufferSizeBy_DI:=SIZEOF(RIO_Output) ,

Param_ADDR:=Params_ADDR ,

ParamBufferSizeBy_DI:=Params_SIZEOF ,

Action_enRIO_Act:=ReqAction ,

Done_BL=> ,

Error_BL=> ,

RetSlaveAddr_DI=> ,

RetAction_enRIO_Act=> ,

Status_enComsRet=> );

1.1.1.4 SerialC30

1.1.1.4.1 Description

The function block SerialC30 allows to configure and implement a transparent communication
using the C30 Protocol.

1.1.1.4.2 Syntax

FUNCTION_BLOCK SerialC30

VAR_INPUT

EnableComs_BL:BOOL;

StationNum_US:USINT;

EnMultiStationRx_BL:BOOL;

TxBuff_ADDR:DWORD;

NumBytesTx_US:USINT;

RxBuff_ADDR:DWORD;

RxTimeout_T:TIME;

SerialParam_stSerialPortParam:stSerialPortParam;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

ComPort_DI:DINT;

Ingeteam Proprietary All Rights Reserved Pag. 31


END_VAR

VAR_OUTPUT

ConnectOK_BL:BOOL:=FALSE;

ConnectError_BL:BOOL;

TxOK_BL:BOOL;

TxError_BL:BOOL;

RxOK_BL:BOOL;

RxStationNum_US:USINT;

RxError_BL:BOOL;

NumBytesRx_US:USINT;

CommStatus_enComsRet:enComsRet;

END_VAR

VAR_IN_OUT

FlagEnTx_BL:BOOL;

FlagEnRx_BL:BOOL;

END_VAR

1.1.1.4.3 Input parameters

Input Parameter Name Type Description


Activation of the C30 comunications.
FALSE: The communications are disabled.
EnableComs_BL BOOL TRUE: The communications are enabled.
The serial port configuration is performed only on
EnableComs_BL's transition from FALSE to TRUE.
This parameter indicates the number of station.
StationNum_US USINT
A value of 0xFF means broadcast.
EnMultiStationRx_BL BOOL Enable the mode for communication with several stations.
TxBuff_ADDR DWORD Memory address of the buffer containing the data to transmit.
Number of bytes to send.
NumBytesTx_US USINT The C30 protocol supports a maximum of 253 bytes of user data
per frame.
RxBuff_ADDR DWORD Memory address of the buffer where the received data is stored.
RxTimeout_T TIME Timeout for receiving.
SerialParam_stSerialPortParam stSerialPortParam This structure contains fields for the serial port settings.
ChassisNum_DI DINT Number of the chassis where the communications card is installed.
SlotNum_DI DINT Number of the slot where the communications card is installed.
Serial Port Indicates the communications port to use for the
ComPort_DI DINT
connection.
Tbl. 1.15 Input parameters of function SerialC30.

Ingeteam Proprietary All Rights Reserved Pag. 32


1.1.1.4.4 Output parameters

Output Parameter Name Type Description


FALSE: There is no connection and therefore it is not possible to
communicate.
TRUE: A successful connection has been done (opening and
ConnectOK_BL BOOL
configuring the port) and it is possible to start communicating.
This parameter remains TRUE while EnableComs_BL is TRUE and
the port was configured correctly.
Indicates erron in the connection:FALSE:No error has occurred
while connecting.
ConnectError_BL BOOL
TRUE: An error occurred when trying to connect (open and
configure the port).
Indicates if the transmission was successful (TRUE).
TxOK_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Indicates if an error occurred during the transmission (TRUE).
TxError_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
Indicates if the receiving was successful (TRUE).
RxOK_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
If the communication with several stations is enabled
RxStationNum_US USINT (EnMultiStationRx = TRUE) then this parameter indicates the
station from which the received data came.
Indicates if an error occurred during the receiving (TRUE).
RxError_BL BOOL This flag retains its TRUE value during a cycle.
The next function call resets it to FALSE.
NumBytesRx_US USINT Indicates the number of bytes of data received.
Communication Status, the values of the enumeration are available
CommStatus_enComsRet enComsRet
in the Communications_02 library.
Tbl. 1.16 Output parameters of function SerialC30.

1.1.1.4.5 Input/Output parameters

Input/Output Parameter Name Type Description


The data transmission is controlled with this input parameter. You
must set this parameter to TRUE to perform a data transmission.
FlagEnTx_BL BOOL
The function resets this flag to FALSE when the data transmission
is complete.
The data receiving is controlled with this input parameter. You must
set this parameter to TRUE to perform a data receiving. The
FlagEnRx_BL BOOL
function resets this flag to FALSE when the data receiving is
complete.
Tbl. 1.17 Input/Output parameters of function SerialC30.

1.1.1.4.6 Data Types

1.1.1.4.6.1 enComsRet

( see Appendix I )

Ingeteam Proprietary All Rights Reserved Pag. 33


1.1.1.4.6.2 stSerialPortParam

Field Name Type Description


ChannelType_STR STRING(20) Channel type:. 'RS232'. 'MODEM'. 'RS485FULL'. 'RS485HALF'.
Data transmission speed(Baud):. '110B' = Link speed is 110 bauds. '300B'
= Link speed is 300 bauds. '600B" = Link speed is 600 bauds.
'1200B' = Link speed is 1200 bauds. '2400B' = Link speed is 2400 bauds -
Valid CPU USART-. '4800B' = Link speed is 4800 bauds -Valid CPU
USART-. '9600B' = Link speed is 9600 bauds -Valid CPU USART-.
RxTxSpeed_STR STRING(20)
'19200B' = Link speed is 19200 bauds -Valid CPU USART-. '38400B' =
Link speed is 38400 bauds -Valid CPU USART-. '48000B' = Link speed is
48000 bauds. '64000B' = Link speed is 64000 bauds. '96000B' = Link
speed is 96000 bauds. '192000B' = Link speed is 192000 bauds. '250000B'
= Link speed is 250000 bauds. '500000B' = Link speed is 500000 bauds.
Type of parity to be used:. 'NO PARITY' = No parity. 'ODD' = Odd parity.
Parity_STR STRING(20)
'EVEN' = Even parity.
Number of stop bits.:. 0 = 1 stop bit. 1 = 1+1/2 if CharBitsNum_STR= 5. 1 = 2 if
StopBitNum_DI DINT
CharBitsNum_STR<> 5.
The number of bits per character.:. '5BITS' = 5 bits per char. '6BITS' = 6 bits
CharBitsNum_STR STRING(20)
per char. '7BITS' = 7 bits per charr. '8BITS' = 8 bits per char.
Tbl. 1.18 Fields of the stSerialPortParam structure.

1.1.1.4.7 Remarks

The SerialC30 function is used both for opening and configuring of the serial port, as well as
sending and receiving of data.

The input parameter EnableComs_BL enables or disables the execution of the function block. If
EnableComs_BL is FALSE the port is closed and there are no communications.
EnableComs_BL must be TRUE to enable the function block.

The function block opens the port and configures it when it detects a rising edge in
EnableComs_BL. If the settings are correct, then ConnectOK_BL is set to TRUE and
ConnectError_BL is reset to FALSE . If an error occurs (ConnectError_BL = TRUE), the error
code is given in CommStatus_enComsRet. Another rising edge must occur to retry configuring.

Once the port has been successfully opened and configured, EnableComs_BL must stay to
TRUE, until a new configuration or the closing of the port is desired.

The C30 message includes the number of destination station. Each station filters messages and
processes only those which destination is such station. However the function block SerialC30
enables a mode of operation which allows to read messages addressed to other stations. This
mode can be enabled setting EnMultiStationRx_BL to TRUE. RxStationNum_US indicates the
number of the message's destination station.

The transmission and reception of messages is controlled by FlagEnTx_BL and FlagEnRx_BL.


Set the corresponding flag to TRUE to send or receive respectively. The function reset its state
to FALSE after the execution, correct or incorrect.

In the case of transmission, the amount of data to transmit must be indicated in NumBytesTx_US
(253 maximum). The location of the data to send must be pointed by TxBuff_ADDR. The station
to which send the data must also be indicated using the input parameter StationNum_US.

Ingeteam Proprietary All Rights Reserved Pag. 34


In the case of the receiving, the number of bytes received is indicated in the output parameter
NumBytesRx_US. The location where the data received is stored is indicated by RxBuff_ADDR.
In the case of multi station mode, the output parameter RxStationNum_US indicates from which
station the data come. If not working in multi station mode, the number of the station must be
indicated in StationNum_US, so that the function block filters the messages and returns only the
ones destinated to the station.

Check TxOK_BL, TxError_BL, RxOK_BL and RxError_BL to know when and how the
sending/receiving finishes. The function block resets these parameters in cycle next after the
completion of the sending/receiving.

The output parameter CommStatus_enComsRet indicates the status of the communications at


any time. In case of error provides additional information to parameters ConnectOK_BL,
ConnectError_BL, TxOK_BL, TxError_BL, RxOK_BL and RxError_BL.

The format of the frame in the C30 protocol is shown below:

Byte1: 68h

Byte2: Length of the message

Byte3: Length of the message

Byte4: 68h

Byte5: Number of station

Byte6: 00h

Byte6+1: User Data1

Byte6+2: User Data2

: :

Byte6+X: UserDataX

Byte6+X+1: Checksum

Byte6+X+2: 16h

The maximum length of the user Data is 253Bytes

1.1.1.4.8 Example

PROGRAM C30ExampleProgram

(* This program first receives data and then sends data *)

VAR CONSTANT

(* Memory buffer size *)

Ingeteam Proprietary All Rights Reserved Pag. 35


buffer_size : USINT := 253;

END_VAR

VAR

(* SerialC30 FB *)

CommC30: SerialC30;

en : BOOL := TRUE;

(* RS232 port configuration *)

port_conf : stSerialPortParam := (ChannelType_STR:= 'RS232',

RxTxSpeed_STR:= '38400B',

Parity_STR:= 'EVEN',

StopBitNum_DI := 0,

CharBitsNum_STR:= '8BITS');

(* Rx Tx control flags *)

flag_tx : BOOL;

flag_rx : BOOL;

sending : BOOL;

receiving : BOOL;

(* Send and receive data buffers *)

rx_buffer : ARRAY [1..buffer_size] OF BYTE;

tx_buffer : ARRAY [1..buffer_size] OF BYTE;

(* Rising edge detection *)

connected : R_TRIG;

(* Statistical *)

rx_frame_num : DINT;

rx_err_num : DINT;

tx_frame_num : DINT;

tx_err_num : DINT;

END_VAR

(* Calling of the FB *)

CommC30(

Ingeteam Proprietary All Rights Reserved Pag. 36


EnableComs_BL:= en,

StationNum_US:= 1,

EnMultiStationRx_BL:= FALSE,

TxBuff_ADDR:= ADR(tx_buffer),

NumBytesTx_US:= buffer_size,

RxBuff_ADDR:= ADR(rx_buffer),

RxTimeout_T:= t#500ms,

SerialParam_stSerialPortParam:= port_conf,

ChassisNum_DI:= 0,

SlotNum_DI:= 1,

ComPort_DI:= 0,

FlagEnTx_BL:= flag_tx,

FlagEnRx_BL:= flag_rx,

ConnectOK_BL=> ,

ConnectError_BL=> ,

TxOK_BL=> ,

TxError_BL=> ,

RxOK_BL=> ,

RxStationNum_US=> ,

RxError_BL=> ,

NumBytesRx_US=> ,

CommStatus_enComsRet=> );

(* Detect rising edge => connection established *)

connected(CLK:= CommC30.ConnectOK_BL, Q=> );

(* Start receiving after connection is established *)

IF connected.Q

THEN

receiving := TRUE;

END_IF

IF CommC30.ConnectOK_BL

Ingeteam Proprietary All Rights Reserved Pag. 37


THEN

(* If Received OK, then Send *)

IF CommC30.RxOK_BL

THEN

rx_frame_num := rx_frame_num + 1;

sending := TRUE;

END_IF

(* If Receive error, then retry *)

IF CommC30.RxError_BL

THEN

rx_err_num := rx_err_num + 1;

receiving := TRUE;

END_IF

(* If Sent OK, then receive *)

IF CommC30.TxOK_BL

THEN

tx_frame_num := tx_frame_num + 1;

receiving := TRUE;

END_IF

(* If Send error, then retry *)

IF CommC30.TxError_BL

THEN

tx_err_num := tx_err_num + 1;

sending := TRUE;

END_IF

END_IF

(* Set the flag for Sending *)

IF sending

THEN

flag_tx := TRUE;

Ingeteam Proprietary All Rights Reserved Pag. 38


END_IF

(* Set the flag for Receiving *)

IF receiving

THEN

flag_rx := TRUE;

END_IF

1.1.1.5 SerialVMP

1.1.1.5.1 Description

The function block SerialVMP allows to configure and implement a transparent communication
using the VMP Protocol.

1.1.1.5.2 Syntax

FUNCTION_BLOCK SerialVMP

VAR_INPUT

EnableComs_BL:BOOL;

TxSrcStationNum_US:USINT;

TxDstStationNum_US:USINT;

TxBuff_ADDR:DWORD;

NumBytesTx_US:USINT;

RxBuff_ADDR:DWORD;

RxTimeout_T:TIME;

SerialParam_stSerialPortParam:stSerialPortParam;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

ComPort_DI:DINT;

END_VAR

VAR_OUTPUT

ConnectOK_BL:BOOL:=FALSE;

ConnectError_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 39


TxOK_BL:BOOL;

TxError_BL:BOOL;

RxOK_BL:BOOL;

RxSrcStationNum_US:USINT;

RxDstStationNum_US:USINT;

RxError_BL:BOOL;

NumBytesRx_US:USINT;

CommStatus_enComsRet:enComsRet;

END_VAR

VAR_IN_OUT

FlagEnTx_BL:BOOL;

FlagEnRx_BL:BOOL;

END_VAR

1.1.1.5.3 Input parameters

Input Parameter Name Type Description


EnableComs_BL BOOL Activation of the VMP comunications.
TxSrcStationNum_US USINT Number of VMP station that is calling this function.
TxDstStationNum_US USINT Number of VMP destination station.
TxBuff_ADDR DWORD Address of the data buffer to send.
NumBytesTx_US USINT Number of bytes to send.
RxBuff_ADDR DWORD Address of the data buffer for the reception.
RxTimeout_T TIME Reception timeout.
SerialParam_stSerialPortParam stSerialPortParam Configuration of the serial communication.
ChassisNum_DI DINT Chassis Number.
SlotNum_DI DINT Module number.
ComPort_DI DINT Serial Port.
Tbl. 1.19 Input parameters of function SerialVMP.

Ingeteam Proprietary All Rights Reserved Pag. 40


1.1.1.5.4 Output parameters

Output Parameter Name Type Description


ConnectOK_BL BOOL The system is connected.
ConnectError_BL BOOL Erron in the connection.
TxOK_BL BOOL Frame sent OK.
TxError_BL BOOL Frame sent Erroneous.
RxOK_BL BOOL Frame reception OK .
RxSrcStationNum_US USINT Number of VMP station that sent the received message.
RxDstStationNum_US USINT Number of VMP station to which the received message was sent.
RxError_BL BOOL Frame reception Erroneous.
NumBytesRx_US USINT Number of received Bytes.
Communication Status, the values of the enumeration are available in
CommStatus_enComsRet enComsRet
the Communications_02 library.
Tbl. 1.20 Output parameters of function SerialVMP.

1.1.1.5.5 Input/Output parameters

Input/Output Parameter Name Type Description


FlagEnTx_BL BOOL Activation of the VMP sending.
FlagEnRx_BL BOOL Activation of the VMP receiving.
Tbl. 1.21 Input/Output parameters of function SerialVMP.

1.1.1.5.6 Data Types

1.1.1.5.6.1 enComsRet

( see Appendix I )

1.1.1.5.6.2 stSerialPortParam

Field Name Type Description


ChannelType_STR STRING(20) Channel type:. 'RS232'. 'MODEM'. 'RS485FULL'. 'RS485HALF'.
Data transmission speed(Baud):. '110B' = Link speed is 110 bauds.
'300B' = Link speed is 300 bauds. '600B" = Link speed is
600 bauds. '1200B' = Link speed is 1200 bauds. '2400B' = Link
speed is 2400 bauds -Valid CPU USART-. '4800B' = Link speed is
4800 bauds -Valid CPU USART-. '9600B' = Link speed is 9600
RxTxSpeed_STR STRING(20) bauds -Valid CPU USART-. '19200B' = Link speed is 19200 bauds
-Valid CPU USART-. '38400B' = Link speed is 38400 bauds -Valid
CPU USART-. '48000B' = Link speed is 48000 bauds. '64000B' =
Link speed is 64000 bauds. '96000B' = Link speed is 96000 bauds.
'192000B' = Link speed is 192000 bauds. '250000B' = Link speed
is 250000 bauds. '500000B' = Link speed is 500000 bauds.
Type of parity to be used:. 'NO PARITY' = No parity. 'ODD' =
Parity_STR STRING(20)
Odd parity. 'EVEN' = Even parity.
Number of stop bits.:. 0 = 1 stop bit. 1 = 1+1/2 if CharBitsNum_STR= 5.
StopBitNum_DI DINT
1 = 2 if CharBitsNum_STR<> 5.
The number of bits per character.:. '5BITS' = 5 bits per char. '6BITS' =
CharBitsNum_STR STRING(20)
6 bits per char. '7BITS' = 7 bits per charr. '8BITS' = 8 bits per char.
Tbl. 1.22 Fields of the stSerialPortParam structure.

Ingeteam Proprietary All Rights Reserved Pag. 41


1.1.1.5.7 Remarks

The SerialVMP function is used both for opening and configuring of the serial port, as well as
sending and receiving of data.

The input parameter EnableComs_BL enables or disables the execution of the function block. If
EnableComs_BL is FALSE the port is closed and there are no communications.
EnableComs_BL must be TRUE to enable the function block.

The function block opens the port and configures it when it detects a rising edge in
EnableComs_BL. If the settings are correct, then ConnectOK_BL is set to TRUE and
ConnectError_BL is reset to FALSE . If an error occurs (ConnectError_BL = TRUE), the error
code is given in CommStatus_enComsRet. Another rising edge must occur to retry configuring.

Once the port has been successfully opened and configured, EnableComs_BL must stay to
TRUE, until a new configuration or the closing of the port is desired.

The transmission and reception of messages is controlled by FlagEnTx_BL and FlagEnRx_BL.


Set the corresponding flag to TRUE to send or receive respectively. The function reset its state
to FALSE after the execution, correct or incorrect.

In the case of transmission, the amount of data to transmit must be indicated in NumBytesTx_US
(253 maximum). The location of the data to send must be pointed by TxBuff_ADDR. The station
to which send the data must also be indicated using the input parameter TxDstStationNum.

In the case of the receiving, the number of bytes received is indicated in the output parameter
NumBytesRx_US. The location where the data received is stored is indicated by RxBuff_ADDR.

Check TxOK_BL, TxError_BL, RxOK_BL and RxError_BL to know when and how the
sending/receiving finishes. The function block resets these parameters in cycle next after the
completion of the sending/receiving.

The output parameter CommStatus_enComsRet indicates the status of the communications at


any time. In case of error provides additional information to parameters ConnectOK_BL,
ConnectError_BL, TxOK_BL, TxError_BL, RxOK_BL and RxError_BL.

The format of the frame in the VMP protocol is shown below:

Byte1: E5h

Byte2: A7h

Byte3: CDh

Byte4: Number of station that transmits

Byte5: Number of station that receives

Byte6: Length of the message

Byte7: Message type

Ingeteam Proprietary All Rights Reserved Pag. 42


Byte7+1: User Data1

Byte7+2: User Data2

.. ..

Byte7+N: UserDataN

Byte7+N+1: ChecksumMSB

Byte7+N+2: ChecksumLSB

The maximum length of the user Data is 253 Bytes

1.2 Communications_02

The following tables sumarize the entities contained in Communications_02:

Name Description
BRCV The BRCV function is used to receive communication threads from a pre-established connection.
BSEND The BSEND function is used to send communication threads from a pre-established connection.
The CONNECT function establishes the connection between two participants for communication
CONNECT
purposes.
ETHERNET_SEND_RCV By means of the ETHERNET_SEND_RCV is possible to send and receive data via Ethernet.
Tbl. 1.23 Functions, Function Blocks, and Programs.

Ingeteam Proprietary All Rights Reserved Pag. 43


1.2.1 Functions

1.2.1.1 BRCV

1.2.1.1.1 Description

The BRCV function is used to receive communication threads from a pre-established connection.

The same BRCV function is used for receiving threads via both Ethernet (TCP, UDP) and Serial
(RS232, RS485 half-duplex, RS485 full-duplex), depending on what type of connection it is
associated with.

The function stands by listening for new receptions from the specified connection. When it
receives a new thread, it indicates this event by a reception flag. In the event of errors in the
reception, the function indicates this event by the corresponding error code.

1.2.1.1.2 Syntax

FUNCTION_BLOCK BRCV

VAR_INPUT

EnR_BL:BOOL;

Id_DI:DINT;

Rid_DI:DINT;

Rd1_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Ndr_BL:BOOL;

Error_BL:BOOL;

Status_enComsRet:enComsRet;

Len_DI:DINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 44


1.2.1.1.3 Input parameters

Input Parameter Name Type Description


EnR_BL BOOL Enable Frame Reception.
Id_DI DINT Connection ID number obtained by the CONNECT function.
Rid_DI DINT Variable designed for future use.
Rd1_ADDR DWORD Address of the data reception buffer.
Tbl. 1.24 Input parameters of function BRCV.

1.2.1.1.4 Output parameters

Output Parameter Name Type Description


Ndr_BL BOOL TRUE if a correct frame has been received.
Error_BL BOOL TRUE if there has been an error during reception.
Status_enComsRet enComsRet The function returns a code indicating possible running errors.
Len_DI DINT The size of the frame received in bytes.
Tbl. 1.25 Output parameters of function BRCV.

1.2.1.1.5 Data Types

1.2.1.1.5.1 enComsRet

( see Appendix I )

1.2.1.1.5.2 stTCPIP

Field Name Type Description


SyncProtocolType_STR STRING(16) Type of protocol. = 'TCP'.
The field in which to enter the IP address of the node we want to connect
to. If we enter an IP 0.0.0.0 in this field and the node is passive during the
Ip_STR STRING(16)
connection (ConnectionEstablishment_I:=0), the PLC will accept
connections from any IP.
If the node is responsible for making the connection
(ConnectionEstablishment_I:=1) it indicates the port of the remote
ConnectionPort_I INT equipment that it will connect to. If the node only accepts connections
(ConnectionEstablishment_I:=0) it indicates the local port through which it
will connect.
ConnectionEstablishment_I INT Tells the function if it has to establish(1) or accept (0) the connection.
NetworkCard_I INT Indicates the ethernet network interface to use.
ConnectionNum_I INT Indicates the connection number to use (0..15).
0: The connection includes a bit to continually detect the presence of the
KeepAliveInhibition_I INT connection. 1: The connection does not include the continuous link
detection bit.
Reserve0_DI INT Reserved for future use.
Reserve1_DI DINT Reserved for future use.
Reserve2_DI DINT Reserved for future use.
Reserve3_DI DINT Reserved for future use.
Reserve4_DI DINT Reserved for future use.
Reserve5_DI DINT Reserved for future use.
Tbl. 1.26 Fields of the stTCPIP structure.

Ingeteam Proprietary All Rights Reserved Pag. 45


Ingeteam Proprietary All Rights Reserved Pag. 46
1.2.1.1.6 Remarks

The use of the BRCV is very simple. Once a connection identifier has been obtained (output
parameter Id_DI of the CONNECT function), while reception is enabled with the EnR_BL
parameter of the BRCV function, the PLC will check for the arrival of new threads.

If it detects reception, it will indicate this with the corresponding flag, Ndr_BL, and place the data
in the address indicated in Rd1_ADDR, and the length of the thread received in the Len_DI field.

If an error occurs during reception, this will be shown with the Error_BL flag and the cause of the
error will be indicated by the code of the Status_DI variable.

To use the BRCV function in Ethernet communications, the reception data buffer must be
declared with a length of 1460 bytes, no matter how long the data we are going to receive is.

1.2.1.1.7 Example

PROGRAM PRG_Test_ComunicacionesEthernet

(************* MAIN PROGRAM ***************)

VAR CONSTANT

(* Definition of TCP communication*)

Port1TcpRemoteIp_STR: STRING:= '10.100.1.31';(*IP of remote computer on the TCP


communication port 1*)

Port1TcpNetworkCard_I: INT:=1 ;(*Port 1 of TCP communication network*)

Port1TcpKeepAliveInhibition_I: INT:=0 ;(*0 = Disable KeepAlive*)

Port1TcpConnectionEstablishment_I: INT:=1;(*1 = Establishes connection.*)

Port1TcpConnectionNum_I:INT:=1;(*Connection number*)

Port1TcpConnectionPort_I: INT:=1000;(*Connection port of the remote device *)

(* Definition of UDP communication*)

Port1UdpRemoteIp_STR: STRING:='10.100.1.31';(*IP of remote computer on the UDP


communication port 1*)

Port1UdpNetworkCard_I:INT:=1;(*Port 1 of UDP communication network*)

Port1UdpConnectionNum_I:INT:=0;(*Connection number *)

Port1UdpLocalConnectionPort_I:INT:=2345;(*Connection port number of the local UDP


communication port 1*)

Port1UdpRemoteConnectionPort_I:INT:=2345;(*Connection port number of the remote


UDP communication port 1*)

Ingeteam Proprietary All Rights Reserved Pag. 47


END_VAR

(* Block Variables*)

VAR

EnTestTcpEtherTransPort1 :BOOL:=TRUE;(*Enable test for the TCP communication port


*)

EnTestUdpEtherTransPort1 :BOOL:=TRUE;(*Enable test for the UDP communication port


1*)

TestComTcpEtherTransPort1 :TestComTcpEtherTrans;(*FB Communications TCP Test *)

TestComUdpEtherTransPort1 :TestComUdpEtherTrans;(*FB Communications UDP Test*)

ResetTcpEtherTransPort1: BOOL;(*Reset error values for the TCP communication test *)

ResetUdpEtherTransPort1 : BOOL;(*Reset error values for the UDP communication test*)

END_VAR

VAR

counter : INT := 0;

END_VAR

counter := counter +1;

(*FB Communications TCP Test *)

TestComTcpEtherTransPort1(

EnableTest:=EnTestTcpEtherTransPort1 ,

RemoteIp_STR:=Port1TcpRemoteIp_STR ,

NetworkCard_I:=Port1TcpNetworkCard_I ,

KeepAliveInhibition_I:=Port1TcpKeepAliveInhibition_I ,

ConnectionEstablishment_I:=Port1TcpConnectionEstablishment_I ,

ConnectionNum_I:=Port1TcpConnectionNum_I ,

ConnectionPort_I:=Port1TcpConnectionPort_I ,

ResetNumErrores:=ResetTcpEtherTransPort1 ,

ErrorFunciones=> ,

ErrorDatos=> );

FUNCTION_BLOCK TestComTcpEtherTrans

(************* MAIN FUNCTION_BLOCK ***************)

Ingeteam Proprietary All Rights Reserved Pag. 48


(*Input variables*)

VAR_INPUT

EnableTest :BOOL;(*Variable to activate the ethernet communications test*)

RemoteIp_STR :STRING;(*Remote computer's IP which is going to communicate*)

NetworkCard_I :INT;(*Number of port network to communicate*)

KeepAliveInhibition_I :INT;(*Inhabilitacion del Keep Alive*)

ConnectionEstablishment_I :INT;(*Establishing the connection to the remote computer*)

ConnectionNum_I :INT;(*Connection Number*)

ConnectionPort_I :INT;(*Connection port*)

ResetNumErrores:BOOL;(*Reset the number of errors accumulated*)

END_VAR

(*Variables de salida*)

VAR_OUTPUT

ErrorFunciones: BOOL; (*Error in communications functions*)

ErrorDatos: BOOL;(*Error in received data*)

END_VAR

(*{library private}*)

VAR

SendRec :TcpEtherSendRecTrans;(*low level FB which sends and waits for a reception


with the same data*)

BufferSend: ARRAY [0..24] OF DINT;(*Tx Buffer*)

BufferRec: ARRAY [0..24] OF DINT;(*Rx Buffer*)

Ind: DINT;(*Index usable in FOR*)

ErrorAuxFunciones: BOOL;(*Error in communications functions*)

ErrorAuxLongDatos: BOOL;(*Length error in the received data*)

END_VAR

(*low level FB which sends and waits for a reception with the same data*)

SendRec(

Enable_BL:=EnableTest ,

RxBuff_ADDR:=ADR (BufferRec) ,

Ingeteam Proprietary All Rights Reserved Pag. 49


TxBuff_ADDR:=ADR (BufferSend) ,

NumBytesTx_DI:=SIZEOF (BufferSend) ,

TxWaitTime_T:=T#200ms,

RxWaitTime_T:=T#1000ms ,

RemoteIp_STR:=RemoteIp_STR ,

NetworkCard_I:=NetworkCard_I ,

KeepAliveInhibition_I:=KeepAliveInhibition_I ,

ConnectionEstablishment_I:=ConnectionEstablishment_I ,

ConnectionNum_I:=ConnectionNum_I ,

ConnectionPort_I:=ConnectionPort_I ,

ConectOK_BL=> ,

ConectError_BL=> ,

RxOK_BL=> ,

RxError_BL=> ,

NumBytesRx_DI=> ,

TxOK_BL=> ,

TxError_BL=> ,

ComunicationStatus_enComsRet=> );

(*There have been a reception at the ethernet port*)

IF SendRec.RxOK_BL

THEN

(*The size of the data received is correct*)

IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)

THEN

ErrorAuxLongDatos:=TRUE;

END_IF;

(*Change before retransmit*)

BufferSend[0]:=BufferSend[0]+1;

FOR Ind:=1 TO ((SIZEOF( BufferSend)/4)-1)

DO

Ingeteam Proprietary All Rights Reserved Pag. 50


BufferSend[Ind]:=BufferSend[0]+Ind;

END_FOR;

END_IF;

(*Check for errors in communication*)

IF ((SendRec.RxError_BL OR SendRec.TxError_BL OR SendRec.ConectError_BL) AND


EnableTest)

THEN

ErrorAuxFunciones:=TRUE;

END_IF;

FUNCTION_BLOCK TcpEtherSendRecTrans

(************* LOW LEVEL FUNCTION_BLOCK ***************)

VAR_INPUT

(*Input variables to control communication*)

Enable_BL :BOOL;(*Activation of communications*)

RxBuff_ADDR :DWORD;(*Data reception buffer address *)

TxBuff_ADDR :DWORD;(*Data transmision buffer address*)

NumBytesTx_DI: DINT; (*Number of Bytes to be sent*)

TxWaitTime_T :TIME;(*Timeout after receiving and before transmitting*)

RxWaitTime_T :TIME;(*Timeout after transmitting and before receiving*)

(*Input variables to the configuration of Ethernet TCP*)

RemoteIp_STR: STRING;(*Remote computer's IP*)

NetworkCard_I: INT;(*Ethernet port which sends*)

KeepAliveInhibition_I: INT;(*Inhibition of Keep Alive*)

ConnectionEstablishment_I: INT;(*The computer establishes the connection*)

ConnectionNum_I: INT; (*Connection Number*)

ConnectionPort_I: INT;(* If this processor is responsible for establishing the connection


must indicate the connection port on the remote processor. In contrast, if the remote processor
establishes a connection who must indicate the connection port on the local processor.*)

END_VAR

VAR_OUTPUT

(*Output variables for know the communication status*)

Ingeteam Proprietary All Rights Reserved Pag. 51


ConectOK_BL: BOOL:=FALSE; (*The system is connected*)

ConectError_BL: BOOL;(*Connection Failed*)

RxOK_BL: BOOL;(*Received data OK*)

RxError_BL :BOOL;(*Erroneous reception*)

NumBytesRx_DI :DINT; (*Number of bytes received*)

TxOK_BL: BOOL;(*Sending a data OK*)

TxError_BL: BOOL;(*Transmission error*)

ComunicationStatus_enComsRet :enComsRet; (*Communication status*)

END_VAR

{library private}

VAR

Temp1: TON;

Temp2: TON;

(*COMMUNICATION FUNCTIONS USED*)

Conectar: CONNECT;

Envio:BSEND;

Recep:BRCV;

(*Configuration variables of the serial communication*)

Conexion:stTCPIP;

(*Communication control variables*)

ActivarConexion: BOOL;

SendEn: BOOL;

RecEn: BOOL;

Enviando: BOOL;

Recibiendo: BOOL;

RecepAuxStatus_enComsRet: enComsRet;

recValue :DINT;

recValueModified :DINT;

pRxBuffValue: POINTER TO DINT;

pTxBuffValue: POINTER TO DINT;

Ingeteam Proprietary All Rights Reserved Pag. 52


Status_ConectenComsRet :enComsRet;

Status_RxComsRet :enComsRet;

Status_TxComsRet :enComsRet;

END_VAR

(*Connection status*)

IF NOT ConectOK_BL

THEN

(* Comm. Setup*)

Conexion.SyncProtocolType_STR:= 'TCP';

Conexion.Ip_STR:= RemoteIp_STR;

Conexion.NetworkCard_I:= NetworkCard_I;

Conexion.KeepAliveInhibition_I:= KeepAliveInhibition_I;

Conexion.ConnectionEstablishment_I:= ConnectionEstablishment_I;

Conexion.ConnectionNum_I:= ConnectionNum_I;

Conexion.ConnectionPort_I:= ConnectionPort_I;

(*Activate the connection*)

ActivarConexion:=Enable_BL;

(*Do not apply any function while not connected*)

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

ELSE

(*Condition to start sending data*)

IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo

THEN

Enviando:=TRUE;

SendEn:=TRUE;

END_IF;

(*Condition to terminate transmission*)

Ingeteam Proprietary All Rights Reserved Pag. 53


IF SendEn AND Envio.Done_BL

THEN

SendEn:=FALSE;

Enviando:=FALSE;

Recibiendo:=TRUE;

END_IF;

(*Condition to start reception*)

IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo

THEN

RecEn:=TRUE;

END_IF;

(*Condition to wait for sending data *)

IF Recibiendo AND RecEn AND Recep.Ndr_BL

THEN

Recibiendo:=FALSE;

RecEn:=FALSE;

END_IF;

(*Check any error in communication*)

IF Conectar.Error_BL OR Envio.Error_BL OR Recep.Error_BL OR NOT Enable_BL

THEN

ActivarConexion:=FALSE;

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

END_IF;

END_IF;

(* CONNECT *)

Conectar (

EnC_BL:=ActivarConexion,

Ingeteam Proprietary All Rights Reserved Pag. 54


Partner_ADDR:=ADR(Conexion),

Valid_BL=>ConectOK_BL ,

Error_BL=>ConectError_BL ,

Status_enComsRet=>Status_ConectenComsRet,

Id_DI=> );

(* Timed to wait *)

Temp1(

IN:=ConectOK_BL AND NOT Enviando AND NOT Recibiendo ,

PT:=TxWaitTime_T ,

Q=> ,

ET=> );

Temp2(

IN:= Recibiendo ,

PT:=RxWaitTime_T ,

Q=> ,

ET=> );

(*RECEIVE*)

Recep(

EnR_BL:=RecEn ,

Id_DI:=Conectar.Id_DI ,

Rid_DI:=0 ,

Rd1_ADDR:=RxBuff_ADDR ,

Ndr_BL=>RxOK_BL ,

Error_BL=>RxError_BL ,

Status_enComsRet=>Status_RxComsRet ,

Len_DI=>NumBytesRx_DI );

(*SEND*)

Envio(

Req_BL:=SendEn ,

Reset_BL:=0 ,

Ingeteam Proprietary All Rights Reserved Pag. 55


Id_DI:=Conectar.Id_DI ,

Rid_DI:=0 ,

Len_DI:=NumBytesTx_DI ,

Sd1_ADDR:=TxBuff_ADDR ,

Done_BL=>TxOK_BL ,

Error_BL=>TxError_BL ,

Status_enComsRet=>Status_TxComsRet );

(*Check if time waiting for the reception has passed*)

IF Temp2.Q

THEN

(*indicates an error in receiving data*)

RxError_BL:=TRUE;

RecepAuxStatus_enComsRet:=125; (*NO_NEW_DATA*)

(*Disables the receiving mark and enable the reception to activate a new transmission*)

Recibiendo:=FALSE;

RecEn:=FALSE;

END_IF;

(*Init output FB status*)

ComunicationStatus_enComsRet:=OK_COMS;

(*Prioriry definition: in the case of having some communication error status follows the following
priority:

- first the status of the Connect function,

- second, the status of the receiver function and

- third the status of the transfer function*)

IF Conectar.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Conectar.Status_enComsRet;

ELSE

IF Recep.Status_enComsRet<>OK_COMS OR
RecepAuxStatus_enComsRet<>OK_COMS

Ingeteam Proprietary All Rights Reserved Pag. 56


THEN

IF RecepAuxStatus_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=RecepAuxStatus_enComsRet;

RecepAuxStatus_enComsRet:=OK_COMS;

ELSE

ComunicationStatus_enComsRet:=Recep.Status_enComsRet;

END_IF;

ELSE

IF Envio.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Envio.Status_enComsRet;

END_IF;

END_IF;

END_IF;

1.2.1.2 BSEND

1.2.1.2.1 Description

The BSEND function is used to send communication threads from a pre-established connection.

The BSEND function can be used to send threads both via Ethernet (TCP, UDP) and Serial
(RS232, RS485 half-duplex, RS485 full-duplex).

Every time there is an edge in the transmission flag, the function sends the specified data. If the
transmission does not end satisfactorily, this event will be indicated with an error flag, as well as
the code corresponding to the error that has occurred.

1.2.1.2.2 Syntax

FUNCTION_BLOCK BSEND

VAR_INPUT

Req_BL:BOOL;

Reset_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 57


Id_DI:DINT;

Rid_DI:DINT;

Len_DI:DINT;

Sd1_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Error_BL:BOOL;

Status_enComsRet:enComsRet;

END_VAR

1.2.1.2.3 Input parameters

Input Parameter Name Type Description


Req_BL BOOL A rising edge in this parameter indicates that a new transmission is ready.
Reset_BL BOOL Variable designed for future use.
Id_DI DINT Connection ID number obtained by the CONNECT function.
Rid_DI DINT Variable designed for future use.
Len_DI DINT Length in bytes of the data to be sent.
Sd1_ADDR DWORD Address of the buffer of data to be sent.
Tbl. 1.27 Input parameters of function BSEND.

1.2.1.2.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL TRUE if transmission ended and was correct.
TRUE if there has been an error during transmission.
Error_BL BOOL
The error status will be given in variable Status_enComsRet
Status_enComsRet enComsRet The function returns a code indicating possible running errors.
Tbl. 1.28 Output parameters of function BSEND.

1.2.1.2.5 Data Types

1.2.1.2.5.1 enComsRet

( see Appendix I )

Ingeteam Proprietary All Rights Reserved Pag. 58


1.2.1.2.5.2 stTCPIP

Field Name Type Description


SyncProtocolType_STR STRING(16) Type of protocol. = 'TCP'.
The field in which to enter the IP address of the node we want to connect
to. If we enter an IP 0.0.0.0 in this field and the node is passive during the
Ip_STR STRING(16)
connection (ConnectionEstablishment_I:=0), the PLC will accept
connections from any IP.
If the node is responsible for making the connection
(ConnectionEstablishment_I:=1) it indicates the port of the remote
ConnectionPort_I INT equipment that it will connect to. If the node only accepts connections
(ConnectionEstablishment_I:=0) it indicates the local port through which it
will connect.
ConnectionEstablishment_I INT Tells the function if it has to establish(1) or accept (0) the connection.
NetworkCard_I INT Indicates the ethernet network interface to use.
ConnectionNum_I INT Indicates the connection number to use (0..15).
0: The connection includes a bit to continually detect the presence of the
KeepAliveInhibition_I INT connection. 1: The connection does not include the continuous link
detection bit.
Reserve0_DI INT Reserved for future use.
Reserve1_DI DINT Reserved for future use.
Reserve2_DI DINT Reserved for future use.
Reserve3_DI DINT Reserved for future use.
Reserve4_DI DINT Reserved for future use.
Reserve5_DI DINT Reserved for future use.
Tbl. 1.29 Fields of the stTCPIP structure.

1.2.1.2.6 Remarks

The use of the BSEND is very simple. Once the connection identifier has been obtained (output
parameter Id_DI of the CONNECT function), the BSEND function sends the number of bytes
established in Len_DI of the data contained in a buffer whose address is set in the Sd1_ADDR
parameter each time there is a rising edge in the Req_BL input variable.

Once the transmission of the established data has been completed, the function returns this
status and sets the Done_BL flag to 1. Once the transmission is complete, another rising edge
can be provoked in Req_BL to send another transmission.

If an error occurs during transmission, this will be shown with the Error_BL flag and the cause of
the error will be indicated by the code of the Status_DI variable.

1.2.1.2.7 Example

PROGRAM PRG_Test_ComunicacionesEthernet

(************* MAIN PROGRAM ***************)

VAR CONSTANT

(* Definition of TCP communication*)

Ingeteam Proprietary All Rights Reserved Pag. 59


Port1TcpRemoteIp_STR:STRING:= '10.100.1.31';(*IP of remote computer on the TCP
communication port 1*)

Port1TcpNetworkCard_I:INT:=1;(*Port 1 of TCP communication network*)


Port1TcpKeepAliveInhibition_I: INT:=0 ;(*0 = Disable KeepAlive *)

Port1TcpConnectionEstablishment_I: INT:=1;(*1 = Establishes connection.*)

Port1TcpConnectionNum_I: INT:=1;(*Connection number*)

Port1TcpConnectionPort_I: INT:=1000 ;(*Connection port of the remote device*)

(* Definition of UDP communication*)

Port1UdpRemoteIp_STR:STRING:= '10.100.1.31';(*IP of remote computer on the UDP


communication port 1 *)

Port1UdpNetworkCard_I: INT:=1;(*Port 1 of UDP communication network*)

Port1UdpConnectionNum_I:INT:=0;(*Connection number*)

Port1UdpLocalConnectionPort_I:INT:=2345;(*Connection port number of the local UDP


communication port 1*)

Port1UdpRemoteConnectionPort_I: INT:=2345; (*Connection port number of the remote


UDP communication port 1*)

END_VAR

(* Block Variables*)

VAR

EnTestTcpEtherTransPort1:BOOL:=TRUE;(*Enable test for the TCP communication port 1


*)

EnTestUdpEtherTransPort1:BOOL:=TRUE;(*Enable test for the UDP communication port


1*)

TestComTcpEtherTransPort1:TestComTcpEtherTrans; (*FB Communications TCP Test*)

TestComUdpEtherTransPort1:TestComUdpEtherTrans; (*FB CommunicationsUDP Test *)

ResetTcpEtherTransPort1: BOOL;(*Reset error values for the TCP communication test *)

ResetUdpEtherTransPort1:BOOL;(*Reset error values for the UDP communication test *)

END_VAR

VAR

counter : INT := 0;

END_VAR

counter := counter +1;

Ingeteam Proprietary All Rights Reserved Pag. 60


(*FB Communications TCP Test*)

TestComTcpEtherTransPort1(

EnableTest:=EnTestTcpEtherTransPort1 ,

RemoteIp_STR:=Port1TcpRemoteIp_STR ,

NetworkCard_I:=Port1TcpNetworkCard_I ,

KeepAliveInhibition_I:=Port1TcpKeepAliveInhibition_I ,

ConnectionEstablishment_I:=Port1TcpConnectionEstablishment_I ,

ConnectionNum_I:=Port1TcpConnectionNum_I ,

ConnectionPort_I:=Port1TcpConnectionPort_I ,

ResetNumErrores:=ResetTcpEtherTransPort1 ,

ErrorFunciones=> ,

ErrorDatos=> );

FUNCTION_BLOCK TestComTcpEtherTrans

(************* MAIN FUNCTION_BLOCK ***************)

(*Input variables*)

VAR_INPUT

EnableTest :BOOL;(*Variable to activate the ethernet communications test*)

RemoteIp_STR :STRING;(*Remote computer's IP which is going to communicate*)

NetworkCard_I :INT;(*Number of port network to communicate*)

KeepAliveInhibition_I :INT;(*Inhabilitacion del Keep Alive*)

ConnectionEstablishment_I :INT;(*Establishing the connection to the remote computer*)

ConnectionNum_I :INT; (*Connection Number*)

ConnectionPort_I :INT;(*Connection port*)

ResetNumErrores:BOOL;(*Reset the number of errors accumulated*)

END_VAR

(*Variables de salida*)

VAR_OUTPUT

ErrorFunciones: BOOL; (*Error in communications functions*)

ErrorDatos: BOOL;(*Error in received data*)

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 61


(*{library private}*)

VAR

SendRec:TcpEtherSendRecTrans;(*low level FB which sends and waits for a reception


with the same data*)

BufferSend: ARRAY [0..24] OF DINT;(*Tx Buffer*)

BufferRec: ARRAY [0..24] OF DINT;(*Rx Buffer*)

Ind: DINT;(*Index usable in FOR*)

ErrorAuxFunciones: BOOL;(*Error in communications functions*)

ErrorAuxLongDatos: BOOL;(*Length error in the received data*)

END_VAR

(*low level FB which sends and waits for a reception with the same data*)

SendRec(

Enable_BL:=EnableTest ,

RxBuff_ADDR:=ADR (BufferRec) ,

TxBuff_ADDR:=ADR (BufferSend) ,

NumBytesTx_DI:=SIZEOF (BufferSend) ,

TxWaitTime_T:=T#200ms,

RxWaitTime_T:=T#1000ms ,

RemoteIp_STR:=RemoteIp_STR ,

NetworkCard_I:=NetworkCard_I ,

KeepAliveInhibition_I:=KeepAliveInhibition_I ,

ConnectionEstablishment_I:=ConnectionEstablishment_I ,

ConnectionNum_I:=ConnectionNum_I ,

ConnectionPort_I:=ConnectionPort_I ,

ConectOK_BL=> ,

ConectError_BL=> ,

RxOK_BL=> ,

RxError_BL=> ,

NumBytesRx_DI=> ,

TxOK_BL=> ,

Ingeteam Proprietary All Rights Reserved Pag. 62


TxError_BL=> ,

ComunicationStatus_enComsRet=> );

(*There have been a reception at the ethernet port*)

IF SendRec.RxOK_BL

THEN

(*The size of the data received is correct*)

IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)

THEN

ErrorAuxLongDatos:=TRUE;

END_IF;

(*Change before retransmit*)

BufferSend[0]:=BufferSend[0]+1;

FOR Ind:=1 TO ((SIZEOF( BufferSend)/4)-1)

DO

BufferSend[Ind]:=BufferSend[0]+Ind;

END_FOR;

END_IF;

(*Check for errors in communication*)

IF ((SendRec.RxError_BL OR SendRec.TxError_BL OR SendRec.ConectError_BL) AND


EnableTest)

THEN

ErrorAuxFunciones:=TRUE;

END_IF;

FUNCTION_BLOCK TcpEtherSendRecTrans

(************* LOW LEVEL FUNCTION_BLOCK ***************)

VAR_INPUT

(*Input variables to control communication*)

Enable_BL :BOOL;(*Activation of communications*)

RxBuff_ADDR :DWORD;(*Data reception buffer address *)

TxBuff_ADDR :DWORD;(*Data transmision buffer address*)

Ingeteam Proprietary All Rights Reserved Pag. 63


NumBytesTx_DI: DINT; (*Number of Bytes to be sent*)

TxWaitTime_T :TIME;(*Timeout after receiving and before transmitting*)

RxWaitTime_T :TIME;(*Timeout after transmitting and before receiving*)

(*Input variables to the configuration of Ethernet TCP*)

RemoteIp_STR: STRING;(*Remote computer's IP*)

NetworkCard_I: INT;(*Ethernet port which sends*)

KeepAliveInhibition_I: INT;(*Inhibition of Keep Alive*)

ConnectionEstablishment_I: INT;(*The computer establishes the connection*)

ConnectionNum_I: INT; (*Connection Number*)

ConnectionPort_I: INT; (* If this processor is responsible for establishing the connection


must indicate the connection port on the remote processor. In contrast, if the remote processor
establishes a connection who must indicate the connection port on the local processor. *)

END_VAR

VAR_OUTPUT

(*Output variables for know the communication status*)

ConectOK_BL: BOOL:=FALSE; (*The system is connected*)

ConectError_BL: BOOL;(*Connection Failed*)

RxOK_BL: BOOL;(*Received data OK*)

RxError_BL :BOOL;(*Erroneous reception*)

NumBytesRx_DI :DINT; (*Number of bytes received*)

TxOK_BL: BOOL;(*Sending a data OK*)

TxError_BL: BOOL;(*Transmission error*)

ComunicationStatus_enComsRet :enComsRet; (*Communication status*)

END_VAR

{library private}

VAR

Temp1: TON;

Temp2: TON;

(*COMMUNICATION FUNCTIONS USED*)

Conectar: CONNECT;

Ingeteam Proprietary All Rights Reserved Pag. 64


Envio:BSEND;

Recep:BRCV;

(*Configuration variables of the serial communication*)

Conexion:stTCPIP;

(*Communication control variables*)

ActivarConexion: BOOL;

SendEn: BOOL;

RecEn: BOOL;

Enviando: BOOL;

Recibiendo: BOOL;

RecepAuxStatus_enComsRet: enComsRet;

recValue :DINT;

recValueModified :DINT;

pRxBuffValue: POINTER TO DINT;

pTxBuffValue: POINTER TO DINT;

Status_ConectenComsRet :enComsRet;

Status_RxComsRet :enComsRet;

Status_TxComsRet :enComsRet;

END_VAR

(*Connection status*)

IF NOT ConectOK_BL

THEN

(* Comm. Setup*)

Conexion.SyncProtocolType_STR:= 'TCP';

Conexion.Ip_STR:= RemoteIp_STR;

Conexion.NetworkCard_I:= NetworkCard_I;

Conexion.KeepAliveInhibition_I:= KeepAliveInhibition_I;

Conexion.ConnectionEstablishment_I:= ConnectionEstablishment_I;

Conexion.ConnectionNum_I:= ConnectionNum_I;

Conexion.ConnectionPort_I:= ConnectionPort_I;

Ingeteam Proprietary All Rights Reserved Pag. 65


(*Activate the connection*)

ActivarConexion:=Enable_BL;

(*Do not apply any function while not connected*)

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

ELSE

(*Condition to start sending data*)

IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo

THEN

Enviando:=TRUE;

SendEn:=TRUE;

END_IF;

(*Condition to terminate transmission*)

IF SendEn AND Envio.Done_BL

THEN

SendEn:=FALSE;

Enviando:=FALSE;

Recibiendo:=TRUE;

END_IF;

(*Condition to start reception*)

IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo

THEN

RecEn:=TRUE;

END_IF;

(*Condition to wait for sending data *)

IF Recibiendo AND RecEn AND Recep.Ndr_BL

THEN

Recibiendo:=FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 66


RecEn:=FALSE;

END_IF;

(*Check any error in communication*)

IF Conectar.Error_BL OR Envio.Error_BL OR Recep.Error_BL OR NOT Enable_BL

THEN

ActivarConexion:=FALSE;

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

END_IF;

END_IF;

(* CONNECT *)

Conectar (

EnC_BL:=ActivarConexion,

Partner_ADDR:=ADR(Conexion),

Valid_BL=>ConectOK_BL ,

Error_BL=>ConectError_BL ,

Status_enComsRet=>Status_ConectenComsRet,

Id_DI=> );

(* Timed to wait *)

Temp1(

IN:=ConectOK_BL AND NOT Enviando AND NOT Recibiendo ,

PT:=TxWaitTime_T ,

Q=> ,

ET=> );

Temp2(

IN:= Recibiendo ,

PT:=RxWaitTime_T ,

Q=> ,

Ingeteam Proprietary All Rights Reserved Pag. 67


ET=> );

(*RECEIVE*)

Recep(

EnR_BL:=RecEn ,

Id_DI:=Conectar.Id_DI ,

Rid_DI:=0 ,

Rd1_ADDR:=RxBuff_ADDR ,

Ndr_BL=>RxOK_BL ,

Error_BL=>RxError_BL ,

Status_enComsRet=>Status_RxComsRet ,

Len_DI=>NumBytesRx_DI );

(*SEND*)

Envio(

Req_BL:=SendEn ,

Reset_BL:=0 ,

Id_DI:=Conectar.Id_DI ,

Rid_DI:=0 ,

Len_DI:=NumBytesTx_DI ,

Sd1_ADDR:=TxBuff_ADDR ,

Done_BL=>TxOK_BL ,

Error_BL=>TxError_BL ,

Status_enComsRet=>Status_TxComsRet );

(*Check if time waiting for the reception has passed*)

IF Temp2.Q

THEN

(*indicates an error in receiving data*)

RxError_BL:=TRUE;

RecepAuxStatus_enComsRet:=125; (*NO_NEW_DATA*)

(*Disables the receiving mark and enable the reception to activate a new transmission*)

Recibiendo:=FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 68


RecEn:=FALSE;

END_IF;

(*Init output FB status*)

ComunicationStatus_enComsRet:=OK_COMS;

(*Prioriry definition: in the case of having some communication error status follows the following
priority:

- first the status of the Connect function,

- second, the status of the receiver function and

- third the status of the transfer function*)

IF Conectar.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Conectar.Status_enComsRet;

ELSE

IF Recep.Status_enComsRet<>OK_COMS OR
RecepAuxStatus_enComsRet<>OK_COMS

THEN

IF RecepAuxStatus_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=RecepAuxStatus_enComsRet;

RecepAuxStatus_enComsRet:=OK_COMS;

ELSE

ComunicationStatus_enComsRet:=Recep.Status_enComsRet;

END_IF;

ELSE

IF Envio.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Envio.Status_enComsRet;

END_IF;

END_IF;

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 69


1.2.1.3 CONNECT

1.2.1.3.1 Description

The CONNECT function establishes the connection between two participants for communication
purposes.

These communications can be Ethernet (TCP, UDP), Serial (RS232, RS485 half-duplex, RS485
full-duplex), Serial Slave Modbus (RS232, RS485 half-duplex, RS485 full-duplex) or Serial
Master Modbus (RS232, RS485 half-duplex, RS485 full-duplex).

The call to function is based on parameter settings. Once completed, the function returns a
connection identifier if the connection has been completed satisfactorily or the corresponding
error code if connection has not been made.

1.2.1.3.2 Syntax

FUNCTION_BLOCK CONNECT

VAR_INPUT

EnC_BL:BOOL;

Partner_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Valid_BL:BOOL;

Error_BL:BOOL;

Status_enComsRet:enComsRet;

Id_DI:DINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 70


1.2.1.3.3 Input parameters

Input Parameter Name Type Description


This variable is used for enabling connection.
If the variable is set to TRUE, the function will allow or will attempt to establish the
EnC_BL BOOL
connection.
If the variable is set to FALSE, the connection will be closed.
Address of the buffer containing the connection configuration parameters.
Possible partners:.
Serial transparent communication (stTranspSerialConf)
Partner_ADDR DWORD Ethernet TCPIP transparent communication (stTCPIP)
Ethernet UDP transparent communication (stUDP)
Serial Modbus communication (stGenModbusSerialConf)
Asincronous ModbusTcp communication (stModbusTCP). .
Tbl. 1.30 Input parameters of function CONNECT.

1.2.1.3.4 Output parameters

Output Parameter Name Type Description


Variable in which the function writes the connection status.
If the variable is set to TRUE, it means that the connection with the remote device
Valid_BL BOOL
or communication port is valid.
If it is set to FALSE, it means that the connection is not established.
TRUE if there has been an error in the connection.
Error_BL BOOL
The error status will be given in variable Status_enComsRet.
The function returns a code indicating possible running errors.
Status_enComsRet enComsRet
See related status in enComsRet data type.
Id_DI DINT Connection identifier. This identifier is needed for functions BSEND and BRCV.
Tbl. 1.31 Output parameters of function CONNECT.

1.2.1.3.5 Data Types

1.2.1.3.5.1 enComsRet

( see Appendix I )

1.2.1.3.5.2 stGenModbusSerialConf

Field Name Type Description


Type of protocol:. MODBUS_SERIAL_MASTER'
ProtocolType_STR STRING(20)
'MODBUS_SERIAL_SLAVE'.
ChassisNum_DI DINT Chassis number of the IO module, -1 = CPU SERIAL PORT.
SlotNum_DI DINT Slot number of the IO module, -1 = CPU SERIAL PORT.
ComPort_DI DINT PORT number.
SerialParam_stSerialPortParam stSerialPortParam Serial communication parameters.
ModbusParam_stModbus_ADDR DWORD Address of the stModbusMaster or stModbusSlave structure.
TxMode_STR STRING(20) Transmission mode : 'RTU' o 'ASCII'.
SlaveMaster_STR STRING(20) Modbus slave or master setup is requested ('MASTER' or 'SLAVE').
It is the ID of the requested slave when used as a master and the ID of
SlaveAddr_DI DINT
the slave when used as a slave.
RxFrameTiming_T TIME Maximum waiting time to receive new frames.
Tbl. 1.32 Fields of the stGenModbusSerialConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 71


1.2.1.3.5.3 stModbusSerialConf

Field Name Type Description


Type of protocol:. 'MODBUS_SERIAL_MASTER'
ProtocolType_STR STRING(20)
MODBUS_SERIAL_SLAVE'. .
ChassisNum_DI DINT Chassis number of the IO module, -1 = CPU.
SlotNum_DI DINT Slot number of the IO module, -1 = CPU.
ComPort_DI DINT PORT number.
SerialParam_stSerialPortParam stSerialPortParam Serial communication parameters.
ModbusParam_stModbusSlave_ADDR DWORD Address of the stModbusSlave structure.
TxMode_STR STRING(20) Transmission mode : 'RTU' o 'ASCII'.
Modbus slave or master setup is requested ('MASTER' or
SlaveMaster_STR STRING(20)
'SLAVE').
It is the ID of the requested slave when used as a master and the
SlaveAddr_DI DINT
ID of the slave when used as a slave.
RxFrameTiming_T TIME Maximum waiting time to receive new frames.
Tbl. 1.33 Fields of the stModbusSerialConf structure.

1.2.1.3.5.4 stModbusSlave

Field Name Type Description


IniCoils_ADDR DWORD Pointer to the start address of the Coils.
IniInputs_ADDR DWORD Pointer to the start address of the Inputs.
IniHRegs_ADDR DWORD Pointer to the start address of the Holding Registers.
IniIRegs_ADDR DWORD Pointer to the start address of the Inputs Registers.
NoCoils_W WORD Number of Coils.
NoInputs_W WORD Number of Inputs.
NoHRegs_W WORD Number of Holding Registers.
NoIRegs_W WORD Number of Inputs Registers.
Tbl. 1.34 Fields of the stModbusSlave structure.

1.2.1.3.5.5 stModbusTCP

Field Name Type Description


ProtocolType_STR STRING(30) Type of protocol. = 'MODBUS_TCP'.
Identifier of the item to be sent/received. For this, the
communications module's configuration file must have been
ItemId_DI DINT
configured with an identifier for this transaction and Interval time
has to be 0.
This variable is used for enabling the sending or reception of
EnableComs_BL BOOL
data. If the variable is set to 0, the communication will finish.
FinishComs_BL BOOL The communication has finihed.
The function returns a code indicating the state of last
sent/received data. Possible codes:. ERR_ITEM_NUM.
ERR_SENDING_ITEM. ERR_REQUESTING_ITEM.
StatusComs_enComsRet enComsRet
OUT_OF_RANGE. ERR_TRAN_CYCLIC.
COMS_MODULE_NOT_STARTED_UP.
COMS_MODULE_BUSY.
Counter of successfully sent/received frames since
FrameOkCounter_DI DINT
EnableComs_BL was set.
Counter of unsuccessfully sent/received frames since
FrameErrorCounter_DI DINT
EnableComs_BL was set.
Tbl. 1.35 Fields of the stModbusTCP structure.

Ingeteam Proprietary All Rights Reserved Pag. 72


1.2.1.3.5.6 stTCPIP

Field Name Type Description


SyncProtocolType_STR STRING(16) Type of protocol. = 'TCP'.
The field in which to enter the IP address of the node we want to connect
to. If we enter an IP 0.0.0.0 in this field and the node is passive during the
Ip_STR STRING(16)
connection (ConnectionEstablishment_I:=0), the PLC will accept
connections from any IP.
If the node is responsible for making the connection
(ConnectionEstablishment_I:=1) it indicates the port of the remote
ConnectionPort_I INT equipment that it will connect to. If the node only accepts connections
(ConnectionEstablishment_I:=0) it indicates the local port through which it
will connect.
ConnectionEstablishment_I INT Tells the function if it has to establish(1) or accept (0) the connection.
NetworkCard_I INT Indicates the ethernet network interface to use.
ConnectionNum_I INT Indicates the connection number to use (0..15).
0: The connection includes a bit to continually detect the presence of the
KeepAliveInhibition_I INT connection. 1: The connection does not include the continuous link
detection bit.
Reserve0_DI INT Reserved for future use.
Reserve1_DI DINT Reserved for future use.
Reserve2_DI DINT Reserved for future use.
Reserve3_DI DINT Reserved for future use.
Reserve4_DI DINT Reserved for future use.
Reserve5_DI DINT Reserved for future use.
Tbl. 1.36 Fields of the stTCPIP structure.

1.2.1.3.5.7 stTranspSerialConf

Field Name Type Description


ProtocolType_STR STRING(20) Type of protocol = 'SERIAL'.
Chassis number of the IO module:. -1 = Use the USART of the CPU.
ChassisNum_DI DINT 0..15 = The Number of the chassis where the communication card is
inserted.
Slot number of the IO module:. -1 = Use the USART of the CPU.
SlotNum_DI DINT 0..15 = The Number of the chassis where the communication card is
inserted.
This indicates the communication port in the card that will be used to
ComPort_DI DINT
make the connection (0..X).
SerialParam_stSerialPortParam stSerialPortParam Serial communication parameters.
RxEnable_BL BOOL TRUE to start data reception.
RxFrameTiming_T TIME Maximum waiting time to receive new frames.
End of the message detected by:. 'TIMING' = End of message detection
EndMsgType_STR STRING(20) is time-based. 'END_MSG_CHAR' = End of message detection is
character-based.
Number of characters indicating the end of the message if
EndMsgType_STR='END_MSG_CHAR'. 0 = The end of message
EndMsgCharNum_DI DINT
character is not used. 1 = One end message char. 2 = Two end
message char.
ARRAY[0..1] OF End of message characters. Used only when the setting is
EndMsgChar_2SI_ARR
SINT 'END_MSG_CHAR' in the EndMsgType_STR field.
Timing between chars to consider the message finished (if
EndFrameTiming_T TIME
EndMsgType_STR='TIMING').
MaxNumBytesRx_DI DINT Maximum size of reception buffer in bytes.
TxEnable_BL BOOL Allow data sending in this connection.
MaxNumBytesTx_DI DINT Maximum size of the transmission buffer in bytes.
Tbl. 1.37 Fields of the stTranspSerialConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 73


1.2.1.3.5.8 stUDP

Field Name Type Description


SyncProtocolType_STR STRING(16) Type of protocol = 'UDP'.
The field in which to enter the IP address of the node we want to connect to. If we
Ip_STR STRING(16) enter an IP '0.0.0.0' in this field, the PLC will accept the connections from any IP.
Example: '90.0.0.1'.
This indicates the local node port through which the connection will be made. If
LocalConnectionPort_I INT
we want to send data only, we can set this parameter to 0.
RemoteConnectionPort_I INT This indicates the remote node port through which the connection will be made.
NetworkCard_I INT Indicates the ethernet network interface to use.
ConnectionNum_I INT Indicates the connection number to use (0..15).
Reserve0_DI DINT Reserved for future use.
Reserve1_DI DINT Reserved for future use.
Reserve2_DI DINT Reserved for future use.
Reserve3_DI DINT Reserved for future use.
Reserve4_DI DINT Reserved for future use.
Reserve5_DI DINT Reserved for future use.
Tbl. 1.38 Fields of the stUDP structure.

1.2.1.3.6 Remarks

The CONNECT function must be called to establish a connection with other equipment with
which to exchange data.

During bit EnC_BL, the CONNECT function first attempts to establish the link with the other
equipment. While unable to establish the connection, if the bit is still 1 the function will continue
attempting to establish connection.

Once the connection has been made, the EnC_BL bit must remain at 1 to keep the connection
open. When the value of this bit goes to 0, the connection will close.

For a previously established connection with specific parameters to change its parameters based
on the structure addressed in Partner_ADDR, a rising edge must take place in EnC_BL.
Therefore, if the connection was open, it must first be closd by setting the bit to 0, and then
enabling the connection by setting the bit to 1.

In the event that an Ethernet connection is established by the CONNECT function, if 0.0.0.0 is
entered in the Ip_STR parameter of the TCP or UDP structure (stTCPIP or stUDP), the PLC will
accept incoming connections from any remote client.

When establishing a connection for communication via Ethernet, the structure used by the
Partner_ADDR parameter must be of the stTCPIP or stUDP type, depending on whether we
want to use TCP/IP or UDP communication, respectively.

When establishing a port through which to make the connection, take into account that there are
several values assigned to communications defined by the system itself. These values are:

502: Reserved for Modbus communications.

Ingeteam Proprietary All Rights Reserved Pag. 74


8738: Reserved for SisteamBus communications.

21845: Reserved for CoDeSys.

8000..8100: Reserved for the System.

If the connection required is for communications via Serial (RS232 or RS485), the structure
containing the connection parameters must be of the stTranspSerialConf type.

If the connection required is for communications via Serial (Slave Modbus), the structure
containing the connection parameters must be of the stModbusSerialConf type.

The ModbusParam_stModbusSlave_ADDR field in the table above is a pointer to a structure of


the stModbusSlave type.

1.2.1.3.7 Example

PROGRAM PRG_Test_ComunicacionesEthernet

(************* MAIN PROGRAM ***************)

VAR CONSTANT

(* Definition of TCP communication*)

Port1TcpRemoteIp_STR:STRING:= '10.100.1.31';(*IP of remote computer on the TCP


communication port 1 *)

Port1TcpNetworkCard_I: INT:=1;(*Port 1 of TCP communication network*)

Port1TcpKeepAliveInhibition_I:INT:=0;(*0 = Disable KeepAlive*)

Port1TcpConnectionEstablishment_I:INT:=1;(*1 = Establishes connection.*)

Port1TcpConnectionNum_I:INT:=1;(*Connection number*)

Port1TcpConnectionPort_I:INT:=1000;(*Connection port of the remote device*)

(* Definition of UDP communication*)

Port1UdpRemoteIp_STR:STRING:= '10.100.1.31';(*IP of remote computer on the UDP


communication port 1 *)

Port1UdpNetworkCard_I:INT:=1;(*Port 1 of UDP communication network*)

Port1UdpConnectionNum_I:INT:=0;(*Connection number*)
Port1UdpLocalConnectionPort_I:INT:=2345;(*Connection port number of the local UDP
communication port 1 *)

Port1UdpRemoteConnectionPort_I:INT:=2345; (*Connection port number of the remote


UDP communication port 1*)

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 75


(* Block Variables*)

VAR

EnTestTcpEtherTransPort1:BOOL:=TRUE;(*Enable test for the TCP communication port 1


*)

EnTestUdpEtherTransPort1:BOOL:=TRUE;(*Enable test for the UDP communication port


1*)

TestComTcpEtherTransPort1:TestComTcpEtherTrans; (*FB Communications TCP Test*)

TestComUdpEtherTransPort1:TestComUdpEtherTrans;(*FB Communications UDP Test*)

ResetTcpEtherTransPort1: BOOL;(*Reset error values for the TCP communication test *)

ResetUdpEtherTransPort1:BOOL;(*Reset error values for the UDP communication test *)

END_VAR

VAR

counter : INT := 0;

END_VAR

counter := counter +1;

(*FB Communications TCP Test*)

TestComTcpEtherTransPort1(

EnableTest:=EnTestTcpEtherTransPort1 ,

RemoteIp_STR:=Port1TcpRemoteIp_STR ,

NetworkCard_I:=Port1TcpNetworkCard_I ,

KeepAliveInhibition_I:=Port1TcpKeepAliveInhibition_I ,

ConnectionEstablishment_I:=Port1TcpConnectionEstablishment_I ,

ConnectionNum_I:=Port1TcpConnectionNum_I ,

ConnectionPort_I:=Port1TcpConnectionPort_I ,

ResetNumErrores:=ResetTcpEtherTransPort1 ,

ErrorFunciones=> ,

ErrorDatos=> );

FUNCTION_BLOCK TestComTcpEtherTrans

(************* MAIN FUNCTION_BLOCK ***************)

(*Input variables*)

Ingeteam Proprietary All Rights Reserved Pag. 76


VAR_INPUT

EnableTest :BOOL;(*Variable to activate the ethernet communications test*)

RemoteIp_STR :STRING;(*Remote computer's IP which is going to communicate*)

NetworkCard_I :INT;(*Number of port network to communicate*)

KeepAliveInhibition_I :INT;(*Inhabilitacion del Keep Alive*)

ConnectionEstablishment_I :INT;(*Establishing the connection to the remote computer*)

ConnectionNum_I :INT; (*Connection Number*)

ConnectionPort_I :INT;(*Connection port*)

ResetNumErrores:BOOL;(*Reset the number of errors accumulated*)

END_VAR

(*Variables de salida*)

VAR_OUTPUT

ErrorFunciones: BOOL; (*Error in communications functions*)

ErrorDatos: BOOL;(*Error in received data*)

END_VAR

(*{library private}*)

VAR

SendRec :TcpEtherSendRecTrans;(*low level FB which sends and waits for a reception


with the same data*)

BufferSend: ARRAY [0..24] OF DINT;(*Tx Buffer*)

BufferRec: ARRAY [0..24] OF DINT;(*Rx Buffer*)

Ind: DINT;(*Index usable in FOR*)

ErrorAuxFunciones: BOOL;(*Error in communications functions*)

ErrorAuxLongDatos: BOOL;(*Length error in the received data*)

END_VAR

(*low level FB which sends and waits for a reception with the same data*)

SendRec(

Enable_BL:=EnableTest ,

RxBuff_ADDR:=ADR (BufferRec) ,

TxBuff_ADDR:=ADR (BufferSend) ,

Ingeteam Proprietary All Rights Reserved Pag. 77


NumBytesTx_DI:=SIZEOF (BufferSend) ,

TxWaitTime_T:=T#200ms,

RxWaitTime_T:=T#1000ms ,

RemoteIp_STR:=RemoteIp_STR ,

NetworkCard_I:=NetworkCard_I ,

KeepAliveInhibition_I:=KeepAliveInhibition_I ,

ConnectionEstablishment_I:=ConnectionEstablishment_I ,

ConnectionNum_I:=ConnectionNum_I ,

ConnectionPort_I:=ConnectionPort_I ,

ConectOK_BL=> ,

ConectError_BL=> ,

RxOK_BL=> ,

RxError_BL=> ,

NumBytesRx_DI=> ,

TxOK_BL=> ,

TxError_BL=> ,

ComunicationStatus_enComsRet=> );

(*There have been a reception at the ethernet port*)

IF SendRec.RxOK_BL

THEN

(*The size of the data received is correct*)

IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)

THEN

ErrorAuxLongDatos:=TRUE;

END_IF;

(*Change before retransmit*)

BufferSend[0]:=BufferSend[0]+1;

FOR Ind:=1 TO ((SIZEOF( BufferSend)/4)-1)

DO

BufferSend[Ind]:=BufferSend[0]+Ind;

Ingeteam Proprietary All Rights Reserved Pag. 78


END_FOR;

END_IF;

(*Check for errors in communication*)

IF ((SendRec.RxError_BL OR SendRec.TxError_BL OR SendRec.ConectError_BL) AND


EnableTest)

THEN

ErrorAuxFunciones:=TRUE;

END_IF;

FUNCTION_BLOCK TcpEtherSendRecTrans

(************* LOW LEVEL FUNCTION_BLOCK ***************)

VAR_INPUT

(*Input variables to control communication*)

Enable_BL :BOOL;(*Activation of communications*)

RxBuff_ADDR :DWORD;(*Data reception buffer address *)

TxBuff_ADDR :DWORD;(*Data transmision buffer address*)

NumBytesTx_DI: DINT; (*Number of Bytes to be sent*)

TxWaitTime_T :TIME;(*Timeout after receiving and before transmitting*)

RxWaitTime_T :TIME;(*Timeout after transmitting and before receiving*)

(*Input variables to the configuration of Ethernet TCP*)

RemoteIp_STR: STRING;(*Remote computer's IP*)

NetworkCard_I: INT;(*Ethernet port which sends*)

KeepAliveInhibition_I: INT;(*Inhibition of Keep Alive*)

ConnectionEstablishment_I: INT;(*The computer establishes the connection*)

ConnectionNum_I: INT; (*Connection Number*)

ConnectionPort_I: INT; (* If this processor is responsible for establishing the connection


must indicate the connection port on the remote processor. In contrast, if the remote processor
establishes a connection who must indicate the connection port on the local processor. *)

END_VAR

VAR_OUTPUT

(*Output variables for know the communication status*)

ConectOK_BL: BOOL:=FALSE; (*The system is connected*)

Ingeteam Proprietary All Rights Reserved Pag. 79


ConectError_BL: BOOL;(*Connection Failed*)

RxOK_BL: BOOL;(*Received data OK*)

RxError_BL :BOOL;(*Erroneous reception*)

NumBytesRx_DI :DINT; (*Number of bytes received*)

TxOK_BL: BOOL;(*Sending a data OK*)

TxError_BL: BOOL;(*Transmission error*)

ComunicationStatus_enComsRet :enComsRet; (*Communication status*)

END_VAR

{library private}

VAR

Temp1: TON;

Temp2: TON;

(*COMMUNICATION FUNCTIONS USED*)

Conectar: CONNECT;

Envio:BSEND;

Recep:BRCV;

(*Configuration variables of the serial communication*)

Conexion:stTCPIP;

(*Communication control variables*)

ActivarConexion: BOOL;

SendEn: BOOL;

RecEn: BOOL;

Enviando: BOOL;

Recibiendo: BOOL;

RecepAuxStatus_enComsRet: enComsRet;

recValue :DINT;

recValueModified :DINT;

pRxBuffValue: POINTER TO DINT;

pTxBuffValue: POINTER TO DINT;

Status_ConectenComsRet :enComsRet;

Ingeteam Proprietary All Rights Reserved Pag. 80


Status_RxComsRet :enComsRet;

Status_TxComsRet :enComsRet;

END_VAR

(*Connection status*)

IF NOT ConectOK_BL

THEN

(* Comm. Setup*)

Conexion.SyncProtocolType_STR:= 'TCP';

Conexion.Ip_STR:= RemoteIp_STR;

Conexion.NetworkCard_I:= NetworkCard_I;

Conexion.KeepAliveInhibition_I:= KeepAliveInhibition_I;

Conexion.ConnectionEstablishment_I:= ConnectionEstablishment_I;

Conexion.ConnectionNum_I:= ConnectionNum_I;

Conexion.ConnectionPort_I:= ConnectionPort_I;

(*Activate the connection*)

ActivarConexion:=Enable_BL;

(*Do not apply any function while not connected*)

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

ELSE

(*Condition to start sending data*)

IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo

THEN

Enviando:=TRUE;

SendEn:=TRUE;

END_IF;

(*Condition to terminate transmission*)

IF SendEn AND Envio.Done_BL

Ingeteam Proprietary All Rights Reserved Pag. 81


THEN

SendEn:=FALSE;

Enviando:=FALSE;

Recibiendo:=TRUE;

END_IF;

(*Condition to start reception*)

IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo

THEN

RecEn:=TRUE;

END_IF;

(*Condition to wait for sending data *)

IF Recibiendo AND RecEn AND Recep.Ndr_BL

THEN

Recibiendo:=FALSE;

RecEn:=FALSE;

END_IF;

(*Check any error in communication*)

IF Conectar.Error_BL OR Envio.Error_BL OR Recep.Error_BL OR NOT Enable_BL

THEN

ActivarConexion:=FALSE;

SendEn :=FALSE;

RecEn :=FALSE;

Recibiendo:=FALSE;

Enviando :=FALSE;

END_IF;

END_IF;

(* CONNECT *)

Conectar (

EnC_BL=ActivarConexion,

Partner_ADDR:=ADR(Conexion),

Ingeteam Proprietary All Rights Reserved Pag. 82


Valid_BL=>ConectOK_BL ,

Error_BL=>ConectError_BL ,

Status_enComsRet=>Status_ConectenComsRet,

Id_DI=> );

(* Timed to wait *)

Temp1(

IN:=ConectOK_BL AND NOT Enviando AND NOT Recibiendo ,

PT:=TxWaitTime_T ,

Q=> ,

ET=> );

Temp2(

IN:= Recibiendo ,

PT:=RxWaitTime_T ,

Q=> ,

ET=> );

(*RECEIVE*)

Recep(

EnR_BL:=RecEn ,

Id_DI:=Conectar.Id_DI ,

Rid_DI:=0 ,

Rd1_ADDR:=RxBuff_ADDR ,

Ndr_BL=>RxOK_BL ,

Error_BL=>RxError_BL ,

Status_enComsRet=>Status_RxComsRet ,

Len_DI=>NumBytesRx_DI );

(*SEND*)

Envio(

Req_BL:=SendEn ,

Reset_BL:=0 ,

Id_DI:=Conectar.Id_DI ,

Ingeteam Proprietary All Rights Reserved Pag. 83


Rid_DI:=0 ,

Len_DI:=NumBytesTx_DI ,

Sd1_ADDR:=TxBuff_ADDR ,

Done_BL=>TxOK_BL ,

Error_BL=>TxError_BL ,

Status_enComsRet=>Status_TxComsRet );

(*Check if time waiting for the reception has passed*)

IF Temp2.Q

THEN

(*indicates an error in receiving data*)

RxError_BL:=TRUE;

RecepAuxStatus_enComsRet:=125; (*NO_NEW_DATA*)

(*Disables the receiving mark and enable the reception to activate a new transmission*)

Recibiendo:=FALSE;

RecEn:=FALSE;

END_IF;

(*Init output FB status*)

ComunicationStatus_enComsRet:=OK_COMS;

(*Prioriry definition: in the case of having some communication error status follows the following
priority:

- first the status of the Connect function,

- second, the status of the receiver function and

- third the status of the transfer function*)

IF Conectar.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Conectar.Status_enComsRet;

ELSE

IF Recep.Status_enComsRet<>OK_COMS OR
RecepAuxStatus_enComsRet<>OK_COMS

THEN

Ingeteam Proprietary All Rights Reserved Pag. 84


IF RecepAuxStatus_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=RecepAuxStatus_enComsRet;

RecepAuxStatus_enComsRet:=OK_COMS;

ELSE

ComunicationStatus_enComsRet:=Recep.Status_enComsRet;

END_IF;

ELSE

IF Envio.Status_enComsRet<>OK_COMS

THEN

ComunicationStatus_enComsRet:=Envio.Status_enComsRet;

END_IF;

END_IF;

END_IF;

1.2.1.4 ETHERNET_SEND_RCV

1.2.1.4.1 Description

By means of the ETHERNET_SEND_RCV is possible to send and receive data via Ethernet.

Using the function's parameterization, the protocol over Ethernet to be used in communications
is indicated. Currently, communications as a ModbusTCP client are supported.

Once the function is parameterized, the function calling is executed to enable the
communications with the corresponding protocol, and the items send/return is enabled. This
function offers a diagnosis of the communications, so every time a send or receive finishes, it
gives the result of the operation.

1.2.1.4.2 Syntax

FUNCTION_BLOCK ETHERNET_SEND_RCV

VAR_INPUT

Enable_BL:BOOL;

Partner_ADDR:DWORD;

Ingeteam Proprietary All Rights Reserved Pag. 85


END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enComsRet:enComsRet;

END_VAR

1.2.1.4.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Allow or disallow the communications.
Pointer to an structure that contains the parameters of the communication to be done:
stModbusTCP.
Partner_ADDR DWORD
Currently, the following protocols can be used with Ethernet:
MODBUS_TCP, see stModbusTCP. .
Tbl. 1.39 Input parameters of function ETHERNET_SEND_RCV.

1.2.1.4.4 Output parameters

Output Parameter Name Type Description


Variable in which the function writes if the action performed by Enable_BL has
Done_BL BOOL
finished or not.
The function returns a code indicating possible running errors. See related status in
Status_enComsRet enComsRet
enComsRet data type
Tbl. 1.40 Output parameters of function ETHERNET_SEND_RCV.

1.2.1.4.5 Data Types

1.2.1.4.5.1 enComsRet

( see Appendix I )

1.2.1.4.5.2 stModbusTCP

Field Name Type Description


ProtocolType_STR STRING(30) Type of protocol. = 'MODBUS_TCP'.
Identifier of the item to be sent/received. For this, the communications module's
ItemId_DI DINT configuration file must have been configured with an identifier for this transaction
and Interval time has to be 0.
This variable is used for enabling the sending or reception of data. If the variable
EnableComs_BL BOOL
is set to 0, the communication will finish.
FinishComs_BL BOOL The communication has finihed.
The function returns a code indicating the state of last sent/received data.
Possible codes:. ERR_ITEM_NUM. ERR_SENDING_ITEM.
StatusComs_enComsRet enComsRet
ERR_REQUESTING_ITEM. OUT_OF_RANGE. ERR_TRAN_CYCLIC.
COMS_MODULE_NOT_STARTED_UP. COMS_MODULE_BUSY.
FrameOkCounter_DI DINT Counter of successfully sent/received frames since EnableComs_BL was set.
FrameErrorCounter_DI DINT Counter of unsuccessfully sent/received frames since EnableComs_BL was set.

Ingeteam Proprietary All Rights Reserved Pag. 86


Tbl. 1.41 Fields of the stModbusTCP structure.

Ingeteam Proprietary All Rights Reserved Pag. 87


1.2.1.4.6 Remarks

The ETHERNET_SEND_RCV function is used to send or receive data via Ethernet, using a
particular protocol specified in the function's parameterization.

To enable communication, the input parameter Enable_BL must be TRUE. When the requested
action ends, the function indicates it in the output parameter Done_BL, setting it to TRUE for a
cycle. Then it's value returns to FALSE.

Similarly, setting Enable_BL to FALSE requests the disabling of the communication, and the
output parameter Done_BL is TRUE for a cycle to indicate that communication has been
disabled.

In case of the protocol to use is ModbusTCP:

Having the communication enabled, to send/receive data the parameter EnableComs_BL must
be set to TRUE. The result of the communication (item sending/receiving) can be checked by
means of the FrameOkCounter_DI and FrameErrorCounter_DI fields of the stModbusTCP
structure.

The output parameter Status_enComsRet provides AT any moment diagnosis information about
the state OF communications.

Input parameter Partner_ADDR must point to an structure of stModbusTCP type. The most
important points for communication parametering via ModbusTCP are:

For each client item of ModbusTCP to communicate, an stModbusTCP structure is needed,


whose ItemId_DI field corresponds with an item configured in the ModbusTCP module
configurator.

While the field EnableComs_BL of the stModbusTCP structure is TRUE and the communications
are enabled (Enable_BL = TRUE), the ETHERNET_SEND_RCV function makes the
parameterized communication continuously. This is, it sends or receives data constantly.

If the item ModbusTCP is going to be communicated just once, by holding on TRUE the field
EnableComs_BL of the stModbusTCP structure (with the communications enabled) during a
cycle in the function calling, and then setting it to FALSE. Next, the sending/receiving will be
done, and that action could require a cycle or more.

The finishing of the ModbusTCP communication is indicated on the field FinishComs_BL of the
stModbusTCP structure. The function sets this field to TRUE when the communication of the
item finishes, and remains TRUE during a cycle.

The finishing of the communication of the ModbusTCP item does not imply that the
communication has been correct. The correct or wrong finish of the communication is obtained
by means of the fields FrameOkCounter_DI and FrameErrorCounter_DI of the stModbusTCP
structure.

Ingeteam Proprietary All Rights Reserved Pag. 88


The field StatusComs_enComsRet of the stModbusTCP structure contains a code that indicates
the state of the last sent/reception.

1.2.1.4.7 Example

PROGRAM PLC_PRG

VAR

send : ETHERNET_SEND_RCV;

recv: ETHERNET_SEND_RCV;

itemSend: stModbusTCP;

itemRecv: stModbusTCP;

communicating: BOOL;

sending: BOOL;

receiving: BOOL;

temp: TON;

prevSendOkCounter : DINT;

prevRecvOkCounter : DINT;

prevSendErrorCounter : DINT;

prevRecvErrorCounter : DINT;

END_VAR

(* Performs a 1 second period communication *)

temp.PT := t#1s;

temp.IN := NOT temp.Q;

temp();

IF NOT communicating AND temp.Q

THEN

communicating := TRUE;

sending := TRUE;

receiving := TRUE;

%QW2 := %QW2 + 1;

%QW3 := %QW3 + 2;

Ingeteam Proprietary All Rights Reserved Pag. 89


END_IF;

(* Items are configured in the ModbusTcp module configurator *)

(* 2 items: *)

(* READ_HOLDING_REGISTERS:Read 2 words at remote address %QW0 Local address


%QW0 item_ID: 0 WRITE_MULTIPLE_REGISTERS:Write 2 words at remote address %QW2
Local address %QW2 item_ID: 1*)

(* Read data: *)

%QW0;

%QW1;

(* Data to be written: *)

%QW2;

%QW3;

(* Item structure *)

itemSend.ItemId_DI := 1;

itemSend.ProtocolType_STR := 'MODBUS_TCP';

itemRecv.ItemId_DI := 0;

itemRecv.ProtocolType_STR := 'MODBUS_TCP';

itemSend.EnableComs_BL := sending;

itemRecv.EnableComs_BL := receiving;

(* Input parameters *)

send.Enable_BL := TRUE;

send.Partner_ADDR := ADR(itemSend);

recv.Enable_BL := TRUE;

recv.Partner_ADDR := ADR(itemRecv);

prevSendOkCounter := itemSend.FrameOkCounter_DI;

prevRecvOkCounter := itemRecv.FrameOkCounter_DI;

prevSendErrorCounter := itemSend.FrameErrorCounter_DI;

prevRecvErrorCounter := itemRecv.FrameErrorCounter_DI;

(* Calling of the functions *)

send();

Ingeteam Proprietary All Rights Reserved Pag. 90


recv();

sending := FALSE;

receiving := FALSE;

(* Do not attempt another send / recv until the previous one is finished *)

IF prevSendOkCounter <> itemSend.FrameOkCounter_DI AND prevRecvOkCounter <>


itemRecv.FrameOkCounter_DI OR

prevSendErrorCounter <> itemSend.FrameErrorCounter_DI OR

prevRecvErrorCounter <> itemRecv.FrameErrorCounter_DI

THEN

(* Make sure that communications are stopped *)

IF itemSend.FinishComs_BL = TRUE AND itemRecv.FinishComs_BL = TRUE

THEN

IF prevSendErrorCounter <> itemSend.FrameErrorCounter_DI

THEN

(*Error sending frame*)

itemSend.StatusComs_enComsRet;

END_IF;

IF prevRecvErrorCounter <> itemRecv.FrameErrorCounter_DI

THEN

(*Error sending frame*)

itemRecv.StatusComs_enComsRet;

END_IF;

communicating := FALSE;

END_IF;

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 91


1.3 CPU_01

The following tables sumarize the entities contained in CPU_01:

Name Description
PLC_DIAGNOSTIC Diagnostic information: CPU, I/O, communications, Temperature, ...
PLC_TIME This function block reads or sets the PLC real time clock time.
With this function the application can be informed of the defined scan time assigned to the task
READ_TASK_TIME
from which it is called.
WRITE_CONFIGURATION Generic function for configuring CPU resources.
The function block WRITE_CONFIGURATION can be used to configure some of the PLC's
WRITE_CONFIGURATIONv1
resources, such as the Ethernet network settings, for example.
WRITE_LOG This function inserts a log message into CPU log system.
Tbl. 1.42 Functions, Function Blocks, and Programs.

1.3.1 Functions

1.3.1.1 PLC_DIAGNOSTIC

1.3.1.1.1 Description

Diagnostic information: CPU, I/O, communications, Temperature, ...

The PLC_DIAGNOSTIC function provides staged information about the system errors or failures
and obtain statistical information regarding CPU consumption and temperature for example. This
function allows us to obtain information both at module or channel level.

The diagnosis is staged since each level has the information in more detail.

1.3.1.1.2 Syntax

FUNCTION_BLOCK PLC_DIAGNOSTIC

VAR_INPUT

Enable_BL:BOOL;

Reset_BL:BOOL;

IdElement_STR:STRING(35);

DiagnosticBuffer_ADDR:DWORD;

DiagnosticBufferSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

Status_DI:enDiagRet;

Ingeteam Proprietary All Rights Reserved Pag. 92


Valid_BL:BOOL;

Error_BL:BOOL;

END_VAR

1.3.1.1.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Function Block Enable / Disable.
Reset_BL BOOL Reset the diagnostic information.
Type of diagnostic information to obtain:
'I/Ov1cX': A diagnosis will be performed of the input/output slave modules of
a specific chassis.
X refers to the chassis number to be diagnosed.
When diagnosing this type of element, the data should be saved in a variable
of type stChassisIODiagnosticV1.
IdElement_STR STRING(35)
'CPUv2': The CPU will be diagnosed.
When diagnosing this type of element, the data should be saved in a variable
of type stCPUDiagnosticV2.
'CFLASHv0': The external Flash memory will be diagnosed.
When diagnosing this type of element, the data should be saved in a variable
of type stCflashDiagnostic.
Address of the buffer where the diagnostic information is going to be written
DiagnosticBuffer_ADDR DWORD
by the Function Block.
DiagnosticBufferSizeBy_DI DINT Size of the diagnostic buffer in bytes.
Tbl. 1.43 Input parameters of function PLC_DIAGNOSTIC.

1.3.1.1.4 Output parameters

Output Parameter Name Type Description


Status_DI enDiagRet Result of the function block execution. See enDiagRetfor related information.
Valid_BL BOOL Flag wich is set to TRUE when the diagnostic information is valid.
Flag wich is set to TRUE when the Function Block finishes incorrectly
Error_BL BOOL The extended information related to the FB error is written in the Status_DI
variable.
Tbl. 1.44 Output parameters of function PLC_DIAGNOSTIC.

1.3.1.1.5 Data Types

1.3.1.1.5.1 enDiagRet

Value Description
OK_DIAG (0) OK
UNKNOWN_ID_ELEMENT (1) Unknown IdElement_STR
INVALID_DIAGNOSTIC_BUFFER (2) The buffer is out of the task memory
INVALID_SIZE_DIAGNOSTIC_BUFFER (3) The buffer size is too small or too big
INVALID_CHASSIS_NUMBER (4) Invalid chassis number (I/O diagnostic)
DIAG_INTERNAL_ERROR (10) Function internal error
Tbl. 1.45 Enumerator enDiagRet.

Ingeteam Proprietary All Rights Reserved Pag. 93


1.3.1.1.5.2 stCflashDiagnostic

Field Name Type Description


ExternalMemoryStatus_BL BOOL FALSE when the external Flash memory is OK.
NumberOfOpenFiles_DI DINT Number open files.
BytesWritten_DI DINT Number of bytes writen into the CFlash.
BytesRead_DI DINT Number of bytes read from the CFlash.
ExternalMemorySizeMb_DI DINT Size of the external memory in MBytes.
ExternalMemoryFreeSpacePerc_R REAL Percentage of free memory size.
Tbl. 1.46 Fields of the stCflashDiagnostic structure.

1.3.1.1.5.3 stChassisIODiagnosticV1

Field Name Type Description


Status of the I/Os. Array of structures of the
stIOStatusV1 type where the results are stored.
IO_16stIOStatus_ARR ARRAY[0..15] OF stIOStatusV1 Each position of the array corresponds to the
diagnostic data of the module that occupies this
position in the chassis.
Chassis number:. 0: Local chassis. 1..15:
ChassisNumber_DI DINT
Remote chassis.
Tbl. 1.47 Fields of the stChassisIODiagnosticV1 structure.

1.3.1.1.5.4 stCPUDiagnosticV1

Field Name Type Description


BatteryRTCError_BL BOOL Status of the RTC battery.
CPUtemperature_stUnit stUnit CPU temperature.
FALSE when the external Flash memory is OK
ExternalMemoryStatus_BL BOOL
.
Ether_2stEtherStatus_ARR ARRAY[0..1] OF stEtherStatus Status of the CPU's ethernet.
TaskTime_10stTaskTime_ARR ARRAY[0..9] OF stTaskTimeV1 Contains task time related statistics.
CPUuse_stUnit stUnit Percentage of CPU use.
System_st10StartUp st10StartUp Information of last 10 system startups.
Tbl. 1.48 Fields of the stCPUDiagnosticV1 structure.

1.3.1.1.5.5 stCPUDiagnosticV2

Field Name Type Description


BatteryRTCError_BL BOOL Status of the RTC battery.
CPUtemperature_stUnit stUnit CPU temperature.
ExternalMemoryStatus_BL BOOL FALSE when the external Flash memory is OK.
Ether_2stEtherStatus_ARR ARRAY[0..1] OF stEtherStatus Status of the CPU's Ethernet Links.
TaskTime_10stTaskTime_ARR ARRAY[0..9] OF stTaskTimeV1 Contains task time related statistics.
CPUuse_stUnit stUnit Percentage of CPU use.
System_st10StartUp st10StartUp Information of last 10 system starts-ups.
LocalCPUExtendenInfo_stLocalCPUInfo stLocalCPUInfo CPU Local Information.
Tbl. 1.49 Fields of the stCPUDiagnosticV2 structure.

Ingeteam Proprietary All Rights Reserved Pag. 94


1.3.1.1.5.6 stCPUDiagnosticV3

Field Name Type Description


BatteryRTCError_BL BOOL Status of the RTC battery.
CPUtemperature_stUnit stUnit CPU temperature.
ExternalMemoryStatus_BL BOOL FALSE when the external Flash memory is OK.
Ether_4stEtherStatus_ARR ARRAY[0..3] OF stEtherStatusV1 Status of the CPU's Ethernet Links.
TaskTime_10stTaskTime_ARR ARRAY[0..9] OF stTaskTimeV1 Contains task time related statistics.
CPUuse_stUnit stUnit Percentage of CPU use.
MEMuse_stUnit stUnit Percentage of MEM use.
System_st10StartUp st10StartUp Information of last 10 system starts-ups.
LocalCPUExtendenInfo_stLocalCPUInfo stLocalCPUInfo CPU Local Information.
Tbl. 1.50 Fields of the stCPUDiagnosticV3 structure.

1.3.1.1.5.7 StCPUDiagnosticV4

Field Name Type Description


BatteryRTCError_BL BOOL Status of the RTC battery.
CPUtemperature_stUnit stUnit CPU temperature.
ExternalMemoryStatus_BL BOOL FALSE when the external Flash memory is OK.
Ether_4stEtherStatus_ARR ARRAY[0..3] OF stEtherStatusV1 Status of the CPU's Ethernet Links.
TaskTime_10stTaskTime_ARR ARRAY[0..9] OF stTaskTimeV1 Contains task time related statistics.
CPUuse_stUnit stUnit Percentage of CPU use.
MEMuse_stUnit stUnit Percentage of MEM use.
System_st10StartUp st10StartUp Information of last 10 system starts-ups.
LocalCPUExtendenInfo_stLocalCPUInfo stLocalCPUInfo CPU Local Information.
PowerSupply_ST stPowerStatus Power Supply Status.
Tbl. 1.51 Fields of the stCPUDiagnosticV4 structure.

1.3.1.1.5.8 stIOStatusV1

Field Name Type Description


IOtype_STR STRING(30) Type of I/O board configured in this posiiton.
IOtype_DI DINT Type of I/O board configured in this position.
IOVersion_STR STRING(30) Version of I/O board configured in this posiiton.
Manufactured version of the module present in this position of
IOManufactureVersion_STR STRING(30)
the chassis.
Serial number of the module present in this position of the
IOSerialNumber_STR STRING(30)
chassis.
IOStatus_DI enIOStatus I/O card status.
IOAutotestNumericalError_DI enIOAutotestNumericalError Numerical code related to the internal error of the I/O card.
Extended autotest information:. 0=OK (The channel is correct.
Valid for modules of the type: Digital inputs, Digital outputs,
Analog inputs, Analog outputs). 1=CHANNEL_ERROR (The
channel has an error. Valid for modules of the type: Digital
inputs, Digital outputs, Analog inputs, Analog outputs.).
2=CHANNEL_NOT_ENABLED (The channel is inhibited by its
IOAutotestExtInfo_100S_ARR ARRAY[0..100] OF SINT configuration. Valid for modules of the type: Digital inputs,
Digital outputs, Analog inputs, Analog outputs.).
3=CHANNEL_OVERFLOW (An Overflow has occurred in the
channel. Valid for modules of the type: Analog inputs, Analog
outputs). 4=CHANNEL_UNDERFLOW (An Underflow has
occurred in the channel. Valid for modules of the type: Analog
inputs, Analog outputs). 5=CHANNEL_TYPE_INCORRECT
(Channel configuration is incorrect. Valid for modules of the

Ingeteam Proprietary All Rights Reserved Pag. 95


Field Name Type Description
type: Analog inputs, Analog outputs).
6=CHANNEL_CONFIGURATION_ERROR (Channel
configuration error). There are some structures available to
make the use of extended information easier:.
IC3391=>stExtInfoIC3391. IC3392=>stExtInfoIC3392.
Firmware version of the module. Valid only for intelligent
IOVerFirmware_STR STRING(10)
modules.
Tbl. 1.52 Fields of the stIOStatusV1 structure.

1.3.1.1.6 Remarks

The PLC_DIAGNOSTIC function provides staged information about the system status. Thus, the
user can decide the level of depth to apply to the status analysis, as well as the actions to take in
each case.

The function will begin running as long as the Enable_BL bit enabling it is set at 1. To restart the
last values obtained by the function, set the Reset_BL bit to 1. This allows us to diagnose the
system again.

The information from the diagnosis is stored in a buffer whose type will depend on the type of
diagnosis performed. The diagnosis can be performed either on the status of the input/output
modules of a specific chassis or on the CPU. This type of diagnosis is configured by the value of
the IdElement_STR parameter. If the parameter takes the 'I/Ov1cX' value (where the X refers to
the number of the chassis of which we want to know the diagnosis results), the buffer must be of
the stChassisIODiagnosticV1 type. However, if the parameter takes the 'CPUv1' value, the buffer
must be established as the stCPUDiagnosticV1 type.

The IdElement_STR string type parameter must be I/Ov1cX, where the X is replaced by the
number of the chassis to diagnose, in order to diagnose the input/output modules.

The PLC_DIAGNOSTIC function returns the result of the input/output module diagnosis to a
stChassisIODiagnosticV1 type buffer, as has been mentioned. The information of this structure is
organized various levels. We can access the fields of each of the structures comprising the
buffer, depending on how much detail we want regarding an error type.

As an example, on the first level, as a field of the stChassisIODiagnosticV1 structure, there is the
stIOStatusV1 structure array. This array has an element for each of the chassis positions. This
structure contains information regarding the type of module, variant...as well as the result of the
diagnosis in the IOStatus_DI field. The IOAutotestNumericalError_DI field shows relevant
information when the value of IOStatus_DI is 1 (autotest). If the IOAutotestNumericalError_DI
value is 1 (error in one of the channels), we can access the value of the
IOAutotestExtInfo_100S_ARR array. This array contains information regarding the status of each
of the channels available in the module.

In addition, the function returns its own indications about the status of itself's execution via the
Status_DI, Valid_BL and Error_BL variables.

Ingeteam Proprietary All Rights Reserved Pag. 96


1.3.1.1.7 Example

PROGRAM EXAMPLE

VAR

nTest :DINT := 0;

END_VAR

VAR

myCPUdiag:PLC_DIAGNOSTIC;

locCPUDiagnosticV1:stCPUDiagnosticV1;(*CPUv1, *)

locChassisIODiagnosticV1:stChassisIODiagnosticV1; (* I/Ov1cX *)

END_VAR

CASE nTest OF

1:(* Get CPU Diagnostics on locCPUDiagnosticV1 struct*)

myCPUdiag(

Enable_BL:= TRUE,

Reset_BL:= FALSE,

IdElement_STR:= 'CPUV1',(*CPU diagnostic*)

DiagnosticBuffer_ADDR:= ADR(locCPUDiagnosticV1),

DiagnosticBufferSizeBy_DI:= SIZEOF(locCPUDiagnosticV1),

Status_DI=> ,

Valid_BL=> ,

Error_BL=> );

2:(* Get IO Diagnostics on locChassisIODiagnosticV1 struct*)

myCPUdiag(

Enable_BL:= TRUE,

Reset_BL:= FALSE,

IdElement_STR:= 'I/Ov1c0',

DiagnosticBuffer_ADDR:= ADR(locChassisIODiagnosticV1),

DiagnosticBufferSizeBy_DI:= SIZEOF(locChassisIODiagnosticV1),

Status_DI=> ,

Valid_BL=> ,

Ingeteam Proprietary All Rights Reserved Pag. 97


Error_BL=> );

END_CASE;

1.3.1.2 PLC_TIME

1.3.1.2.1 Description

This function block reads or sets the PLC real time clock time.

1.3.1.2.2 Syntax

FUNCTION_BLOCK PLC_TIME

VAR_INPUT

Enable_BL:BOOL;

Read_BL:BOOL;

Write_BL:BOOL;

WriteTime_stPLCTime:stPLCTime;

END_VAR

VAR_OUTPUT

Valid_BL:BOOL;

Status_DI:enPlcTimeRet;

ReadTime_stPLCTime:stPLCTime;

END_VAR

1.3.1.2.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable/Disable the PLC_TIME function Block.
When this input variable is set to TRUE, the PLC's clock is read in the
Read_BL BOOL
variable ReadTime_ST.
When this input variable is set to TRUE, the PLC's clock is written with the
Write_BL BOOL
value of the variable WriteTime_ST.
WriteTime_stPLCTime stPLCTime The data structure with the date and time information to write.
Tbl. 1.53 Input parameters of function PLC_TIME.

Ingeteam Proprietary All Rights Reserved Pag. 98


1.3.1.2.4 Output parameters

Output Parameter Name Type Description


When this variable is TRUE, the date and time read in the variable
Valid_BL BOOL
ReadTime_ST is valid.
Result of the execution of the Function Block, Value 0 means OK.
Status_DI enPlcTimeRet
See enPlcTimeRet for related information.
ReadTime_stPLCTime stPLCTime This structure contains the date and time that has been read from the PLC.
Tbl. 1.54 Output parameters of function PLC_TIME.

1.3.1.2.5 Data Types

1.3.1.2.5.1 enPlcTimeRet

Value Description
OK_PLC_TIME (0) OK
ERR_WRITTING_PLC_TIME (1) Error writting the PLC's clock
ERR_READING_PLC_TIME (2) Error reading the PlC's clock
ERR_WRITTING_INVALID_YEAR (3) Error writting the PLC's clock, wrong year
ERR_WRITTING_INVALID_DAY_OF_MONTH (4) Error writting the PLC's clock, wrong Day of Month
ERR_WRITTING_INVALID_MONTH (5) Error writting the PLC's clock, wrong Month
ERR_WRITTING_INVALID_HOUR (6) Error writting the PLC's clock, wrong Hour
ERR_WRITTING_INVALID_MINUTES (7) Error writting the PLC's clock, wrong minutes
ERR_WRITTING_INVALID_SECONDS (8) Error writting the PLC's clock, wrong seconds
ERR_WRITTING_INVALID_MILISECONDS (9) Error writting the PLC's clock, wrong milisencods
Tbl. 1.55 Enumerator enPlcTimeRet.

Ingeteam Proprietary All Rights Reserved Pag. 99


1.3.1.2.5.2 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing, the PLC_TIME
WeekDay_I INT function ignores this field, since the PLC calculates this value and writes it in the clock
automatically.
Tbl. 1.56 Fields of the stPLCTime structure.

1.3.1.2.6 Remarks

The Enable_BL boolean parameter enables/disables the function block. If Enable_BL is set to
FALSE, the FB does not execute. If Enable_BL set to TRUE, the FB executes and performs a
date and time reading if Read_BL is TRUE, or writing if Write_BL is TRUE.

When reading the PLC date and time, the read value is stored in the output parameter
ReadTime_stPLCTime. The FB sets the output parameter Valid_BL to TRUE if the value
contained in ReadTime_stPLCTime is a valid date and time. Otherwise Valid_BL is set to
FALSE. The result of the reading is indicated in the Status_DI output parameter.

When writing, the date and time to be written must be indicated in the input parameter
WriteTime_stPLCTime. The result of the writing is indicated in the Status_DI output parameter.

The WeekDay_I parameter of the structure stPLCTime is ignored when writing the PLC time.
The PLC calculates the week day for any given date automatically. When reading, the week day
will be 1 for Monday and 7 for Sunday.

1.3.1.2.7 Example

PROGRAM EXAMPLE

VAR

PlcTime : PLC_TIME;

newTime:stPLCTime:=(Year_I:=2008,Month_I:=07,Day_I:=30,Hour_I:=12,Minute_I:=55,Se
conds_I:=23,Miliseconds_I:=777) ; (*2008/07/30 12:55:23:777*)

END_VAR

(*Assign the new time*)

PlcTime( Enable_BL := TRUE,

Ingeteam Proprietary All Rights Reserved Pag. 100


Read_BL:=FALSE,

Write_BL:= TRUE, (*the PLC's clock is writted *)

WriteTime_stPLCTime := newTime, (*2008/07/30 12:55:23:777*)

Valid_BL =>,

Status_DI=>,

ReadTime_stPLCTime => );

1.3.1.3 READ_TASK_TIME

1.3.1.3.1 Description

With this function the application can be informed of the defined scan time assigned to the task
from which it is called.

1.3.1.3.2 Syntax

FUNCTION READ_TASK_TIME : DINT

1.3.1.3.3 Remarks

The function returns the scan time in microseconds.

A return value of 0 indicates internal error.

1.3.1.3.4 Example

PROGRAM EXAMPLE

VAR

task_time: DINT;

END_VAR

task_time := READ_TASK_TIME( );

1.3.1.4 WRITE_CONFIGURATION

1.3.1.4.1 Description

Generic function for configuring CPU resources.

Ingeteam Proprietary All Rights Reserved Pag. 101


The function block WRITE_CONFIGURATION can be used to configure some of the PLC's
resources, such as the Ethernet network settings, for example.

1.3.1.4.2 Syntax

FUNCTION_BLOCK WRITE_CONFIGURATION

VAR_INPUT

Enable_BL:BOOL;

IdElement_STR:STRING(35);

ConfigurationBuffer_ADDR:DWORD;

ConfigurationBufferSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

Status_enConfRet:enConfRet;

Done_BL:BOOL;

END_VAR

1.3.1.4.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Function Block Enable / Disable.
ID of the configuration information:
'NETc1v0': Net Configuration, for configuring one controller.
IdElement_STR STRING(35)
'NETc2v0': Net Configuration, for configuring two controller.
'NETcnv0': Net Configuration, for configuring n controller.
Address of the buffer that contains the new settings.
For configuring one controller: stConfEtherV0.
ConfigurationBuffer_ADDR DWORD
For configuring two controller: ARRAY[0..1] OF stConfEtherV0.
For configuring n controller (ARRAY[0..n-1] OF stConfEtherV0).
ConfigurationBufferSizeBy_DI DINT Size in bytes of the configuration buffer.
Tbl. 1.57 Input parameters of function WRITE_CONFIGURATION.

1.3.1.4.4 Output parameters

Output Parameter Name Type Description


Result of the function block execution.
Status_enConfRet enConfRet
See enConfRet for related information.
The function sets this parameter to TRUE after the configuration operation
Done_BL BOOL
finishes. The execution result is given in Status_enConfRet.
Tbl. 1.58 Output parameters of function WRITE_CONFIGURATION.

Ingeteam Proprietary All Rights Reserved Pag. 102


1.3.1.4.5 Data Types

1.3.1.4.5.1 enConfRet

Value Description
OK_CONF (0) No error.
UNKNOWN_CONF_ID (1) Unknown ID of the configuration information.
INVALID_CONF_BUFFER_ADDR (2) Buffer address is out of memory.
INVALID_CONF_BUFFER_SIZE (3) Erroneous size of configuration buffer.
INVALID_PARAM_CONF_BUFFER (4) Erroneous parameter in configuration buffer.
INTERNAL_ERROR (5) Function internal error.
Tbl. 1.59 Enumerator enConfRet.

1.3.1.4.5.2 stConfEtherV0

Field Name Type Description


IPaddr_STR STRING(30) IP address. For example: '90.0.0.1'.
Mask_STR STRING(30) Mask. For example: '255.255.255.0'.
Gateway_STR STRING(30) Gateway. For example: '0.0.0.0'.
NICId_I INT Number of the ethernet controller to configure.
Tbl. 1.60 Fields of the stConfEtherV0 structure.

1.3.1.4.6 Remarks

The input parameter Enable_BL enables or disables the execution of the function block. If
Enable_BL is TRUE the configuration contained in the memory buffer pointed to by
ConfigurationBuffer_ADDR is written. The configuration ID must be indicated in IdElement_STR,
so that the function block can parse the data stored in the buffer.

For example, to set a new network configuration for the two Ethernet interfaces, assign
IdElement_STR: = 'NETc2v0'. Done_BL output parameter is set to TRUE during one cycle after
the execution of the function block. The Status_enConfRet parameter contains the result of the
execution. If Status_enConfRet = OK_CONF then the configuration was successful, otherwise
an error occurred. In the case of Ethernet network configuration, if successfully configured, the
PLC automatically restarts after the execution of the function block so that the new settings can
come into force.

1.3.1.4.7 Example

PROGRAM WriteNetConfigurationExample

VAR

SetNetConf : WRITE_CONFIGURATION;

status : enConfRet;

Ingeteam Proprietary All Rights Reserved Pag. 103


ntconfig : ARRAY[0..1] OF stConfEtherV0;

en: BOOL:=TRUE;

done: BOOL;

END_VAR

(*SetNetConf : WRITE_CONFIGURATION;*)

ntconfig[0].IPaddr_STR := '90.0.0.1';(*Primary IP*)

ntconfig[0].Mask_STR :='255.255.255.0';

ntconfig[0].Gateway_STR:='0.0.0.0';

ntconfig[0].NICId_I:= 0;

ntconfig[1].IPaddr_STR:='90.0.32.1';(*Secondary IP*)

ntconfig[1].Mask_STR:='255.255.255.0';

ntconfig[1].Gateway_STR:='0.0.0.0';

ntconfig[1].NICId_I:=1;

SetNetConf( Enable_BL:= en,

IdElement_STR:='NETc2v0',

ConfigurationBuffer_ADDR:=ADR(ntconfig),

ConfigurationBufferSizeBy_DI:=SIZEOF(ntconfig),

Status_enConfRet=> status,

Done_BL=> done);

IF en AND status = OK_CONF AND done

THEN

en := FALSE;

END_IF;

1.3.1.5 WRITE_CONFIGURATIONv1

1.3.1.5.1 Description

The function block WRITE_CONFIGURATION can be used to configure some of the PLC's
resources, such as the Ethernet network settings, for example.

Ingeteam Proprietary All Rights Reserved Pag. 104


1.3.1.5.2 Syntax

FUNCTION_BLOCK WRITE_CONFIGURATIONv1

VAR_INPUT

Enable_BL:BOOL;

IdElement_STR:STRING(35);

ConfigurationBuffer_ADDR:DWORD;

ConfigurationBufferSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

Status_enConfRet:enConfRet;

Done_BL:BOOL;

END_VAR

1.3.1.5.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Function Block Enable / Disable.
Identifier of the configuration information.
'NETc1v0' = Net Configuration, for configuring one controller.
'NETc2v0' = Net Configuration , for configuring two controller.
IdElement_STR STRING(35) 'NETcnv0' = Net Configuration, for configuring n controller.
'AE_LOG_RETAIN_v0' = Alarms/Events Log Memory Configuration.
'FW_PROTEC_V0' = Write Firmware Protections.
'RECONFIG_REQUEST_V0' = Firmware Reconfiguration Request.
Address of the buffer where the Configuration information is written.
For configuring one controller (stConfEtherV0).
For configuring two controller (ARRAY[0..1] OF stConfEtherV0).
ConfigurationBuffer_ADDR DWORD For configuring 'n' controller (ARRAY[0..n-1] OF stConfEtherV0).
For configuring Alarms/Events Log Memory (stConfAELogRetainV0).
For configuring Firmware Protections (stFwProtectionsV0).
For Firmware Reconfiguration Request (stReconfigRequestV0).
ConfigurationBufferSizeBy_DI DINT Size in bytes of the configuration buffer.
Tbl. 1.61 Input parameters of function WRITE_CONFIGURATIONv1.

1.3.1.5.4 Output parameters

Output Parameter Name Type Description


Result of the function block execution.
Status_enConfRet enConfRet
See 'enConfRet' for related information
Done_BL BOOL Function set to TRUE when the configuration has been written
Tbl. 1.62 Output parameters of function WRITE_CONFIGURATIONv1.

Ingeteam Proprietary All Rights Reserved Pag. 105


1.3.1.5.5 Data Types

1.3.1.5.5.1 enConfRet

Value Description
OK_CONF (0) No error.
UNKNOWN_CONF_ID (1) Unknown ID of the configuration information.
INVALID_CONF_BUFFER_ADDR (2) Buffer address is out of memory.
INVALID_CONF_BUFFER_SIZE (3) Erroneous size of configuration buffer.
INVALID_PARAM_CONF_BUFFER (4) Erroneous parameter in configuration buffer.
INTERNAL_ERROR (5) Function internal error.
Tbl. 1.63 Enumerator enConfRet.

1.3.1.5.5.2 stConfAELogRetainV0

Field Name Type Description


Log_Base_ADDR DWORD Base Address for the Alarms/Events Log Memory.
Log_Size_DW DWORD Size of the Alarms/Events Log Memory.
Alarms/Events Log Memory Command (according to the enumeration
Command_DW DWORD
'enAELogConfCommands'.
Tbl. 1.64 Fields of the stConfAELogRetainV0 structure.

1.3.1.5.5.3 stConfEtherV0

Field Name Type Description


IPaddr_STR STRING(30) IP address. For example: '90.0.0.1'.
Mask_STR STRING(30) Mask. For example: '255.255.255.0'.
Gateway_STR STRING(30) Gateway. For example: '0.0.0.0'.
NICId_I INT Number of the ethernet controller to configure.
Tbl. 1.65 Fields of the stConfEtherV0 structure.

1.3.1.5.5.4 stFwProtectionsV0

Field Name Type Description


Firmware Protections mask (can be obtained by using the global
FirmwareProtections_DW DWORD
constants declared in &quot;Firmware_Protections&quot; list.
Tbl. 1.66 Fields of the stFwProtectionsV0 structure.

1.3.1.5.5.5 stReconfigRequestV0

Field Name Type Description


ReconfigurationId_enReconfId enReconfId Reconfiguration Identifier.
Tbl. 1.67 Fields of the stReconfigRequestV0 structure.

Ingeteam Proprietary All Rights Reserved Pag. 106


1.3.1.5.6 Remarks

The input parameter Enable_BL enables or disables the execution of the function block. If
Enable_BL is TRUE the configuration contained in the memory buffer pointed to by
ConfigurationBuffer_ADDR is written. The configuration ID must be indicated in IdElement_STR,
so that the function block can parse the data stored in the buffer.

For example, to set a new network configuration for the two Ethernet interfaces, assign
IdElement_STR: = 'NETc2v0'. Done_BL output parameter is set to TRUE during one cycle after
the execution of the function block. The Status_enConfRet parameter contains the result of the
execution. If Status_enConfRet = OK_CONF then the configuration was successful, otherwise
an error occurred. In the case of Ethernet network configuration, if successfully configured, the
PLC automatically restarts after the execution of the function block so that the new settings can
come into force.

1.3.1.5.7 Example

PROGRAM WriteNetConfigurationExample

VAR

SetNetConf : WRITE_CONFIGURATIONv1;

status : enConfRet;

ntconfig : ARRAY[0..1] OF stConfEtherV0;

en: BOOL := TRUE;

done: BOOL;

END_VAR

(*SetNetConf : WRITE_CONFIGURATIONv1;*)

ntconfig[0].IPaddr_STR :='90.0.0.1';(*Primary IP*)

ntconfig[0].Mask_STR :='255.255.255.0';

ntconfig[0].Gateway_STR:='0.0.0.0';

ntconfig[0].NICId_I:= 0;

ntconfig[1].IPaddr_STR :='90.0.32.1';(*Secondary IP*)

ntconfig[1].Mask_STR:='255.255.255.0';

ntconfig[1].Gateway_STR:='0.0.0.0';

ntconfig[1].NICId_I:=1;

SetNetConf( Enable_BL:=en,

Ingeteam Proprietary All Rights Reserved Pag. 107


IdElement_STR:= 'NETc2v0',

ConfigurationBuffer_ADDR:= ADR(ntconfig),

ConfigurationBufferSizeBy_DI:= SIZEOF(ntconfig),

Status_enConfRet=> status,

Done_BL=> done);

IF en AND status = OK_CONF AND done

THEN

en := FALSE;

END_IF;

1.3.1.6 WRITE_LOG

1.3.1.6.1 Description

This function inserts a log message into CPU log system.

1.3.1.6.2 Syntax

FUNCTION WRITE_LOG : DINT

VAR_INPUT

Enable_BL:BOOL;

Source_SI:SINT;

EventCode_I:INT;

ParameterList_STR:STRING(127);

CriticalyLevel_enCLevel:enCLevel;

PrivilegeLevel_SI:SINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 108


1.3.1.6.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Function Enable/Disable.
Source_SI SINT Source area numerical code 0..99.
EventCode_I INT = 0. Reserved for future use.
ParameterList_STR STRING(127) Log message.
CriticalyLevel_enCLevel enCLevel Log criticaly level.
Log privilege level. 0..100.
PrivilegeLevel_SI SINT A log can be read by user with Read Privilege Level equal or higher
than Log Privilege Level.
Tbl. 1.68 Input parameters of function FUNCTION WRITE_LOG : DINT.

1.3.1.6.4 Data Types

1.3.1.6.4.1 enCLevel

Value Description
CL_ERROR (1)
CL_WARNING (2)
CL_INFO (3)
CL_DEBUG (4)
CL_CRITICAL (5)
CL_SECURITY (6)
Tbl. 1.69 Enumerator enCLevel.

1.3.1.6.5 Remarks

RETURN values

-1: Error occurs. The log has not been written

0: No error or disabled

1.3.1.6.6 Example

PROGRAM EXAMPLE

VAR

Error_DI : DINT;

END_VAR

VAR CONSTANT

SRC_EXAMPLE: SINT := 1;

PL_EXAMPLE: SINT := 10;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 109


Error_DI := WRITE_LOG(TRUE, SRC_EXAMPLE, 0, 'Hello world', CL_INFO, PL_EXAMPLE);

1.4 DataLogger_02

The following tables sumarize the entities contained in DataLogger_02:

Name Description
DIR_CREATE This function creates directories with the desired name in the CFLASH.
DIR_REMOVE This function removes an existing directory from the CFLASH memory.
DIR_RENAME This function renames an existing directory in the CFLASH memory.
DIR_SCAN This function searches a directory for a file or a subdirectory whose name matches the specified file name.
FILE_CREATE This function creates, opens or closes files in the CFLASH memory of the PLC.
FILE_DELETE This function deletes a previously created file in the non volatile memory of the INGESYS IC3 CPU.
FILE_READ This function reads data from a file in the CFLASH memory and stores it in a program buffer.
FILE_RENAME This function renames an existing file in the CFLASH memory.
FILE_SET_POINTER This function moves the file pointer to the position specified by the user.
FILE_WRITE This function writes data from a buffer program in a CFLASH memory file.
LIST_CREATE This function is used to create a list of elements.
LIST_GET The LIST_GET function obtains a specific element contained in a list.
LIST_INSERT This function inserts an element in a previously created list.
LIST_REMOVE Function block to remove a single/all element from the LIST.
Tbl. 1.70 Functions, Function Blocks, and Programs.

1.4.1 Functions

1.4.1.1 DIR_CREATE

1.4.1.1.1 Description

This function creates directories with the desired name in the CFLASH.

1.4.1.1.2 Syntax

FUNCTION_BLOCK DIR_CREATE

VAR_INPUT

Enable_BL:BOOL;

DirectoryName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enDirRet:enDirRet;

Ingeteam Proprietary All Rights Reserved Pag. 110


END_VAR

1.4.1.1.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
String of characters with the path of the directory we want to create.
DirectoryName_STR STRING(255)
The string must start with the character '\'.
Tbl. 1.71 Input parameters of function DIR_CREATE.

1.4.1.1.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
Status_enDirRet enDirRet OK_DIR: Correct execution
ERR_CREATE_DIR: Error, the directory can not be created
ERR_DIR_NAME: Error, the name of the directory is invalid
Tbl. 1.72 Output parameters of function DIR_CREATE.

1.4.1.1.5 Data Types

1.4.1.1.5.1 enDirRet

Value Description
OK_DIR (0) Correct execution
ERR_CREATE_DIR (21) Error, the directory can not be creatted
ERR_DIR_NAME (22) Error, the name of the directory is invalid
ERR_DELETE_DIR (32) Error, the directory can not be deleted
DIR_NOT_EXIST (33) Error, the directory does not exist
ERR_RENAME_DIR (43) Error, the directory can not be renamed
DIR_ALREADY_EXIST (44) The NewDirectoryName alredy exists
CURRENT_DIR_NOT_EXIST (45) The CurrentDirectoryName does not exist
ERR_SCAN_DIR (60) Error, in the scan operation
NO_MORE_FILES (61) Error, there are no more files
ERR_DIR_FILE_NAME (62) Error in the file/directory name
ERR_CLOSING_DIR (63) Error, closing the search
Tbl. 1.73 Enumerator enDirRet.

Ingeteam Proprietary All Rights Reserved Pag. 111


1.4.1.1.6 Remarks

To use the DIR_CREATE function correctly, it is important to remember certain points:

The maximum string including the path and the name of the directory is 255 characters. If the
string assigned to the DirectoryName_STR parameter is more than 255 characters, only the first
255 characters will be considered and the directory will be created with that 255 character name.

The PLC may take more than one cycle to create the directory, depending on the load at that
moment. The 'Done_BL' flag indicates when the function has finished running.

1.4.1.1.7 Example

PROGRAM EXAMPLE

VAR

(*function declaration*)

DirCreate: DIR_CREATE;

(*input parameters*)

bEnableCreateDir: BOOL :=TRUE;

END_VAR

(*Create Directory*)

DirCreate( Enable_BL:= bEnableCreateDir,

DirectoryName_STR:= '\New Directory Name',

Done_BL =>,

Status_enDirRet => );

IF DirCreate.Done_BL = TRUE AND DirCreate.Status_enDirRet = OK_DIR

THEN

bEnableCreateDir := FALSE;

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 112


1.4.1.2 DIR_REMOVE

1.4.1.2.1 Description

This function removes an existing directory from the CFLASH memory.

This function deletes both the specified directory and the contents of the directory.

1.4.1.2.2 Syntax

FUNCTION_BLOCK DIR_REMOVE

VAR_INPUT

Enable_BL:BOOL;

DirectoryName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enDirRet:enDirRet;

END_VAR

1.4.1.2.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
DirectoryName_STR STRING(255) Name of the directory which is going to be removed.
Tbl. 1.74 Input parameters of function DIR_REMOVE.

1.4.1.2.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
OK_DIR: Correct execution
Status_enDirRet enDirRet
ERR_DIR_NAME: Error, the name of the directory is invalid
ERR_DELETE_DIR: Error, the directory can not be deleted
DIR_NOT_EXIST: Error, the directory does not exist
Tbl. 1.75 Output parameters of function DIR_REMOVE.

Ingeteam Proprietary All Rights Reserved Pag. 113


1.4.1.2.5 Data Types

1.4.1.2.5.1 enDirRet

Value Description
OK_DIR (0) Correct execution
ERR_CREATE_DIR (21) Error, the directory can not be creatted
ERR_DIR_NAME (22) Error, the name of the directory is invalid
ERR_DELETE_DIR (32) Error, the directory can not be deleted
DIR_NOT_EXIST (33) Error, the directory does not exist
ERR_RENAME_DIR (43) Error, the directory can not be renamed
DIR_ALREADY_EXIST (44) The NewDirectoryName alredy exists
CURRENT_DIR_NOT_EXIST (45) The CurrentDirectoryName does not exist
ERR_SCAN_DIR (60) Error, in the scan operation
NO_MORE_FILES (61) Error, there are no more files
ERR_DIR_FILE_NAME (62) Error in the file/directory name
ERR_CLOSING_DIR (63) Error, closing the search
Tbl. 1.76 Enumerator enDirRet.

1.4.1.2.6 Example

PROGRAM EXAMP

VAR

(*function declaration*)

DirRemove: DIR_REMOVE;

bEnableRemoveDir:BOOL:=TRUE;

END_VAR

(* Remove directory*)

DirRemove( Enable_BL:= bEnableRemoveDir,

DirectoryName_STR:=(*'\Renamed Directory Name',*)

Done_BL =>,

Status_enDirRet => );

IF DirRemove.Done_BL = TRUE AND DirRemove.Status_enDirRet = OK_DIR

THEN

bEnableRemoveDir:= FALSE;

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 114


1.4.1.3 DIR_RENAME

1.4.1.3.1 Description

This function renames an existing directory in the CFLASH memory.

1.4.1.3.2 Syntax

FUNCTION_BLOCK DIR_RENAME

VAR_INPUT

Enable_BL:BOOL;

CurrentDirectoryName_STR:STRING(255);

NewDirectoryName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enDirRet:enDirRet;

END_VAR

1.4.1.3.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
String of characters with the path of the directory we want to rename.
CurrentDirectoryName_STR STRING(255)
The string must start with the character '\'.
String of characters with the path of the new directory we want to create.
NewDirectoryName_STR STRING(255)
The string must start with the character '\'.
Tbl. 1.77 Input parameters of function DIR_RENAME.

1.4.1.3.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
OK_DIR: Correct execution
Status_enDirRet enDirRet ERR_DIR_NAME: Error, the name of the directory is invalid
ERR_RENAME_DIR: Error, the directory can not be renamed
DIR_ALREADY_EXIST: The NewDirectoryName alredy exists
CURRENT_DIR_NOT_EXIST: The CurrentDirectoryName does not exist
Tbl. 1.78 Output parameters of function DIR_RENAME.

Ingeteam Proprietary All Rights Reserved Pag. 115


1.4.1.3.5 Data Types

1.4.1.3.5.1 enDirRet

Value Description
OK_DIR (0) Correct execution
ERR_CREATE_DIR (21) Error, the directory can not be creatted
ERR_DIR_NAME (22) Error, the name of the directory is invalid
ERR_DELETE_DIR (32) Error, the directory can not be deleted
DIR_NOT_EXIST (33) Error, the directory does not exist
ERR_RENAME_DIR (43) Error, the directory can not be renamed
DIR_ALREADY_EXIST (44) The NewDirectoryName alredy exists
CURRENT_DIR_NOT_EXIST (45) The CurrentDirectoryName does not exist
ERR_SCAN_DIR (60) Error, in the scan operation
NO_MORE_FILES (61) Error, there are no more files
ERR_DIR_FILE_NAME (62) Error in the file/directory name
ERR_CLOSING_DIR (63) Error, closing the search
Tbl. 1.79 Enumerator enDirRet.

1.4.1.3.6 Remarks

To use the DIR_RENAME function correctly, it is important to remember certain points:

The maximum string including the path and the name of the directory is 255 characters. If the
string assigned to the CurrentDirectoryName_STR and NewDirectoryName_STR parameters is
more than 255 characters, only the first 255 characters will be considered and a directory will be
created with that 255 character name.

CFLASH must not have a directory with the same name as the directory to be created. The PLC
may take more than one cycle to create the directory, depending on the load at that moment.
The Done_BL flag indicates when the function has finished running.

The directory with the new name will retain all the elements that it contains in the same form as
the original directory.

1.4.1.3.7 Example

PROGRAM DIR_RENAME_Example

VAR

(*function declaration*)

DirRename: DIR_RENAME;

bEnableRenameDir :BOOL := TRUE;

END_VAR

DirRename( Enable_BL:= bEnableRenameDir,

Ingeteam Proprietary All Rights Reserved Pag. 116


CurrentDirectoryName_STR:='\New Directory Name' ,

NewDirectoryName_STR:='\Renamed Directory Name',

Done_BL =>,

Status_enDirRet => );

IF DirRename.Done_BL = TRUE AND DirRename.Status_enDirRet = OK_DIR

THEN

bEnableRenameDir := FALSE;

END_IF;

1.4.1.4 DIR_SCAN

1.4.1.4.1 Description

This function searches a directory for a file or a subdirectory whose name matches the specified
file name.

1.4.1.4.2 Syntax

FUNCTION_BLOCK DIR_SCAN

VAR_INPUT

Enable_BL:BOOL;

ScanName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

FoundNewElement_BL:BOOL;

FoundElement_stScanData:stScanData;

Status_enDirRet:enDirRet;

END_VAR

1.4.1.4.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL When Enable_BL is TRUE the scan will start, when this flag is set to

Ingeteam Proprietary All Rights Reserved Pag. 117


Input Parameter Name Type Description
FALSE, the scan will finish.
When the FB finishes (DONE_BL=TRUE), the FB has to be called with
Enable=FALSE.
Name of a valid directory or path and file name, which can contain wildcard
characters, such as * and ?.
ScanName_STR STRING(255) The first character must be '\'.
The last character can not be '\'.
To search all elements in the root directory, use '\*'.
Tbl. 1.80 Input parameters of function DIR_SCAN.

1.4.1.4.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
FoundNewElement_BL BOOL A new element has been found.
FoundElement_stScanData stScanData This structure describes the file/directory found.
Result of the FB execution.
Possible status values for this function:
OK_DIR: Correct execution
Status_enDirRet enDirRet
ERR_SCAN_DIR: Error in the scan operation
ERR_DIR_FILE_NAME:Error in the file/directory name
ERR_CLOSING_DIR:Error closing the search
Tbl. 1.81 Output parameters of function DIR_SCAN.

1.4.1.4.5 Data Types

1.4.1.4.5.1 enDirRet

Value Description
OK_DIR (0) Correct execution
ERR_CREATE_DIR (21) Error, the directory can not be creatted
ERR_DIR_NAME (22) Error, the name of the directory is invalid
ERR_DELETE_DIR (32) Error, the directory can not be deleted
DIR_NOT_EXIST (33) Error, the directory does not exist
ERR_RENAME_DIR (43) Error, the directory can not be renamed
DIR_ALREADY_EXIST (44) The NewDirectoryName alredy exists
CURRENT_DIR_NOT_EXIST (45) The CurrentDirectoryName does not exist
ERR_SCAN_DIR (60) Error, in the scan operation
NO_MORE_FILES (61) Error, there are no more files
ERR_DIR_FILE_NAME (62) Error in the file/directory name
ERR_CLOSING_DIR (63) Error, closing the search
Tbl. 1.82 Enumerator enDirRet.

Ingeteam Proprietary All Rights Reserved Pag. 118


1.4.1.4.5.2 stScanData

Field Name Type Description


Type_USI USINT Type of file: 1 for Directory 2 for File.
FileSize_UDI UDINT Size of the file.
FileName_STR STRING(255) Name of the file or directory.
Tbl. 1.83 Fields of the stScanData structure.

1.4.1.4.6 Remarks

The maximum string of text characters to search is 255. If the string assigned to the
ScanNameString_STR parameter is more than 255 characters, only the first 255 characters will
be considered and therefore the search will be performed for that 255 character name.

The search starts when Enable_BL is set to TRUE. The function performs the search according
to ScanNameString_STR, and each time an element is found, the FoundNewElement_BL flag is
set to TRUE for one cycle. The element data is stored in FoundElement_stScanData.

The result of the execution must be checked in Status_enDirRet. If no error occurred the function
indicates OK_DIR. If an error occurs during the search or while closing the search,
ERR_SCAN_DIR and ERR_CLOSING_DIR codes are returned respectively.

When no more elements are found the function finishes its execution, and the Done_BL flag is
set to TRUE. If Enable_BL is reset to FALSE the search is cancelled. Setting Enable_BL to
TRUE again will start a new search. If the function finishes with code OK_DIR and flag
FoundNewElement_BL was not set, then no file was found.

For the ScanNameString_STR parameter special characters like * and ? can be used. The
string's first character must be '\', and the last character can not be '\', otherwise the function will
fail and ERR_DIR_FILE_NAME will be returned in Status_enDirRet.

1.4.1.4.7 Example

PROGRAM DIR_SCAN_Example

VAR

DirScan: DIR_SCAN;

EnDirScan: BOOL;

DirToScan: STRING := '\*.txt';(*Search for text files in root dir*)

StatusDirScan: enDirRet;

ContFindElem: UDINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 119


(*Set this variable to TRUE to start the scan*)

IF EnDirScan

THEN

(*Check if the function has finished*)

IF DirScan.Done_BL

THEN

EnDirScan:=FALSE;

StatusDirScan:=DirScan.Status_enDirRet;

END_IF;

(*Call to the dir scan function*)

DirScan(

Enable_BL:=EnDirScan ,

ScanName_STR:=DirToScan ,

Done_BL=> ,

FoundNewElement_BL=> ,

FoundElement_stScanData=> ,

Status_enDirRet=> );

(*Counter of found elements*)

IF DirScan.FoundNewElement_BL

THEN

ContFindElem:=ContFindElem+1;

END_IF

END_IF

1.4.1.5 FILE_CREATE

1.4.1.5.1 Description

This function creates, opens or closes files in the CFLASH memory of the PLC.

Ingeteam Proprietary All Rights Reserved Pag. 120


1.4.1.5.2 Syntax

FUNCTION_BLOCK FILE_CREATE

VAR_INPUT

Enable_BL:BOOL;

FileName_STR:STRING(255);

Mode_STR:STRING(20);

END_VAR

VAR_OUTPUT

Id_DI:DINT;

Valid_BL:BOOL;

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

1.4.1.5.3 Input parameters

Input Parameter Name Type Description


When Enable_BL is TRUE a file is created,
Enable_BL BOOL
when this flag is set to FALSE, the file will be closed.
String of characters with the directory path and name of the file to be managed.
FileName_STR STRING(255)
The string must start with the character '\'.
Mode string can be one of the following values:
'Create ' = Create a new file (if exist, the old one is deleted).
Mode_STR STRING(20) 'Open' = Open an existing file.
'Append' = If the file doesn`t exist , the FB creates a new one.
If the file exists, the data is writted at the end of the file.
Tbl. 1.84 Input parameters of function FILE_CREATE.

Ingeteam Proprietary All Rights Reserved Pag. 121


1.4.1.5.4 Output parameters

Output Parameter Name Type Description


Id of the file is s numeric value that serves as a file identifier for
Id_DI DINT
subsequent read/write actions.
The ID is valid and can be used with the FB File_Read, File_Write,
Valid_BL BOOL
File_set_pointer
Done_BL BOOL The current operation (open or close) has finished.
Result of the FB execution.
Possible status values for this function:
OK_FILE: Correct execution
ERR_OPEN_MODE: Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE: Error, the close action has not finished properly
Status_enFileRet enFileRet ERR_OPENIG_FILE: Error, the open action has not finished properly
FILE_ALREADY_OPEN: Error, the file which is going to be open is
being used by another
FILE_CREATE FB
ERR_CREATE_FILE_NAME:
FILE_CREATE: Error in the file name
Tbl. 1.85 Output parameters of function FILE_CREATE.

1.4.1.5.5 Data Types

1.4.1.5.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the
ERR_ADDR_BUFFER (24)
buffer where the data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
Error, invalid Id_DI parameter OR The CurrentFileName is being used
ERR_ACCESS_FILE (28)
by another FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.86 Enumerator enFileRet.

Ingeteam Proprietary All Rights Reserved Pag. 122


1.4.1.5.6 Remarks

To use the FILE_CREATE function correctly, it is important to remember certain points:

The maximum string including the path and the name of the file is 255 characters. If the string
assigned to the FileName_STR parameter is more than 255 characters, only the first 255
characters will be considered and a file will be created with that 255 character name.

To perform other actions, there must not be a file in the CFLASH memory that is the same as the
one in use.

The PLC may take more than one cycle to create the file, depending on the load at that moment.
The Done_BL flag indicates when the function has finished running.

The function has three operating modes for file management that are marked by the Mode_STR
parameter:

Create: For when we want to create a new file with the specified name. If this file does not exist
on the disk, it will be created. If a file with the same name already exists on the disk, it will be
deleted and a new empty file with the same name is created.

Open: For when we want to open a file that already exists in the disk without losing the data it
may contain to perform read/write actions. The file index is placed at the beginning of the file.
Therefore, if we write in the file, the existing data will be overwritten.

Append: For when we want to open a file that already exists on the disk without losing the data it
may contain to perform read/write actions. The list file index is placed at the end of the file.
Therefore, if we write in the file, the new data will be added to the existing data.

1.4.1.5.7 Example

PROGRAM EXAMPLE

VAR

FileCreate:FILE_CREATE;

enableCreate:BOOL :=TRUE;

END_VAR

FileCreate( Enable_BL:= enableCreate,

Mode_STR:='Create' ,

FileName_STR :='\NewFileName',(*'\A\B\C\NewFileName' , *)

Id_DI=>,

Valid_BL=>,

Ingeteam Proprietary All Rights Reserved Pag. 123


Done_BL =>,

Status_enFileRet => );

IF FileCreate.Done_BL = TRUE AND FileCreate.Status_enFileRet = OK_FILE

THEN

enableCreate := FALSE;

END_IF;

1.4.1.6 FILE_DELETE

1.4.1.6.1 Description

This function deletes a previously created file in the non volatile memory of the INGESYS IC3
CPU.

1.4.1.6.2 Syntax

FUNCTION_BLOCK FILE_DELETE

VAR_INPUT

Enable_BL:BOOL;

FileName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

1.4.1.6.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
String of characters with the path and name of the file we want to
FileName_STR STRING(255) delete.
The string must start with the character '\'.
Tbl. 1.87 Input parameters of function FILE_DELETE.

Ingeteam Proprietary All Rights Reserved Pag. 124


1.4.1.6.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
Result of the FB execution:Possible status values for this function:
OK_FILE: Correct execution
Status_enFileRet enFileRet ERR_DELETING_FILE: Error in the delete operation
ERR_DELETE_FILE_NAME: Error in the file name
NO_FILE: The system cannot find the file specified.
Tbl. 1.88 Output parameters of function FILE_DELETE.

1.4.1.6.5 Data Types

1.4.1.6.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the buffer
ERR_ADDR_BUFFER (24)
where the data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
Error, invalid Id_DI parameter OR The CurrentFileName is being used by
ERR_ACCESS_FILE (28)
another FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.89 Enumerator enFileRet.

1.4.1.6.6 Remarks

To use the FILE_DELETE function correctly, it is important to remember certain points:

The file to delete must not be in use at that time.

The PLC may take more than one cycle to delete the file, depending on the load at that moment.
The Done_BL flag indicates when the function has finished running.

Pay special attention not to surpass the 255 character limit in the file names (path+name).

Ingeteam Proprietary All Rights Reserved Pag. 125


1.4.1.6.7 Example

PROGRAM FILE_DELETE_Example

VAR

FileDelete:FILE_DELETE;

enableDelete:BOOL :=TRUE;

END_VAR

FileDelete( Enable_BL:= enableDelete,

FileName_STR:='\NewFileName',

Done_BL =>,

Status_enFileRet =>)

IF FileDelete.Done_BL=TRUE AND FileDelete.Status_enFileRet=OK_FILE

THEN

enableDelete:=FALSE;

END_IF;

1.4.1.7 FILE_READ

1.4.1.7.1 Description

This function reads data from a file in the CFLASH memory and stores it in a program buffer.

The file that is read is identified by an identifier obtained during the FILE_CREATE operation.

1.4.1.7.2 Syntax

FUNCTION_BLOCK FILE_READ

VAR_INPUT

Enable_BL:BOOL;

Id_DI:DINT;

DataReadBuffer_ADDR:DWORD;

NumberOfBytesToRead_DI:DINT;

END_VAR

VAR_OUTPUT

Ingeteam Proprietary All Rights Reserved Pag. 126


NumberOfBytesRead_DI:DINT;

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

1.4.1.7.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
Identifier of the file to be read.
Id_DI DINT
This identifier is obtained from the FILE_CREATE function.
Address of the data buffer where the data read will be stored.
DataReadBuffer_ADDR DWORD
Enough space must be reserved for the data that is read.
NumberOfBytesToRead_DI DINT Number of bytes to be read from the file.
Tbl. 1.90 Input parameters of function FILE_READ.

1.4.1.7.4 Output parameters

Output Parameter Name Type Description


NumberOfBytesRead_DI DINT Number of bytes read from the file.
Done_BL BOOL Indicates that the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
OK_FILE: Correct execution
ERR_ADDR_BUFFER :The addressof the buffer where the data is going to be
copied is invalid.
Status_enFileRet enFileRet
ERR_NUM_BYTES :The number of bytes to read is invalid.
ERR_READING_FILE: Error in the read operation
ERR_ACCESS_FILE:Error, invalid Id_DI parameter
ERR_READ_NUM_DATA: Error, it has been read less data than the expected
data (NumberOfBytesRead_DI &lt; NumberOfBytes)
Tbl. 1.91 Output parameters of function FILE_READ.

Ingeteam Proprietary All Rights Reserved Pag. 127


1.4.1.7.5 Data Types

1.4.1.7.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the buffer
ERR_ADDR_BUFFER (24)
where the data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
Error, invalid Id_DI parameter OR The CurrentFileName is being used by another
ERR_ACCESS_FILE (28)
FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.92 Enumerator enFileRet.

1.4.1.7.6 Remarks

To use the FILE_READ function correctly, it is important to remember certain points:

The PLC may take more than one cycle to read the file, depending on the load at that moment.
The Done_BL flag indicates when the function has finished running.

A memory buffer should be reserved with enough space for the data to be read.

Before reading the file, first open the file with the FILE_CREATE function to obtain a file
identifier.

Ingeteam Proprietary All Rights Reserved Pag. 128


1.4.1.7.7 Example

PROGRAM FILE_READ_Example

VAR

(*Create file before to write*)

FileCreate :FILE_CREATE;

enableCreate :BOOL :=TRUE;

Mode :ARRAY [0..2] OF STRING:='Append','Open','Create';

iMode :INT := 1;

Id_DI :DINT;

(*Write*)

Write :FILE_WRITE;

Buffer_Write :STRING:='Hello ' ;

enableWrite :BOOL :=TRUE;

nTest :INT :=0;

END_VAR

CASE nTest OF

1: (* FileCreate:FILE_CREATE*)

FileCreate( Enable_BL:= enableCreate,

Mode_STR:= Mode[iMode],

FileName_STR := (* '\NewFileName' ,*) '\A\B\C\NewFileName' ,

Id_DI=>,

Valid_BL=>,

Done_BL =>,

Status_enFileRet => );

IF FileCreate.Done_BL = TRUE AND FileCreate.Status_enFileRet = OK_FILE

THEN

FileCreate.Id_DI;

enableCreate := FALSE;

nTest := 2;

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 129


2: (* Read the word "Hello" *)

Read( Enable_BL:=enableRead ,

Id_DI:=FileCreate.Id_DI ,

DataReadBuffer_ADDR:=ADR(Buffer_Read) ,

NumberOfBytesToRead_DI:=SIZEOF(Buffer_Read) ,

NumberOfBytesRead_DI=> ,

Done_BL=> ,

Status_enFileRet=> );

IF Read.Done_BL = TRUE

THEN

enableRead := FALSE;

END_IF

END_CASE

1.4.1.8 FILE_RENAME

1.4.1.8.1 Description

This function renames an existing file in the CFLASH memory.

1.4.1.8.2 Syntax

FUNCTION_BLOCK FILE_RENAME

VAR_INPUT

Enable_BL:BOOL;

CurrentFileName_STR:STRING(255);

NewFileName_STR:STRING(255);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 130


1.4.1.8.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
String of characters with the path and name of the file we want to rename.
CurrentFileName_STR STRING(255)
The string must start with the character '\'.
String of characters with the path and name of the new file.
NewFileName_STR STRING(255)
The string must start with the character '\'.
Tbl. 1.93 Input parameters of function FILE_RENAME.

1.4.1.8.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates that the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
OK_FILE: Correct execution
Status_enFileRet enFileRet ERR_ACCESS_FILE: Error, The CurrentFileName is being used by another
FB. ERR_RENAMING_FILE: Error in the rename operation.
NO_CURRENT_FILE: The file CurrentFileName_STR does not exist
ERR_RENAME_FILE_NAME: FILE_RENAME: Error in the file name
Tbl. 1.94 Output parameters of function FILE_RENAME.

1.4.1.8.5 Data Types

1.4.1.8.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the buffer
ERR_ADDR_BUFFER (24)
where the data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
Error, invalid Id_DI parameter OR The CurrentFileName is being used by another
ERR_ACCESS_FILE (28)
FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.95 Enumerator enFileRet.

Ingeteam Proprietary All Rights Reserved Pag. 131


1.4.1.8.6 Remarks

To use the DIR_RENAME function correctly, it is important to remember certain points:

The maximum string including the path and the name of the directory is 255 characters. If the
string assigned to the CurrentDirectoryName_STR and NewDirectoryName_STR parameters is
more than 255 characters, only the first 255 characters will be considered and a directory will be
created with that 255 character name.

CFLASH must not have a directory with the same name as the directory to be created.

The PLC may take more than one cycle to create the directory, depending on the load at that
moment. The Done_BL flag indicates when the function has finished running.

The directory with the new name will retain all the elements that it contains in the same form as
the original directory.

1.4.1.8.7 Example

PROGRAM FILE_RENAME_Example

VAR

FileRename:FILE_RENAME;

bEnableRenameFile :BOOL:=TRUE;

END_VAR

FileRename( Enable_BL:= bEnableRenameFile,

CurrentFileName_STR:='\FileName',

NewFileName_STR:='\RenamedFileName',

Done_BL=>,

Status_enFileRet=> );

1.4.1.9 FILE_SET_POINTER

1.4.1.9.1 Description

This function moves the file pointer to the position specified by the user.

Ingeteam Proprietary All Rights Reserved Pag. 132


1.4.1.9.2 Syntax

FUNCTION_BLOCK FILE_SET_POINTER

VAR_INPUT

Enable_BL:BOOL;

Id_DI:DINT;

NumberOfBytesToMove_DI:DINT;

MoveMethod_STR:STRING(20);

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

1.4.1.9.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
Identifier of the file to be read.
Id_DI DINT
This identifier is obtained from the FILE_CREATE function.
NumberOfBytesToMove_DI DINT Specifies the number of bytes to move the file pointer.
The starting point for the file pointer move.
This string can be one of the following values:
MoveMethod_STR STRING(20) 'Begin': The starting point is the beginning of the file.
'Current': The starting point is the current value of the file pointer.
'End': The starting point is the current end-of-file position.
Tbl. 1.96 Input parameters of function FILE_SET_POINTER.

1.4.1.9.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Indicates if the execution of the FB has finished.
Result of the FB execution.
Possible status values for this function:
OK_FILE: Correct execution
Status_enFileRet enFileRet ERR_ACCESS_FILE: Error, invalid Id_DI parameter
ERR_NUM_BYTES:The new file pointer is a negative value
ERR_SET_FILE_POINTER:Error while setting the file pointer
ERR_SET_POINTER_METHOD:Invalid MoveMethod_DI parameter
Tbl. 1.97 Output parameters of function FILE_SET_POINTER.

Ingeteam Proprietary All Rights Reserved Pag. 133


1.4.1.9.5 Data Types

1.4.1.9.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the buffer where
ERR_ADDR_BUFFER (24)
the data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
ERR_ACCESS_FILE (28) Error, invalid Id_DI parameter OR The CurrentFileName is being used by another FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.98 Enumerator enFileRet.

1.4.1.9.6 Remarks

If Enable_BL is FALSE the function is disabled. If Enable_BL is TRUE the function will set the file
pointer of the file identified by Id_DI, accordingly to the method and number of bytes specified in
the input parameters MoveMethod_DI and NumberOfBytesToMove_DI.

The function will continue to set the pointer while Enable_BL is TRUE, so the user must reset
Enable_BL to FALSE after the function execution terminates.

When the function finishes executing, the output parameter Done_BL is set to TRUE. The
Status_enFileRet parameter must be checked in order to know the result of the execution. If the
function succeeded, Status_enFileRet is OK_FILE and the file pointer has been set correctly.
Any other value of Status_enFileRet indicates error.

The Id_DI input parameter indentifies the file which pointer is going to be moved. The identifier
must be a valid file identifier obtained with a previous call to the FILE_CREATE function. If Id_DI
does not correspond to a valid file identifier, the function fails with ERR_ACCESS_FILE code.

Ingeteam Proprietary All Rights Reserved Pag. 134


MoveMethod_DI indicates the starting point from which to move the file pointer. The starting
point can be the beginning of the file, the current position, or the enf-of-file. See the table above
for the possible values and its meaning.

Input parameter NumberOfBytesToMove_DI can be either a positive or negative value. When its
value is positive, the file pointer is moved forward from the starting position. When it is negative it
is moved backwards. If the new pointer position is a negative value, the function fails, the pointer
is not moved, and Status_enFileRet is ERR_NUM_BYTES.

It is not an error to set a file pointer to a position beyond the end of the file. The size of the file
does not increase until you call the FILE_WRITE function. A write operation increases the size of
the file to the file pointer position plus the size of the buffer written, which results in the
intervening bytes uninitialized.

1.4.1.9.7 Example

PROGRAM

VAR

fcreate: FILE_CREATE;

fseek: FILE_SET_POINTER;

fread: FILE_READ;

fwrite: FILE_WRITE;

encreate: BOOL;

enfread: BOOL;

enfseek: BOOL;

enfwrite: BOOL;

fid: DINT;

write_buffer: STRING;

read_buffer: STRING;

run_example: BOOL;

END_VAR

(*Create the file*)

IF NOT fcreate.Valid_BL AND run_example

THEN

encreate := TRUE;

Ingeteam Proprietary All Rights Reserved Pag. 135


END_IF;

(*Write the 'Hello world!' text into the file*)

IF fcreate.Done_BL

THEN

IF fcreate.Valid_BL

THEN

write_buffer := 'Hello world!';

enfwrite := TRUE;

END_IF;

END_IF;

(*Move the file pointer 6 bytes past the beginning of the file*)

IF fwrite.Done_BL

THEN

IF fwrite.Status_enFileRet = OK_FILE

THEN

enfseek := TRUE;

END_IF;

enfwrite := FALSE;

END_IF;

(*Read 5 bytes. The string read will be 'world'*)

IF fseek.Done_BL

THEN

IF fseek.Status_enFileRet = OK_FILE

THEN

enfread := TRUE;

END_IF;

enfseek := FALSE;

END_IF;

(*End of the example, close the file*)

IF fread.Done_BL

Ingeteam Proprietary All Rights Reserved Pag. 136


THEN

enfread := FALSE;

encreate := FALSE;

run_example := FALSE;

END_IF;

(*Calling of the functions*)

fcreate(

Enable_BL:= encreate,

FileName_STR:= '\file.txt',

Mode_STR:= 'Create',

Id_DI=> fid,

Valid_BL=> ,

Done_BL=> ,

Status_enFileRet=> );

fwrite(

Enable_BL:= enfwrite,

Id_DI:= fid,

DataSourceBuffer_ADDR:=ADR(write_buffer),

NumberOfBytesToWrite_DI:=12,

NumberOfBytesWritten_DI=>,

Done_BL=> ,

Status_enFileRet=> );

fseek(

Enable_BL:= enfseek,

Id_DI:= fid,

NumberOfBytesToMove_DI:=6,

MoveMethod_DI:=1,(*starting point = beginning of the file*)

Done_BL=> ,

Status_enFileRet=> );

fread(

Ingeteam Proprietary All Rights Reserved Pag. 137


Enable_BL:= enfread,

Id_DI:= fid,

DataReadBuffer_ADDR:= ADR(read_buffer),

NumberOfBytesToRead_DI:= 5,

NumberOfBytesRead_DI=> ,

Done_BL=> ,

Status_enFileRet=> );

1.4.1.10 FILE_WRITE

1.4.1.10.1 Description

This function writes data from a buffer program in a CFLASH memory file.

The file that is read is identified by an identifier obtained during the FILE_CREATE operation.

1.4.1.10.2 Syntax

FUNCTION_BLOCK FILE_WRITE

VAR_INPUT

Enable_BL:BOOL;

Id_DI:DINT;

DataSourceBuffer_ADDR:DWORD;

NumberOfBytesToWrite_DI:DINT;

END_VAR

VAR_OUTPUT

NumberOfBytesWritten_DI:DINT;

Done_BL:BOOL;

Status_enFileRet:enFileRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 138


1.4.1.10.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable the execution of the FB.
Identifier of the file to be written.
Id_DI DINT
This identifier is obtained by the FILE_CREATE function.
Address of the data buffer from which to obtain the data to be written.
DataSourceBuffer_ADDR DWORD
The buffer size must correspond to that of the data to be written.
NumberOfBytesToWrite_DI DINT Number of bytes to be written in the file.
Tbl. 1.99 Input parameters of function FILE_WRITE.

1.4.1.10.4 Output parameters

Output Parameter Name Type Description


NumberOfBytesWritten_DI DINT Number of bytes written in the file.
Done_BL BOOL Indicates that the execution of the FB has finished
Result of the FB execution
Possible status values for this function:
OK_FILE: Correct execution
Status_enFileRet enFileRet ERR_ADDR_BUFFER :The address of the source buffer is invalid.
ERR_NUM_BYTES :The number of bytes to write is invalid.
ERR_WRITING_FILE: Error in the write operation.
ERR_ACCESS_FILE: Error, invalid Id_DI parameter DISK_FULL
Tbl. 1.100 Output parameters of function FILE_WRITE.

Ingeteam Proprietary All Rights Reserved Pag. 139


1.4.1.10.5 Data Types

1.4.1.10.5.1 enFileRet

Value Description
OK_FILE (0) Correct execution
ERR_OPEN_MODE (20) Parameter Mode_STR has an invalid value
ERR_CLOSING_FILE (21) Error, the close action has not finished properly
ERR_OPENIG_FILE (22) Error, the open action has not finished properly
FILE_ALREADY_OPEN (23) Error, the open action has not finished properly
The address of the source buffer (write operations) or the addressof the buffer where the
ERR_ADDR_BUFFER (24)
data is going to be copied(read operation) is invalid
ERR_NUM_BYTES (25) The number of bytes to read, write or move file pointer is invalid
ERR_READING_FILE (26) Error in the read operation
ERR_WRITING_FILE (27) Error in the write operation
ERR_ACCESS_FILE (28) Error, invalid Id_DI parameter OR The CurrentFileName is being used by another FB
ERR_READ_NUM_DATA (29) Error, it has been read less data than the expected data
ERR_CREATE_FILE_NAME (30) Error in the file name
ERR_RENAME_FILE_NAME (31) Error in the file name
DISK_FULL (32) The repository of the processor is running with very low space
ERR_DELETING_FILE (33) Error in the delete operation
ERR_DELETE_FILE_NAME (34) Error in the file name
NO_FILE (35) The system cannot find the file specified
ERR_SET_FILE_POINTER (36) Error while setting the file pointer
ERR_SET_POINTER_METHOD (37) Invalid MoveMethod_DI parameter
ERR_RENAMING_FILE (50) Error in the rename operation
NO_CURRENT_FILE (51) The CurrentFileName does not exist
Tbl. 1.101 Enumerator enFileRet.

1.4.1.10.6 Remarks

To use the FILE_WRITE function correctly, it is important to remember certain points:

The PLC may take more than one cycle to write the file, depending on the load at that moment.
The Done_BL flag indicates when the function has finished running.

The maximum amount of data to write must correspond to the size of the buffer that contains the
written data, although this amount of data may be less than the size of the buffer.

Before writing the file, first open the file with the FILE_CREATE function to obtain a file identifier.

1.4.1.10.7 Example

PROGRAM FILE_WRITE_Example

VAR

(*Create file before to write*)

FileCreate :FILE_CREATE;

Ingeteam Proprietary All Rights Reserved Pag. 140


enableCreate :BOOL :=TRUE;

Mode :ARRAY [0..2] OF STRING:='Append','Open','Create';

iMode :INT := 0;

Id_DI :DINT;

(*Write*)

Write :FILE_WRITE;

Buffer_Write :STRING:='Hello ' ;

enableWrite :BOOL :=TRUE;

nTest :INT :=0;

END_VAR

CASE nTest OF

1: (* FileCreate:FILE_CREATE*)

FileCreate( Enable_BL:= enableCreate,

Mode_STR:= Mode[iMode],

FileName_STR := (* '\NewFileName' ,*) '\A\B\C\NewFileName' ,

Id_DI=>,

Valid_BL=>,

Done_BL =>,

Status_enFileRet => );

IF FileCreate.Done_BL = TRUE AND FileCreate.Status_enFileRet = OK_FILE

THEN

FileCreate.Id_DI;

enableCreate := FALSE;

nTest := 2;

END_IF;

2: (* Write the word "Hello" *)

Write( Enable_BL:= enableWrite,

Id_DI:= FileCreate.Id_DI ,

DataSourceBuffer_ADDR:=ADR( Buffer_Write ) ,

NumberOfBytesToWrite_DI:= SIZEOF (Buffer_Write) ,

Ingeteam Proprietary All Rights Reserved Pag. 141


NumberOfBytesWritten_DI=> ,

Done_BL=> ,

Status_enFileRet=> );

IF Write.Done_BL = TRUE

THEN

enableWrite := FALSE;

END_IF

END_CASE

1.4.1.11 LIST_CREATE

1.4.1.11.1 Description

This function is used to create a list of elements.

1.4.1.11.2 Syntax

FUNCTION_BLOCK LIST_CREATE

VAR_INPUT

ElemNbytes_DI:DINT;

NumElem_DI:DINT;

ListName_STR:STRING(32);

ListRetain_BL:BOOL;

VarRetain_ADDR:DWORD;

VarRetainSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

IdList_UDI:UDINT;

Status_enListRet:enListRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 142


1.4.1.11.3 Input parameters

Input Parameter Name Type Description


ElemNbytes_DI DINT Length in bytes of the data associated with the list element.
NumElem_DI DINT Maximum number of elements in the list.
ListName_STR STRING(32) Name of the list.
ListRetain_BL BOOL Set this variable with TRUE if this List is going to be retain.
VarRetain_ADDR DWORD Address of the retain variable used for the retain list.
Size of the retain variable used for the retain list.
VarRetainSizeBy_DI DINT
Calculated as:. arRetainSizeBy_DI >= 100 + (ElemNbytes_DI+53)*NumElem_DI.
Tbl. 1.102 Input parameters of function LIST_CREATE.

1.4.1.11.4 Output parameters

Output Parameter Name Type Description


IdList_UDI UDINT List identier, input for: LIST_GET, LIST_INSERT, and LIST_REMOVE functions.
Result of the FB execution.
Possible status values for this function:
OK_LIST: Correct execution
Status_enListRet enListRet ERR_CREATE_VALUE_PARAMS: Error creating list.
One input param value is incorrect
NO_MEMORY_SPACE: No space in memory
TOO_MUCH_LIST: Too much number of list.
Tbl. 1.103 Output parameters of function LIST_CREATE.

Ingeteam Proprietary All Rights Reserved Pag. 143


1.4.1.11.5 Data Types

1.4.1.11.5.1 enListRet

Value Description
OK_LIST (0) Correct execution
ERR_MODE (1) Error in function mode
LIST_NO_VALID (2) List no valid
LIST_EMPTY (3) LIST Empty
ERR_ADDR_DATA (4) Address Data No Valid
ERR_ID (5) Id Not Found
ERR_NAME (6) Name Not Found
VALUE_NOT_FOUND (7) Value Not Found
ElementToFind_ST.DataSize_DI > ElemSize of the LIST or
WARN_GET_ELEMENT_DATA_SIZE (8)
ElementToFind_ST.DataSize_DI > FoundElement_ST.DataSize_DI
ERR_DATA_SIZE (9) Element data size no valid
ERR_NUM_ELEMENT (10) Too Much Elements
ERR_CREATE_VALUE_PARAMS (11) Error creating list. One input parameter value is incorrect.
NO_MEMORY_SPACE (12) No space in memory
TOO_MUCH_LIST (13) Too much number of list
ElementToInsert_ST.DataSize_DI > ElemSize of the LIST or
WARN_INSERT_ELEMENT_DATA_SIZE (14) ElementToRemove_ST.DataSize_DI
>RemovedElement_ST.DataSize_D I
WARN_REMOVE_ELEMENT_DATA_SIZE (15)
ERR_VarRetainSize (16) Function.VarRetainSizeBY_DI < LIST_CREATE.VarRetainSizeBY_DI
WARN_LIST_ALREADY_EXIST (17)
ERR_RetainADDR_OCCUPIED (18)
Tbl. 1.104 Enumerator enListRet.

1.4.1.11.6 Remarks

To use the LIST_CREATE function correctly, it is important to remember certain points:

In case of using RAM memory the space reserved for lists is 512KB. If this is exceeded, the
LIST_CREATE function will return Status_enListRet:=NO_MEMORY_SPACE.

In case of using retain memory the user must define a retain variable to store the list, the size of
this variable must be as follows:

Size for CPU IC3101 = (100+(ElemNbytes_DI+53)*NumElem_DI)

Size for CPU IC3121 and IC3141 = (100+(ElemNbytes_DI+60)*NumElem_DI)

The maximum number of lists that can be created in the PLC at one time is 20. If this amount is
exceeded, the LIST_CREATE function will return ?Status_enListRet?:=TOO_MUCH_LIST.

The value returned in the IdList_UDI field must be saved for future use by the remaining list
functions.

Ingeteam Proprietary All Rights Reserved Pag. 144


1.4.1.11.7 Example

PROGRAM EXAMPLE

VAR CONSTANT

NUM_OF_WEEKEND_DAYS: DINT := 3;

SIZE_OF_ELEMENT: DINT := 32;

(* Buffer size = 100 + numElements * (sizElement + 60) = 376*)

BUFFER_SIZE:DINT := 376;

END_VAR

VAR

bListCreated: BOOL;

ListCreate: LIST_CREATE := (ListName_STR:='WeekDaysLst' );

StrDay : STRING(32);

END_VAR

IF NOT bListCreated

THEN

(* CREATE a Day LIST*)

ListCreate( ListName_STR:='WeekDaysLst',

ElemNbytes_DI := BUFFER_SIZE,

NumElem_DI := NUM_OF_WEEKEND_DAYS,

IdList_UDI=> (*IdDaysList*),

Status_enListRet=> (*Status_enList*) );

IF (OK_LIST = ListCreate.Status_enListRet)

THEN

bListCreated := TRUE;

(* Add List manipulation code here *)

END_IF

END_IF

Ingeteam Proprietary All Rights Reserved Pag. 145


1.4.1.12 LIST_GET

1.4.1.12.1 Description

The LIST_GET function obtains a specific element contained in a list.

The function returns the information contained in this element, but does not extract it from the
list, so it can be consulted again later.

1.4.1.12.2 Syntax

FUNCTION_BLOCK LIST_GET

VAR_INPUT

IdList_UDI:UDINT;

Mode_STR:STRING(20);

ElementToFind_stElement:stElement;

VarRetainSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

FoundElement_stElement:stElement;

CopyNBytes_DI:DINT;

Status_enListRet:enListRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 146


1.4.1.12.3 Input parameters

Input Parameter Name Type Description


IdList_UDI UDINT The identifier of the list from which we wish to obtain the element.
Function Mode. 'GetById':
This performs the search for the element using the
ElementToFind_stElement.Id_UDI field. 'GetByName':
This performs the search for the element using the
ElementToFind_stElement.Name_STR field. 'GetByValue':
This performs the search for the element using the
Mode_STR STRING(20) ElementToFind_stElement.Value_R field. 'GetBiggest':
This obtains the element using the ElementToFind_stElement.Value_R field.
'GetSmallest':
This obtains the element using the ElementToFind_stElement.Value_R field.
'GetHead':
This obtains the element in the first position in the list. 'GetTail': This obtains
the element in the last position in the list.
ElementToFind_stElement stElement Description of the element to be obtained from the list.
Size of the retain variable used for the retain list.
VarRetainSizeBy_DI DINT
Must be >= List_Create.VarRetainSizeBy_DI.
Tbl. 1.105 Input parameters of function LIST_GET.

1.4.1.12.4 Output parameters

Output Parameter Name Type Description


The function returns the element found in the list in an 'stElement' type
FoundElement_stElement stElement
structure.
The number of bytes copied from the data associated to the element.
This will be the minimum number of bytes between the
CopyNBytes_DI DINT 'ElementToFind_stElement.DataSize_DI' fields of the element to search for,
the 'FoundElement_stElement.DataSize_DI' field of the found element, and
the 'ElemNbytes_DI' field of the LIST_CREATE function when creating the
list.
Result of the FB execution.
Possible status values for this function:
OK_LIST: Correct execution
ERR_MODE: Error in function mode
LIST_NO_VALID: List no valid
LIST_EMPTY: LIST Empty
ERR_ADDR_DATA:Address
Status_enListRet enListRet Data No Valid
ERR_ID: Id Not Found
ERR_NAME: Name Not Found
VALUE_NOT_FOUND:Value Not Found
WARN_GET_ELEMENT_DATA_SIZE:
ElementToFind_ST.DataSize_DI > ElemSize of the LIST or
ElementToFind_ST.DataSize_DI > FoundElement_ST.DataSize_DI
ERR_DATA_SIZE: Element data size no valid.
Tbl. 1.106 Output parameters of function LIST_GET.

Ingeteam Proprietary All Rights Reserved Pag. 147


1.4.1.12.5 Data Types

1.4.1.12.5.1 enListRet

Value Description
OK_LIST (0) Correct execution
ERR_MODE (1) Error in function mode
LIST_NO_VALID (2) List no valid
LIST_EMPTY (3) LIST Empty
ERR_ADDR_DATA (4) Address Data No Valid
ERR_ID (5) Id Not Found
ERR_NAME (6) Name Not Found
VALUE_NOT_FOUND (7) Value Not Found
ElementToFind_ST.DataSize_DI > ElemSize of the LIST or
WARN_GET_ELEMENT_DATA_SIZE (8)
ElementToFind_ST.DataSize_DI > FoundElement_ST.DataSize_DI
ERR_DATA_SIZE (9) Element data size no valid
ERR_NUM_ELEMENT (10) Too Much Elements
ERR_CREATE_VALUE_PARAMS (11) Error creating list. One input parameter value is incorrect.
NO_MEMORY_SPACE (12) No space in memory
TOO_MUCH_LIST (13) Too much number of list
ElementToInsert_ST.DataSize_DI > ElemSize of the LIST or
WARN_INSERT_ELEMENT_DATA_SIZE (14) ElementToRemove_ST.DataSize_DI >RemovedElement_ST.DataSize_D
I
WARN_REMOVE_ELEMENT_DATA_SIZE (15)
ERR_VarRetainSize (16) Function.VarRetainSizeBY_DI < LIST_CREATE.VarRetainSizeBY_DI
WARN_LIST_ALREADY_EXIST (17)
ERR_RetainADDR_OCCUPIED (18)
Tbl. 1.107 Enumerator enListRet.

1.4.1.12.5.2 stElement

Field Name Type Description


Id_UDI UDINT Id of the element.
Name_STR STRING(32) Name of the element.
Value_R REAL Real Value of the element.
DataSize_DI DINT Size of the Data Buffer.
Data_ADDR DWORD Start address of the data buffer.
Tbl. 1.108 Fields of the stElement structure.

1.4.1.12.6 Remarks

To use the LIST_GET function correctly, it is important to remember certain points:

The fields of the ElementToFind_stElement structure must be fully configured before proceeding
with the call to function.

The ElementToFind.Data_ADDR field must contain a valid address in which to keep the data
received, therefore, memory space must be reserved for this data of the found element.

Ingeteam Proprietary All Rights Reserved Pag. 148


We recommend you check whether Status_enListRet:=WARN_GET_ELEMENT_DATA_SIZE
has been returned, since this indicates that the expected number of bytes have not been copied
to the ElementToFind_stElement.DataSize_DI.

It is important to maintain the relation between the Mode_STR search criteria parameter and the
information used to perform the search for the ElementToFind_stElement.

In cases where the criteria used to get the element has several elements in the list that can be
used as reference, the function will use the first one it finds in the list as the reference.

1.4.1.12.7 Example

PROGRAM EXAMPLE

VAR

ContadorDeCiclos :DINT;

nTest :DINT := 0;

InsertListElement :BOOL;

END_VAR

VAR CONSTANT

NUM_OF_WEEKEND_DAYS: DINT := 3;

SIZE_OF_ELEMENT: DINT := 32;

(* Buffer size = 100 + numElements * (sizElement + 60) = 376*)

BUFFER_SIZE:DINT := 376;

END_VAR

VAR

bListCreated: BOOL;

bFridayInserted: BOOL;

bSaturdayInserted: BOOL;

bSundayInserted: BOOL;

idList: UDINT;

statusList: enListRet;

aTemperatures:ARRAY [1..NUM_OF_WEEKEND_DAYS] OF REAL:= 30.0, 22.9, 27.0;

END_VAR

VAR

Ingeteam Proprietary All Rights Reserved Pag. 149


(*LIST_CREATE*)

ListCreate: LIST_CREATE := (ListName_STR:='WeekDaysLst' );

(*input parameters*)

StrDay : STRING(32);

aInfoDay: ARRAY[1..NUM_OF_WEEKEND_DAYS] OF STRING(32);

(*LIST_INSERT*)

ListInsert:LIST_INSERT;

stElementToInsert: stElement;

stReference: stElement;

(*output parameters*)

Status: enListRet;

CopiedBytes: DINT;

(*LIST_GET*)

GetListElement: LIST_GET;

stFoundElement: stElement;

bSaturdayFound :BOOL;

END_VAR

IF NOT bListCreated

THEN

(* CREATE a Day LIST*)

ListCreate( ListName_STR:='WeekDaysLst',

ElemNbytes_DI := SIZEOF(StrDay),

NumElem_DI := NUM_OF_WEEKEND_DAYS,

IdList_UDI=>(*IdDaysList*) ,

Status_enListRet=>(*Status_enList*) );

IF (OK_LIST = ListCreate.Status_enListRet)

THEN

bListCreated := TRUE;

(* Add List manipulation code here *)

StrDay := 'mi Saturday' ;

Ingeteam Proprietary All Rights Reserved Pag. 150


(* ADD Saturday:(Saturday,,)*)

(*Define element to insert*)

stElementToInsert.Id_UDI:=2;

stElementToInsert.Name_STR := 'Saturday' ;

stElementToInsert.Value_R:=aTemperatures[stElementToInsert.Id_UDI ];

stElementToInsert.DataSize_DI:=SIZEOF( StrDay );

stElementToInsert.Data_ADDR:=ADR( StrDay );

StrDay:=stElementToInsert.Name_STR;

(*Insert Saturday*)

ListInsert( IdList_UDI:=ListCreate.IdList_UDI ,

Mode_STR:='InsertHead',

ElementToInsert_stElement:=stElementToInsert,

Status_enListRet=>,

CopyNBytes_DI=>CopiedBytes );

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

bSaturdayInserted:=TRUE;

END_IF

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

(*ADD Friday:(Friday,Saturday,)*)

(*Define element to insert*)

StrDay := 'mi Friday' ;

stElementToInsert.Id_UDI:=1;

stElementToInsert.Name_STR := 'Friday' ;

stElementToInsert.Value_R:=aTemperatures[stElementToInsert.Id_UDI];

stElementToInsert.DataSize_DI:=SIZEOF( StrDay );

stElementToInsert.Data_ADDR:=ADR( StrDay );

StrDay:=stElementToInsert.Name_STR;;

(*Define reference *)

Ingeteam Proprietary All Rights Reserved Pag. 151


stReference.Id_UDI:=2; (*Saturday*)(* 22;*) (*Referencia desconocida*)

(*Insert Friday*)

ListInsert(IdList_UDI:=ListCreate.IdList_UDI,(*ListCreate.IdList_UDI+1,*)
(*0,*)

Mode_STR:='InsertBeforeId' ,

ReferenceElement_stElement:=stReference,

ElementToInsert_stElement:=stElementToInsert,

Status_enListRet=>,

CopyNBytes_DI=>CopiedBytes );

END_IF

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

bFridayInserted := TRUE;

END_IF

END_IF

(*GetListElement: LIST_GET*)

IF (OK_LIST = ListCreate.Status_enListRet)

THEN

GetListElement.ElementToFind_stElement.Name_STR := 'Saturday' ;

GetListElement.ElementToFind_stElement.DataSize_DI:=SIZEOF( StrDay );

GetListElement.ElementToFind_stElement.Data_ADDR:=ADR( StrDay );

GetListElement(IdList_UDI:=ListCreate.IdList_UDI,

Mode_STR := 'GetByName',

Status_enListRet => ,

FoundElement_stElement => stFoundElement,

CopyNBytes_DI =>CopiedBytes);

IF (OK_LIST = GetListElement.Status_enListRet)

THEN

bSaturdayFound := TRUE;

END_IF

Ingeteam Proprietary All Rights Reserved Pag. 152


END_IF

END_IF

1.4.1.13 LIST_INSERT

1.4.1.13.1 Description

This function inserts an element in a previously created list.

1.4.1.13.2 Syntax

FUNCTION_BLOCK LIST_INSERT

VAR_INPUT

IdList_UDI:UDINT;

Mode_STR:STRING(20);

ReferenceElement_stElement:stElement;

ElementToInsert_stElement:stElement;

VarRetainSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

CopyNBytes_DI:DINT;

Status_enListRet:enListRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 153


1.4.1.13.3 Input parameters

Input Parameter Name Type Description


IdList_UDI UDINT The identifier of the list in which we wish to insert the element.
Function Mode :
'InsertHead':The element will be inserted at the beginning of the list.
'InsertTail' The element will be inserted at the end of the list.
'InsertBeforeId': The element will be inserted right before the position
occupied by the element with the same value in the Id_UDI field as in the
ReferenceElement_stElement.Id_UDI field.
'InsertBeforeName': The element will be inserted right before the position
occupied by the element with the same value in the Name_STR field as in
the ReferenceElement_stElement.Name_STR field.
'InsertBeforeValue': The element will be inserted right before the position
occupied by the element with the same value in the Value_R field as in the
ReferenceElement_stElement.Value_R field.
'InsertBeforeBiggest': The element will be inserted right before the element
in the list with the biggest value in the Value_R field.
Mode_STR STRING(20) 'InsertBeforeSmallest': The element will be inserted right before the element
in the list with the smallest value in the Value_R field.
'InsertAfterId': The element will be inserted right after the position occupied
by the element with the same value in the Id_UDI field as in the
ReferenceElement_stElement.Id_UDI field.
'InsertAfterName': The element will be inserted right after the position
occupied by the element with the same value in the Name_STR field as in
the ?ReferenceElement_stElement.Name_STR? field.
'InsertAfterValue': The element will be inserted right after the position
occupied by the element with the same value in the Value_R field as in the
ReferenceElement_stElement.Value_R field.
'InsertAfterBiggest': The element will be inserted right after the element in
the list with the biggest value in the Value_R field.
'InsertAfterSmallest': The element will be inserted right after the element in
the list with the smallest value in the Value_R field.. .
The structure with the fields to be used as reference to find the position in
ReferenceElement_stElement stElement
which to insert an element in the list.
ElementToInsert_stElement stElement The structure with the fields of the element to be inserted in the list.
Size of the retain variable used for retain list.
VarRetainSizeBy_DI DINT
Must be >= List_Create.VarRetainSizeBy_DI.
Tbl. 1.109 Input parameters of function LIST_INSERT.

1.4.1.13.4 Output parameters

Output Parameter Name Type Description


The number of bytes copied from the data associated with the element.
This will be the minimum number of bytes between the
CopyNBytes_DI DINT ElementToInsert_stElement.DataSize_DI fields of the element to insert and
the ElemNbytes_DI field of the LIST_CREATE function when creating the
list.
Result of the FB execution
Possible status values for this function:
OK_LIST: Correct execution
ERR_MODE: Error in function mode
LIST_NO_VALID: List no valid
ERR_ADDR_DATA:Address Data No Valid
Status_enListRet enListRet ERR_ID: Id Not Found
ERR_NAME: Name Not Found
VALUE_NOT_FOUND:Value Not Found
ERR_DATA_SIZE: Element data size no valid.
ERR_NUM_ELEMENT: Too Much Elements
WARN_INSERT_ELEMENT_DATA_SIZE :
ElementToInsert_ST.DataSize_DI > ElemSize of the LIST
Tbl. 1.110 Output parameters of function LIST_INSERT.

Ingeteam Proprietary All Rights Reserved Pag. 154


1.4.1.13.5 Data Types

1.4.1.13.5.1 enListRet

Value Description
OK_LIST (0) Correct execution
ERR_MODE (1) Error in function mode
LIST_NO_VALID (2) List no valid
LIST_EMPTY (3) LIST Empty
ERR_ADDR_DATA (4) Address Data No Valid
ERR_ID (5) Id Not Found
ERR_NAME (6) Name Not Found
VALUE_NOT_FOUND (7) Value Not Found
ElementToFind_ST.DataSize_DI > ElemSize of the LIST or
WARN_GET_ELEMENT_DATA_SIZE (8)
ElementToFind_ST.DataSize_DI > FoundElement_ST.DataSize_DI
ERR_DATA_SIZE (9) Element data size no valid
ERR_NUM_ELEMENT (10) Too Much Elements
ERR_CREATE_VALUE_PARAMS (11) Error creating list. One input parameter value is incorrect.
NO_MEMORY_SPACE (12) No space in memory
TOO_MUCH_LIST (13) Too much number of list
ElementToInsert_ST.DataSize_DI > ElemSize of the LIST or
WARN_INSERT_ELEMENT_DATA_SIZE (14)
ElementToRemove_ST.DataSize_DI >RemovedElement_ST.DataSize_D I
WARN_REMOVE_ELEMENT_DATA_SIZE (15)
ERR_VarRetainSize (16) Function.VarRetainSizeBY_DI < LIST_CREATE.VarRetainSizeBY_DI
WARN_LIST_ALREADY_EXIST (17)
ERR_RetainADDR_OCCUPIED (18)
Tbl. 1.111 Enumerator enListRet.

1.4.1.13.5.2 stElement

Field Name Type Description


Id_UDI UDINT Id of the element.
Name_STR STRING(32) Name of the element.
Value_R REAL Real Value of the element.
DataSize_DI DINT Size of the Data Buffer.
Data_ADDR DWORD Start address of the data buffer.
Tbl. 1.112 Fields of the stElement structure.

1.4.1.13.6 Remarks

To use the LIST_INSERT function correctly, it is important to remember certain points:

The fields of the corresponding ReferenceElement_stElement structure must be configured


according to the insert mode set in the Mode_STR parameter.

The ElementToInsert.Data_ADDR field should contain a valid address from which to obtain the
associated data to insert.

We recommend that you check whether


Status_enListRet:=WARN_GET_ELEMENT_DATA_SIZE has been returned, since this indicates

Ingeteam Proprietary All Rights Reserved Pag. 155


that the expected number of bytes have not been copied to the
ElementToInsert_stElement.DataSize_DI.

If the insert criteria used has several elements in the list that can be used as reference, the
function will use the first one found in the list as the reference.

1.4.1.13.7 Example

PROGRAM EXAMPLE

VAR

ContadorDeCiclos :DINT;

nTest :DINT := 0;

InsertListElement :BOOL;

END_VAR

VAR CONSTANT

NUM_OF_WEEKEND_DAYS: DINT := 3;

SIZE_OF_ELEMENT: DINT := 32;

(* Buffer size = 100 + numElements * (sizElement + 60) = 376*)

BUFFER_SIZE:DINT := 376;

END_VAR

VAR

bListCreated: BOOL;

bFridayInserted: BOOL;

bSaturdayInserted: BOOL;

bSundayInserted: BOOL;

idList: UDINT;

statusList: enListRet;

aTemperatures:ARRAY [1..NUM_OF_WEEKEND_DAYS] OF REAL:= 30.0, 22.9, 27.0;

END_VAR

VAR

(*LIST_CREATE*)

ListCreate: LIST_CREATE := (ListName_STR:='WeekDaysLst' );

Ingeteam Proprietary All Rights Reserved Pag. 156


(*input parameters*)

StrDay : STRING(32);

aInfoDay: ARRAY[1..NUM_OF_WEEKEND_DAYS] OF STRING(32);

(*LIST_INSERT*)

ListInsert:LIST_INSERT;

stElementToInsert: stElement;

stReference: stElement;

(*output parameters*)

Status: enListRet;

CopiedBytes: DINT;

(*************************************************************)

(*LIST_GET*)

GetListElement: LIST_GET;

stFoundElement: stElement;

bSaturdayFound :BOOL;

END_VAR

IF NOT bListCreated

THEN

(* CREATE a Day LIST*)

ListCreate( ListName_STR:='WeekDaysLst',

ElemNbytes_DI := SIZEOF(StrDay),

NumElem_DI := NUM_OF_WEEKEND_DAYS,

IdList_UDI=> (*IdDaysList*) ,

Status_enListRet=>(*Status_enList*) );

IF (OK_LIST = ListCreate.Status_enListRet)

THEN

bListCreated := TRUE;

(* Add List manipulation code here *)

StrDay := 'mi Saturday' ;

(* ADD Saturday :(Saturday,,)*)

Ingeteam Proprietary All Rights Reserved Pag. 157


(*Define element to insert*)

stElementToInsert.Id_UDI:=2;

stElementToInsert.Name_STR := 'Saturday' ;

stElementToInsert.Value_R:=aTemperatures[ stElementToInsert.Id_UDI ];

stElementToInsert.DataSize_DI:=SIZEOF(StrDay);

stElementToInsert.Data_ADDR:=ADR(StrDay);

StrDay := stElementToInsert.Name_STR;

(*Insert Saturday*)

ListInsert( IdList_UDI:=ListCreate.IdList_UDI ,

Mode_STR:='InsertHead',

ElementToInsert_stElement:=stElementToInsert,

Status_enListRet=>,

CopyNBytes_DI=>CopiedBytes );

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

bSaturdayInserted := TRUE;

END_IF

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

(*ADD Friday:(Friday,Saturday,)*)

(*Define element to insert*)

StrDay :='mi Friday';

stElementToInsert.Id_UDI:=1;

stElementToInsert.Name_STR:='Friday';

stElementToInsert.Value_R:=aTemperatures[stElementToInsert.Id_UDI];

stElementToInsert.DataSize_DI:=SIZEOF(StrDay);

stElementToInsert.Data_ADDR:=ADR(StrDay );

StrDay:=stElementToInsert.Name_STR;;

(*Define reference *)

stReference.Id_UDI:=2; (*Saturday*) (* 22;*) (*Referencia desconocida*)

Ingeteam Proprietary All Rights Reserved Pag. 158


(*Insert Friday*)

ListInsert( IdList_UDI:=ListCreate.IdList_UDI,

(*ListCreate.IdList_UDI+1,*) (*0,*)

Mode_STR:= 'InsertBeforeId' ,

ReferenceElement_stElement :=stReference,

ElementToInsert_stElement:=stElementToInsert,

Status_enListRet=>,

CopyNBytes_DI=>CopiedBytes );

END_IF

IF (OK_LIST = ListInsert.Status_enListRet)

THEN

bFridayInserted := TRUE;

END_IF

END_IF

(*GetListElement: LIST_GET*)

IF (OK_LIST = ListCreate.Status_enListRet)

THEN

GetListElement.ElementToFind_stElement.Name_STR := 'Saturday' ;

GetListElement.ElementToFind_stElement.DataSize_DI:=SIZEOF( StrDay );

GetListElement.ElementToFind_stElement.Data_ADDR:=ADR( StrDay );

GetListElement(IdList_UDI:=ListCreate.IdList_UDI,

Mode_STR := 'GetByName',

Status_enListRet => ,

FoundElement_stElement => stFoundElement,

CopyNBytes_DI =>CopiedBytes);

IF (OK_LIST = GetListElement.Status_enListRet)

THEN

bSaturdayFound := TRUE;

END_IF

END_IF

Ingeteam Proprietary All Rights Reserved Pag. 159


END_IF

1.4.1.14 LIST_REMOVE

1.4.1.14.1 Description

Function block to remove a single/all element from the LIST.

The LIST_REMOVE function deletes the desired element from the list. It also includes a function
to delete all the lists created in the PLC up to that time.

1.4.1.14.2 Syntax

FUNCTION_BLOCK LIST_REMOVE

VAR_INPUT

IdList_UDI:UDINT;

Mode_STR:STRING(20);

ElementToRemove_stElement:stElement;

VarRetainSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

RemovedElement_stElement:stElement;

CopyNBytes_DI:DINT;

Status_enListRet:enListRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 160


1.4.1.14.3 Input parameters

Input Parameter Name Type Description


IdList_UDI UDINT The identifier of the list from which to remove the element.
Function Mode:.
'RemoveHead': This removes the first element from the list.
RemoveTail. This removes the last element from the list.
'RemoveAll': This removes all the elements from the list.
'RemoveById': This removes the element in the list with the Id_UDI
field that matches the ElementToRemove_stElement.Id_UDI field.
'RemoveByName': This removes the element in the list with the
Name_STR field that matches the
Mode_STR STRING(20) ElementToRemove_stElement.Id_UDI field.
'RemoveByValue': This removes the element in the list with the
Value_R field that matches the ElementToRemove_stElement.Id_UDI
field.
'RemoveBiggest': This removes the element with the largest Value_R
field in the list.
'RemoveSmallest': This removes the element with the smallest
Value_R field in the list.
'DestroyAllLists': This removes all the lists declared in the PLC. . .
The structure with the fields that contain information on the element
ElementToRemove_stElement stElement
to be deleted.
Size of the retain variable used for retain list.
VarRetainSizeBy_DI DINT
Must be >= List_Create.VarRetainSizeBy_DI.
Tbl. 1.113 Input parameters of function LIST_REMOVE.

1.4.1.14.4 Output parameters

Output Parameter Name Type Description


Structure where the fields associated with the removed element will
RemovedElement_stElement stElement
be stored.
The number of bytes copied from data associated with the removed
element. This will be the minimum number of bytes between the
ElementToRemove_stElement.DataSize_DI fields of the element to
CopyNBytes_DI DINT
remove, the RemovedElement_stElement.DataSize_DI field of the
removed element, and the ElemNbytes_DI field of the LIST_CREATE
function when creating the list.
Result of the FB executin.
Possible status values for this function:
OK_LIST: Correct execution
ERR_MODE: Error in function mode
LIST_NO_VALID: List no valid
LIST_EMPTY: LIST Empty
ERR_ADDR_DATA:Address Data No Valid
Status_enListRet enListRet ERR_ID: Id Not Found
ERR_NAME: Name Not Found
VALUE_NOT_FOUND:Value Not Found
ERR_DATA_SIZE: Element data size no valid
WARN_REMOVE_ELEMENT_DATA_SIZE :
ElementToRemove_ST.DataSize_DI > ElemSize of the LIST or
ElementToRemove_ST.DataSize_DI
>RemovedElement_ST.DataSize_D I
Tbl. 1.114 Output parameters of function LIST_REMOVE.

Ingeteam Proprietary All Rights Reserved Pag. 161


1.4.1.14.5 Data Types

1.4.1.14.5.1 enListRet

Value Description
OK_LIST (0) Correct execution
ERR_MODE (1) Error in function mode
LIST_NO_VALID (2) List no valid
LIST_EMPTY (3) LIST Empty
ERR_ADDR_DATA (4) Address Data No Valid
ERR_ID (5) Id Not Found
ERR_NAME (6) Name Not Found
VALUE_NOT_FOUND (7) Value Not Found
ElementToFind_ST.DataSize_DI > ElemSize of the LIST or
WARN_GET_ELEMENT_DATA_SIZE (8)
ElementToFind_ST.DataSize_DI > FoundElement_ST.DataSize_DI
ERR_DATA_SIZE (9) Element data size no valid
ERR_NUM_ELEMENT (10) Too Much Elements
ERR_CREATE_VALUE_PARAMS (11) Error creating list. One input parameter value is incorrect.
NO_MEMORY_SPACE (12) No space in memory
TOO_MUCH_LIST (13) Too much number of list
ElementToInsert_ST.DataSize_DI > ElemSize of the LIST or
WARN_INSERT_ELEMENT_DATA_SIZE (14)
ElementToRemove_ST.DataSize_DI >RemovedElement_ST.DataSize_D I
WARN_REMOVE_ELEMENT_DATA_SIZE (15)
ERR_VarRetainSize (16) Function.VarRetainSizeBY_DI < LIST_CREATE.VarRetainSizeBY_DI
WARN_LIST_ALREADY_EXIST (17)
ERR_RetainADDR_OCCUPIED (18)
Tbl. 1.115 Enumerator enListRet.

1.4.1.14.5.2 stElement

Field Name Type Description


Id_UDI UDINT Id of the element.
Name_STR STRING(32) Name of the element.
Value_R REAL Real Value of the element.
DataSize_DI DINT Size of the Data Buffer.
Data_ADDR DWORD Start address of the data buffer.
Tbl. 1.116 Fields of the stElement structure.

1.4.1.14.6 Remarks

To use the LIST_REMOVE function correctly, it is important to remember certain points:

The fields of the corresponding ?ElementToRemove_stElement? structure must be configured


according to the insert mode set in the Mode_STR parameter.

The ElementToRemove.Data_ADDR field must contain a valid address in which to keep the data
removed, therefore, memory space must be reserved for this data of the found element.

We recommend that you check whether


Status_enListRet:=WARN_GET_ELEMENT_DATA_SIZE has been returned, since this indicates

Ingeteam Proprietary All Rights Reserved Pag. 162


that the expected number of bytes have not been copied to the
ElementToRemove_stElement.DataSize_DI.

If the removal criteria used has several elements in the list that can be used as reference, the
function will use the first one found in the list as the reference.

1.4.1.14.7 Example

PROGRAM EXAMPLE

VAR

ContadorDeCiclos :DINT;

nTest :DINT := 0;

InsertListElement :BOOL;

END_VAR

VAR CONSTANT

NUM_OF_WEEKEND_DAYS: DINT := 3;

SIZE_OF_ELEMENT: DINT := 32;

(* Buffer size = 100 + numElements * (sizElement + 60) = 376*)

BUFFER_SIZE:DINT := 376;

END_VAR

VAR

bListCreated: BOOL;

bFridayInserted: BOOL;

bSaturdayInserted: BOOL;

bSundayInserted: BOOL;

idList: UDINT;

statusList: enListRet;

aTemperatures:ARRAY [1..NUM_OF_WEEKEND_DAYS] OF REAL:= 30.0, 22.9, 27.0;

END_VAR

VAR

(*LIST_CREATE*)

ListCreate: LIST_CREATE := (ListName_STR:='WeekDaysLst' );

Ingeteam Proprietary All Rights Reserved Pag. 163


(*input parameters*)

StrDay : STRING(32);

aInfoDay: ARRAY[1..NUM_OF_WEEKEND_DAYS] OF STRING(32);

(*LIST_INSERT*)

ListInsert: LIST_INSERT;

stElementToInsert: stElement;

stReference: stElement;

(*output parameters*)

Status: enListRet;

CopiedBytes: DINT;

(*LIST_GET*)

GetListElement: LIST_GET;

stFoundElement: stElement;

bSaturdayFound :BOOL;

END_VAR

VAR

(*LIST_REMOVE*)

ListRemove: LIST_REMOVE;

END_VAR

ListRemove.ElementToRemove_stElement.Value_R:=3.1416;

ListRemove.ElementToRemove_stElement.Name_STR:='Saturday' ;

ListRemove.ElementToRemove_stElement.DataSize_DI:=SIZEOF( StrDay );

ListRemove.ElementToRemove_stElement.Data_ADDR:= ADR( StrDay );

ListRemove( IdList_UDI:= ListCreate.IdList_UDI,

Mode_STR := 'RemoveByName',

Status_enListRet => ,

RemovedElement_stElement => stFoundElement,

CopyNBytes_DI =>CopiedBytes );

IF (OK_LIST = ListRemove.Status_enListRet)

THEN

Ingeteam Proprietary All Rights Reserved Pag. 164


bSaturdayFound := TRUE;

END_IF

1.5 IEC61131-3_01

The following tables sumarize the entities contained in IEC61131-3_01:

Name Description
BCD_TO_INT Function that converts a number in BCD code to its equivalent base 10 integer.
BLINK Function that generates a pulse sequence with configurable high and low status times.
DERIVATIVE Function that approximates the mathematical derivative of an input variable.
HYSTERESIS Function that controls whether the value of the input variable drops below an established limit.
INT_TO_BCD Function that converts a base 10 integer to its equivalent in BCD code.
INTEGRAL Function that approximately determines the integration of an input variable.
PID PID controller.
Tbl. 1.117 Functions, Function Blocks, and Programs.

1.5.1 Functions

1.5.1.1 BCD_TO_INT

1.5.1.1.1 Description

Function that converts a number in BCD code to its equivalent base 10 integer.

1.5.1.1.2 Syntax

FUNCTION BCD_TO_INT : INT

VAR_INPUT

B:BYTE;

END_VAR

1.5.1.1.3 Input parameters

Input Parameter Name Type Description


B BYTE A variable with its value coded in BCD that we want to convert to its equivalent in INT.
Tbl. 1.118 Input parameters of function FUNCTION BCD_TO_INT.

Ingeteam Proprietary All Rights Reserved Pag. 165


1.5.1.1.4 Remarks

This function is equivalent to BCD_BYTE_TO_INT. Recommend using BCD_BYTE_TO_INT.

To use the BCD_TO_INT function, all that is required is the call to the function with an input
parameter containing a value coded in BCD, and a result to be assigned to a variable of the INT
type.

Although the input parameter is coded in BCD, this does not imply that it must be represented in
binary format in the program. It can be represented in any of the forms permitted by the
programming environment.

If an incorrect input parameter is entered, the function will return a result of -1.

The maximum input value is 255 (1111 1111) since it is a BYTE. However, as it is represented in
BCD, the highest integer that can be represented in a BYTE is 99 (0110 0011), which in BCD
corresponds to 153 (1001 1001).

1.5.1.1.5 Example

PROGRAM EXAMPLE

VAR

(*BCD_TO_INT*)

DataIn_BCD: BYTE := 16#93;

(* 93 BCD *)

DataOut_INT: INT;

END_VAR

DataOut_INT:=BCD_TO_INT(DataIn_BCD);

(*Output = 93 (16#5c)*)

1.5.1.2 BLINK

1.5.1.2.1 Description

Function that generates a pulse sequence with configurable high and low status times.

1.5.1.2.2 Syntax

FUNCTION_BLOCK BLINK

VAR_INPUT

Ingeteam Proprietary All Rights Reserved Pag. 166


ENABLE:BOOL;

TIMELOW:TIME;

TIMEHIGH:TIME;

END_VAR

VAR_OUTPUT

OUT:BOOL;

END_VAR

1.5.1.2.3 Input parameters

Input Parameter Name Type Description


ENABLE BOOL Enables the generation of the pulse sequence.
TIMELOW TIME Time that the signal will remain in low status.
TIMEHIGH TIME Time that the signal will remain in high status.
Tbl. 1.119 Input parameters of function BLINK.

1.5.1.2.4 Output parameters

Output Parameter Name Type Description


OUT BOOL Output signal generated.
Tbl. 1.120 Output parameters of function BLINK.

1.5.1.2.5 Remarks

This function is equivalent to BLINK_SIGNAL. Recommend using BLINK_SIGNAL.

1.5.1.2.6 Example

PROGRAM EXAMPLE

VAR

(*BLINK*)

BlinkValue:BLINK := ( ENABLE :=TRUE,

TIMEHIGH := T#1000ms,

TIMELOW := T#1500ms );

(*Output Parameters*)

OutputBlinkSignal: BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 167


(*Generate a blink signal*)

BlinkValue( OUT => OutputBlinkSignal );

1.5.1.3 DERIVATIVE

1.5.1.3.1 Description

Function that approximates the mathematical derivative of an input variable.

To do so, an input signal and the time that elapses between calls to functions are entered.

1.5.1.3.2 Syntax

FUNCTION_BLOCK DERIVATIVE

VAR_INPUT

IN:REAL;

TM:DWORD;

RESET:BOOL;

END_VAR

VAR_OUTPUT

OUT:REAL;

END_VAR

1.5.1.3.3 Input parameters

Input Parameter Name Type Description


IN REAL Input variable to operate on.
TM DWORD Time between calls to function in milliseconds.
RESET BOOL Resets the DERIVATIVE function.
Tbl. 1.121 Input parameters of function DERIVATIVE.

1.5.1.3.4 Output parameters

Output Parameter Name Type Description


Function output variable.
OUT REAL
This will correspond to the value of the input variable derivative.
Tbl. 1.122 Output parameters of function DERIVATIVE.

Ingeteam Proprietary All Rights Reserved Pag. 168


1.5.1.3.5 Remarks

To use the DERIVATIVE function all that is required is the entry of a signal to derive (IN) and the
time between calls to function (TM) in milliseconds.

Fig. 1.1 .

1.5.1.3.6 Example

PROGRAM Example

VAR

(*DERIVATIVE*)

(*************************************************************)

(*DERIVATIVE*)

(*Inputs*)

SamplesCounter:INT:=0;

InputTriangle : ARRAY [1..100] OF REAL := -5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

Ingeteam Proprietary All Rights Reserved Pag. 169


5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4;

(*output variables*)

OutputDerivate : ARRAY [1..100] OF REAL;

(*function*)

DeltaOp: DERIVATIVE := (TM :=10);

END_VAR

(*Samples Counter*)

IF(SamplesCounter>0 AND SamplesCounter<100 )

THEN SamplesCounter := SamplesCounter+1;

ELSE SamplesCounter:=1;

END_IF

(*Get Input Derivate*)

DeltaOp( IN:=InputTriangle[ SamplesCounter ],

OUT => OutputDerivate[ SamplesCounter ]);

1.5.1.4 HYSTERESIS

1.5.1.4.1 Description

Function that controls whether the value of the input variable drops below an established limit.

If the signal falls below this limit, the function will activate a flag. It also has a hysteresis band to
reset the indication flag. Therefore, the flag will not return to 0 until the signal exceeds an upper
limit.

1.5.1.4.2 Syntax

FUNCTION_BLOCK HYSTERESIS

VAR_INPUT

IN:INT;

Ingeteam Proprietary All Rights Reserved Pag. 170


HIGH:INT;

LOW:INT;

END_VAR

VAR_OUTPUT

OUT:BOOL;

END_VAR

1.5.1.4.3 Input parameters

Input Parameter Name Type Description


IN INT Input variable with the value is to be supervised.
HIGH INT Threshold to be exceeded by the variable to set the output flag to FALSE.
LOW INT Lower threshold, below which the variable causes the output flag to set to TRUE.
Tbl. 1.123 Input parameters of function HYSTERESIS.

1.5.1.4.4 Output parameters

Output Parameter Name Type Description


FALSE: The input variable has not fallen below the lower limit or has exceeded the
upper reset limit.
OUT BOOL
TRUE: The input variable has fallen below the lower limit and has not yet exceeded the
upper reset limit.
Tbl. 1.124 Output parameters of function HYSTERESIS.

1.5.1.4.5 Remarks

Use of the HYSTERESIS function is very simple for users. The user simply needs to establish
the values for the upper and lower limits that will determine the hysteresis range. Once these
limits are set, the function will supervise the variable included in the IN parameter and establish
the correct output flag statuses via the OUT variable.

The function logic is based on monitoring the value of the input variable in relation to the lower
limit. If the value falls below this limit, the function returns the output flag with the TRUE status.
The TRUE status will not change until the input variable reaches the upper limit value. The
output flag will then return to FALSE.

1.5.1.4.6 Example

PROGRAM Example

VAR

(*function declaration*)

Ingeteam Proprietary All Rights Reserved Pag. 171


Thermostat: HYSTERESIS;

(*input parameters*)

UpperLimit: INT;

LowerLimit: INT;

InputVariable: INT;

(*output variable*)

HeaterOn: BOOL;

END_VAR

(*Thermostat : HYSTERESIS;*)

(* Contol heater thermostat to turn the heater on when the temperature drops below LowerLimit
degrees, but not turn it off until the temperature rises above UpperLimit degrees*)

Thermostat( (*limit configuration*)

HIGH:=UpperLimit,

LOW:=LowerLimit,

(*input assignment*)

IN:=InputVariable,

(*Output*)

OUT => HeaterOn);

1.5.1.5 INTEGRAL

1.5.1.5.1 Description

Function that approximately determines the integration of an input variable.

1.5.1.5.2 Syntax

FUNCTION_BLOCK INTEGRAL

VAR_INPUT

IN:REAL;

TM:DWORD;

RESET:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 172


VAR_OUTPUT

OUT:REAL;

OVERFLOW:BOOL:=FALSE;

END_VAR

1.5.1.5.3 Input parameters

Input Parameter Name Type Description


IN REAL Input variable to operate on.
TM DWORD Time between calls to function in milliseconds.
RESET BOOL Resets the INTEGRAL function.
Tbl. 1.125 Input parameters of function INTEGRAL.

1.5.1.5.4 Output parameters

Output Parameter Name Type Description


OUT REAL Function output variable. This will correspond with the input variable integral.
OVERFLOW BOOL Indicates if an overflow has occurred in calculating the integral.
Tbl. 1.126 Output parameters of function INTEGRAL.

1.5.1.5.5 Remarks

To use the INTEGRAL function, all that is required is the entry of a signal input (IN) and the time
between calls to function (TM) in milliseconds.

Fig. 1.2 .

Ingeteam Proprietary All Rights Reserved Pag. 173


1.5.1.5.6 Example

PROGRAM Example

VAR

(*INTEGRAL*)

(*Inputs*)

SamplesCounter:INT:=0;

InputSquare : ARRAY [1..100] OF REAL := 1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1;

(*output variables*)

OutputIntegral : ARRAY [1..100] OF REAL;

(*function*)

IntegralWave : INTEGRAL := (TM :=1000);

END_VAR

(*Samples Counter*)

IF(SamplesCounter>0 AND SamplesCounter<100 )

THEN SamplesCounter := SamplesCounter+1;

ELSE SamplesCounter:=1;

END_IF

(*Get Input Derivate*)

IntegralWave( IN:=InputSquare[ SamplesCounter ],

OUT => OutputIntegral[ SamplesCounter ]);

Ingeteam Proprietary All Rights Reserved Pag. 174


1.5.1.6 INT_TO_BCD

1.5.1.6.1 Description

Function that converts a base 10 integer to its equivalent in BCD code.

1.5.1.6.2 Syntax

FUNCTION INT_TO_BCD : BYTE

VAR_INPUT

I:INT;

END_VAR

1.5.1.6.3 Input parameters

Input Parameter Name Type Description


The variable with the value to be converted to its representation in BCD.
I INT The value must be from 0 to 99, which results in output that ranges from 0 to 153 (BCD
values).
Tbl. 1.127 Input parameters of function FUNCTION INT_TO_BCD.

1.5.1.6.4 Remarks

This function is equivalent to INT_TO_BCD_BYTE. Recommend using INT_TO_BCD_BYTE

The function returns 255 if the input parameter can not be represented in BCD in a BYTE.

To use the INT_TO_BCD function, all that is required is the call to the function with an input
parameter containing a value of base 10 INT type and for the result to be assigned to a BYTE
type variable.

Although the output function is coded in BCD, this does not imply that it must be represented in
binary format in the program. It can be represented in any of the forms permitted by the
programming environment.

1.5.1.6.5 Example

PROGRAM Example

VAR

(*INT_TO_BCD*)

DataIn_INT: INT := 93 (* 16#5c *);

Ingeteam Proprietary All Rights Reserved Pag. 175


DataOut_BCD: BYTE;

END_VAR

DataOut_BCD:=INT_TO_BCD(DataIn_INT);

(*Output = 93 (16#93)*)

1.5.1.7 PID

1.5.1.7.1 Description

PID controller.

The PID function performs the Proportional-Integral-Derivative control of a controlled variable to


obtain a given setpoint.

1.5.1.7.2 Syntax

FUNCTION_BLOCK PID

VAR_INPUT

ACTUAL:REAL;

SET_POINT:REAL;

KP:REAL;

TN:REAL;

TV:REAL;

Y_MANUAL:REAL;

Y_OFFSET:REAL;

Y_MIN:REAL;

Y_MAX:REAL;

MANUAL:BOOL;

RESET:BOOL;

END_VAR

VAR_OUTPUT

Y:REAL;

LIMITS_ACTIVE:BOOL:=FALSE;

OVERFLOW:BOOL:=FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 176


END_VAR

1.5.1.7.3 Input parameters

Input Parameter Name Type Description


ACTUAL REAL Current value of the controlled variable.
SET_POINT REAL Value of the setpoint.
KP REAL Value of the proportional constant.
TN REAL Integral action time in seconds.
TV REAL Derivative action time in seconds.
Y_MANUAL REAL Value of output Y if the MANUAL variable is at TRUE.
Y_OFFSET REAL Value of offset for manipulated variable Y.
Lowest value that can be adopted by the manipulated variable Y.
If the value calculated for Y is lower than this limit, it will be restricted by Y_MIN and
Y_MIN REAL
the LIMITS_ACTIVE output flag will be activated.
This control only functions if Y_MIN &lt; Y_MAX.
Highest value that can be adopted by the manipulated variable Y.
If the value calculated for Y is higher than this limit, it will be restricted by Y_MAX and
Y_MAX REAL
the LIMITS_ACTIVE output flag will be activated.
This control only functions if Y_MIN &lt; Y_MAX.
FALSE: The manual function is deactivated.
The Y output will take on the value calculated in the function.
MANUAL BOOL
TRUE: The manual function is activated.
The Y output will take on the value of the Y_MANUAL variable.
RESET BOOL Resets the PID controller assigned to Y=Y_OFFSET.
Tbl. 1.128 Input parameters of function PID.

1.5.1.7.4 Output parameters

Output Parameter Name Type Description


Y REAL Value for the manipulated variable.
FALSE: This indicates that the calculation of the Y output variable has not exceeded
the limits established in Y_MIN and Y_MAX.
LIMITS_ACTIVE BOOL
TRUE: This indicates that the calculation of the Y output variable has exceeded one
of the limits established in Y_MIN or Y_MAX.
FALSE The function does not present overflow in its integral part.
TRUE The function has detected an overflow in the integral part.
OVERFLOW BOOL
he controller will be interrupted and will only run again after being reset by the RESET
input.
Tbl. 1.129 Output parameters of function PID.

1.5.1.7.5 Remarks

The PID function provides Proportional-Integral-Derivative control of a controlled variable


(ACTUAL). The function can be completely parameterised to set the value of the proportional
constant (KP), the derivation time value (TV) and the integration time value (TN).

The function will calculate the manipulated variable (Y) according to the following equation:

Y= KP(e + 1/TN integral( edt ) + TVde / dt) + Y_OFFSET

Where:

Ingeteam Proprietary All Rights Reserved Pag. 177


e=SET_POINT-ACTUAL

The DERIVATIVE part OF the FUNCTION can easily be desabled BY assigning the value TV=0.

The MANUAL parameter can be used to force the value of the Y output with the value assigned
to Y_MANUAL.

The Y_MIN and Y_MAX parameters can be used to set a range of minimum and maximum
values for the manipulated value Y. To disable this restriction, a value of 0 must be assigned to
Y_MIN and Y_MAX.

Given that there is an INTEGRAL part OF the FUNCTION, poor parameter settings OF the
controller may result in an overflow IF the error INTEGRAL becomes very large. TO avoid this,
there is an output flag (OVERFLOW) that is activated IF this value is too high. When this occurs,
the controller is disabled UNTIL it is reset (RESET).

1.5.1.7.6 Example

PROGRAM Example

VAR

(*PID*)

MAX_CYCLES :INT := 50;

Input:REAL;

Output:REAL;

Regulator:PID := (KP:= 0.5,

TN:=70,

TV:=0.05,

Y_MANUAL:=0.0,

Y_ADDOFFSET:=0.0,

Y_MIN :=-1E3,

Y_MAX :=+1E3,

MANUAL:=FALSE,

RESET :=FALSE ;

END_VAR

(* Get Blink Input 01010101010...*)

Counter := Counter +1;

Ingeteam Proprietary All Rights Reserved Pag. 178


IF(Counter>=MAX_CYCLES)

THEN Counter :=0;

END_IF;

Input := REAL_TO_INT( Counter / (MAX_CYCLES/2)) ; (*0/1*)

(*Regulator: PID*)

(* Get regulated output *)

Regulator(ACTUAL:=Regulator.Y,

SET_POINT:=Input,

Y=>Output );

(*if overflow => reset PID*)

Regulator.RESET := Regulator.OVERFLOW;

1.6 IEC61131-3_02

The following tables sumarize the entities contained in IEC61131-3_02:

Name Description
CTD Counter Down.
CTU Counter Up.
CTUD Counter Up Down.
F_TRIG Falling Edge detection.
R_TRIG Rising Edge detection.
RS Bistable function, reset dominant.
RTC Real Time Counter management function.
SR Bistable function, set dominant.
TOF Timer Off Delay.
TON Timer on delay.
TP Timer Pulse.
Tbl. 1.130 Functions, Function Blocks, and Programs.

1.6.1 Functions

1.6.1.1 CTD

1.6.1.1.1 Description

Counter Down.

The CTD function performs a decrement operation on detection of edges on one of its inputs.
When the value to decrement reaches 0, the function activates an indication flag.

Ingeteam Proprietary All Rights Reserved Pag. 179


1.6.1.1.2 Syntax

FUNCTION_BLOCK CTD

VAR_INPUT

CD:BOOL;

LOAD:BOOL;

PV:WORD;

END_VAR

VAR_OUTPUT

Q:BOOL;

CV:WORD;

END_VAR

1.6.1.1.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CD BOOL TRUE: On detection of the rising edge of the signal, the function decrements the
value of the CV output variable by 1.
If TRUE the function loads the value of the PV variable in the internal function count
LOAD BOOL
variable.
PV WORD A variable with the value to preload in the internal function count variable.
Tbl. 1.131 Input parameters of function CTD.

1.6.1.1.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CV variable is greater than 0.
Q BOOL
TRUE: The value of the CV variable has reached 0.
CV WORD Current value of the decremented variable.
Tbl. 1.132 Output parameters of function CTD.

Ingeteam Proprietary All Rights Reserved Pag. 180


1.6.1.1.5 Remarks

This function is equivalent to COUNTER_DOWN. Recommend using COUNTER_DOWN.

When the value of the LOAD variable is TRUE, the CV count variable initialises with the value
set in the PV input variable. When the function detects a rising edge in the CD input variable, the
CV variable decrements by one on each edge. Once CV has reached 0, the variable will not
continue to decrement to negative values. When CV=0, the function activates the flag setting the
Q output to TRUE.

Fig. 1.3 .

1.6.1.1.6 Example

PROGRAM Example

VAR

CounterDown : CTD ;

nTest:INT := 0;

END_VAR

CASE nTest OF

Ingeteam Proprietary All Rights Reserved Pag. 181


0: (* CounterDown : CTD *)

CounterDown( LOAD :=TRUE, PV := 2) ;

1: CounterDown( LOAD :=FALSE);

2: CounterDown( CD :=TRUE); (*CV=1*)

3: CounterDown( CD :=FALSE);

4: CounterDown( CD :=TRUE);(*---- CV=0 Q=TRUE ----*)

5: CounterDown( CD :=FALSE);

6: CounterDown( CD :=TRUE);(*CV=0 Q=FALSE*)

7: CounterDown( CD :=FALSE);

END_CASE;

1.6.1.2 CTU

1.6.1.2.1 Description

Counter Up.

The CTU function increments an output value on detecting rising edges on one of its inputs. The
function returns an indication flag when the count variable exceeds the value defined as the
upper limit.

1.6.1.2.2 Syntax

FUNCTION_BLOCK CTU

VAR_INPUT

CU:BOOL;

RESET:BOOL;

PV:WORD;

END_VAR

VAR_OUTPUT

Q:BOOL;

CV:WORD;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 182


1.6.1.2.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CU BOOL TRUE: On detection of the rising edge of the signal, the function increments the
value of the CV output variable by 1.
RESET BOOL If TRUE the function loads the value 0 in the internal function count variable.
PV WORD A variable with the value to preload in the internal function count variable.
Tbl. 1.133 Input parameters of function CTU.

1.6.1.2.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CV variable is lower than the PV upper limit.
Q BOOL
TRUE The value of the CV variable has reached the PV upper limit.
CV WORD Current value of the incremented variable.
Tbl. 1.134 Output parameters of function CTU.

Ingeteam Proprietary All Rights Reserved Pag. 183


1.6.1.2.5 Remarks

This function is equivalent to COUNTER_UP . Recommend using COUNTER_UP.

When the value of the RESET variable is TRUE, the function sets the value of the CV count
variable to 0. Each time there is a rising edge in the CU input variable, it increments the CV
variable by 1. When the value of CV reached the limit set by the PV parameter, the function
activates the Q flag.

Fig. 1.4 .

1.6.1.2.6 Example

PROGRAM Example

VAR

CounterUp : CTU ;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(* CounterUp : CTU *)(* Use a CounterUp *)CounterUp( RESET :=TRUE, PV := 2 ;

Ingeteam Proprietary All Rights Reserved Pag. 184


2:CounterUp( RESET :=FALSE);

3:CounterUp( CU :=TRUE);(*CV=1*)

4:CounterUp( CU :=FALSE);

5:CounterUp( CU :=TRUE);(*---- Q=TRUE ----*)

6:CounterUp( CU :=FALSE);

7:CounterUp( CU :=TRUE);(* Q=TRUE*)

8:CounterUp( CU :=FALSE);

END_CASE;

1.6.1.3 CTUD

1.6.1.3.1 Description

Counter Up Down.

The CTUD function is a composition of the CTD function for the decrement counter and the CTU
function for the increment counter.

The function performs a decrement operation on detecting edges on one of its inputs. When the
value to decrement reaches 0, the function activates an indication flag.

The function increments an output variable on detecting rising edges on one of its inputs. The
function returns an indication flag when the count variable exceeds the value defined as the
upper limit.

1.6.1.3.2 Syntax

FUNCTION_BLOCK CTUD

VAR_INPUT

CU:BOOL;

CD:BOOL;

RESET:BOOL;

LOAD:BOOL;

PV:WORD;

END_VAR

VAR_OUTPUT

Ingeteam Proprietary All Rights Reserved Pag. 185


QU:BOOL;

QD:BOOL;

CV:WORD;

END_VAR

1.6.1.3.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CU BOOL TRUE: On detection of the rising edge of the signal, the function increments the
value of the CV output variable by 1.
FALSE: The function is waiting to detect the rising edge.
CD BOOL TRUE: On detection of the rising edge of the signal, the function decrements the
value of the CV output variable by 1.
RESET BOOL If TRUE the function loads the value 0 in the internal function count variable.
If TRUE The function loads the value of the PV variable in the internal function
LOAD BOOL
count variable.
PV WORD A variable with the value to preload in the internal function count variable.
Tbl. 1.135 Input parameters of function CTUD.

1.6.1.3.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CV variable is lower than the PV upper limit.
QU BOOL
TRUE: The value of the CV variable has reached the PV upper limit.
FALSE: The value of the CV variable is greater than 0.
QD BOOL
TRUE: The value of the CV variable has reached 0.
CV WORD Current value of the count variable.
Tbl. 1.136 Output parameters of function CTUD.

1.6.1.3.5 Remarks

This function is equivalent to COUNTER_UP_DOWN . Recommend using


COUNTER_UP_DOWN.

The CTUD function increments/decrements a count variable depending on the leading edges
produced in its inputs.

When the value of the LOAD variable is TRUE, the CV count variable initialises with the value
set in the PV input variable. When the function detects a rising edge in the CD input variable, the
CV variable decrements by one on each edge. Once CV has reached 0, the variable will not
continue to be decremented to negative values. When CV=0, the function activates the flag,
setting the QD output to TRUE.

When the value of the RESET variable is TRUE, the function sets the value of the CV count
variable to 0. Each time there is a rising edge in the CU input variable, it increments the CV

Ingeteam Proprietary All Rights Reserved Pag. 186


variable by 1. When the value of CV reached the limit set by the PV parameter, the function
activates the QU flag.

Ingeteam Proprietary All Rights Reserved Pag. 187


Ingeteam Proprietary All Rights Reserved Pag. 188
Fig. 1.5 .

1.6.1.3.6 Example

PROGRAM Example

VAR

CounterUpDown: CTUD ;

nTest:INT := 0;

END_VAR

CASE nTest OF

110: (* CounterUp : CTUD *)(*Use a CounterUpDown*)CounterUpDown( LOAD :=TRUE,


PV := 2) ;

111:CounterUpDown( LOAD :=FALSE);

112:CounterUpDown( CD :=TRUE);(*CV=1*)

113:CounterUpDown( CD :=FALSE);

114:CounterUpDown( CD :=TRUE); (*------- CV=0 Q=TRUE ---------*)

(*CounterUpDown.QD = TRUE *)

115:CounterUpDown( CD :=FALSE);

116:CounterUpDown( CD :=TRUE);(*CV=0 Q=FALSE*)

117:CounterUpDown( CD :=FALSE);

118:CounterUpDown( RESET :=TRUE, PV := 2) ;

119:CounterUpDown( RESET :=FALSE);

120:CounterUpDown( CU :=TRUE); (*CV=1*)

121:CounterUpDown( CU :=FALSE);

122:CounterUpDown( CU :=TRUE);(*------- Q=TRUE ---------*)

(*CounterUpDown.QU = TRUE *

123:CounterUpDown( CU :=FALSE);

124:CounterUpDown( CU :=TRUE);(*Q=TRUE*)

125:CounterUpDown( CU :=FALSE);

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 189


1.6.1.4 F_TRIG

1.6.1.4.1 Description

Falling Edge detection.

The F_TRIG function enables the detection of falling edges in a BOOL type signal to the input.

1.6.1.4.2 Syntax

FUNCTION_BLOCK F_TRIG

VAR_INPUT

CLK:BOOL;

END_VAR

VAR_OUTPUT

Q:BOOL;

END_VAR

1.6.1.4.3 Input parameters

Input Parameter Name Type Description


CLK BOOL Function input variable for detection of the falling edge.
Tbl. 1.137 Input parameters of function F_TRIG.

1.6.1.4.4 Output parameters

Output Parameter Name Type Description


Q BOOL Output variable with the pulse in the falling edge.
Tbl. 1.138 Output parameters of function F_TRIG.

1.6.1.4.5 Remarks

This function is equivalent to FALLING_TRIG. Recommend using FALLING_TRIG.

The F_TRIG FUNCTION can detect falling edges in the CLK input signal. This signal has TO be
a BOOL TYPE signal. When the FUNCTION detects a falling edge, it produces a pulse in its Q
output.

Ingeteam Proprietary All Rights Reserved Pag. 190


1.6.1.4.6 Example

PROGRAM Example

VAR

(*F_TRIG*)

FallingEdgePulse :F_TRIG;

OutputPulsesCounter:INT := 0;

nTest:INT:=0;

END_VAR

CASE nTest OF

1: (* FallingEdgePulse:F_TRIG *)

FallingEdgePulse( CLK :=TRUE );

IF(FallingEdgePulse.Q)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

2: (*Detects falling edges in the In_BL input signal.*)

FallingEdgePulse( CLK :=FALSE );

IF(FallingEdgePulse.Q)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.6.1.5 RS

1.6.1.5.1 Description

Bistable function, reset dominant.

The RS function is a bistable function with priority RESET. The input variables can be used to
request the SET status (TRUE status at the output) or the RESET status (FALSE status at the
output). In the event of a conflict the RESET command will prevail.

Ingeteam Proprietary All Rights Reserved Pag. 191


1.6.1.5.2 Syntax

FUNCTION_BLOCK RS

VAR_INPUT

SET:BOOL;

RESET1:BOOL;

END_VAR

VAR_OUTPUT

Q1:BOOL;

END_VAR

1.6.1.5.3 Input parameters

Input Parameter Name Type Description


SET BOOL Input variable that contains the SET command.
RESET1 BOOL Input variable that contains the RESET command.
Tbl. 1.139 Input parameters of function RS.

1.6.1.5.4 Output parameters

Output Parameter Name Type Description


Q1 BOOL Output variable with the status requested by the input variables.
Tbl. 1.140 Output parameters of function RS.

1.6.1.5.5 Remarks

This function is equivalent to RESET_SET. Recommend using RESET_SET.

The RS function must have two BOOL type input parameters. One of the variables will be
assigned to the SET command and the other to the RESET command. The function will calculate
the status for the output according to the logic, with the RESET command having priority.

SET RESET1 Q1

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE FALSE

Ingeteam Proprietary All Rights Reserved Pag. 192


1.6.1.5.6 Example

PROGRAM Example

VAR

(*RS*)

FlipFlopRS : RS := ( Q1 :=0 ) ;

nTest : DINT := 0;

END_VAR

CASE nTest OF

1: (* FlipFlop:RS *)

(*Use a FlipFlop*)

FlipFlopRS( SET := TRUE );(* => Q1=1*)

2:FlipFlopRS( SET := FALSE );(* => Q1= No change*)

3:FlipFlopRS( RESET1 := TRUE );(* => Q1=0*)

4:FlipFlopRS( RESET1 := FALSE );(* => Q1=0*)

END_CASE;

1.6.1.6 RTC

1.6.1.6.1 Description

Real Time Counter management function.

The RTC (Real Time Counter) function returns the date and time that have elapsed since a given
moment. The user can start the clock at a specific date and time, and the function will return the
current date and time at each call.

1.6.1.6.2 Syntax

FUNCTION_BLOCK RTC

VAR_INPUT

EN:BOOL;

PDT:DT;

END_VAR

VAR_OUTPUT

Ingeteam Proprietary All Rights Reserved Pag. 193


Q:BOOL;

CDT:DT;

END_VAR

1.6.1.6.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is disabled, waiting to detect the rising edge.
The CDT output will be DT#1970-01-01-00:00:00.
EN BOOL
TRUE: When the rising edge occurs, it loads the PDT value in CDT.
While it remains at TRUE, the function increases the time counter.
Date and time that will be loaded in the CDT output variable when a rising edge
PDT DT
occurs in the ?EN? input.
Tbl. 1.141 Input parameters of function RTC.

1.6.1.6.4 Output parameters

Output Parameter Name Type Description


FALSE: The function is not enabled since the input parameter ?EN?:=FALSE.
Q BOOL
TRUE The function is enabled and counting the elapsed time.
CDT DT Date and time of output calculated by the RTC function.
Tbl. 1.142 Output parameters of function RTC.

1.6.1.6.5 Remarks

This function is equivalent to RTC_TIMER . Recommend using RTC_TIMER.

To understand the operation of the RTC function, three situations that will produce different
outputs should be considered:

While the input variable EN:=FALSE, the function will be disabled and therefore will not
increment the time. In this situation, the output Q:=FALSE and the date and time delivered in
CDT:=01-01-1970-00:00:00.

When there is a rising edge in the EN input, the function sets Q:=TRUE and loads the value of
PDT in the CDT variable.

While the input variable EN:=TRUE, the function will be enabled and will therefore increment the
value of the output date and time of the CDT variable.

1.6.1.6.6 Example

PROGRAM Example

VAR

RunTimeCounter : RTC;

Ingeteam Proprietary All Rights Reserved Pag. 194


nTest:INT := 0;

END_VAR

CASE nTest OF

1: (* RunTimeCounter : RTC *)

(* Use a RunTimeCounter*)

RunTimeCounter( EN :=FALSE) ;

(*RunTimeCounter.Q = FALSE *)

2:RunTimeCounter( EN:=TRUE, PDT:=DT#2010-07-14-15:36:30);

(*RunTimeCounter.Q = TRUE *)

(*RunTimeCounter.CDT = actual value *)

3:RunTimeCounter( EN :=FALSE) ;

(*RunTimeCounter.CDT = DT#1970-01-01-00:00:00 *)

END_CASE;

1.6.1.7 R_TRIG

1.6.1.7.1 Description

Rising Edge detection.

The R_TRIG function detects rising edges in a BOOL type signal at the input.

1.6.1.7.2 Syntax

FUNCTION_BLOCK R_TRIG

VAR_INPUT

CLK:BOOL;

END_VAR

VAR_OUTPUT

Q:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 195


1.6.1.7.3 Input parameters

Input Parameter Name Type Description


CLK BOOL Function input variable to detect the rising edge.
Tbl. 1.143 Input parameters of function R_TRIG.

1.6.1.7.4 Output parameters

Output Parameter Name Type Description


Q BOOL Output variable with the pulse in the rising edge.
Tbl. 1.144 Output parameters of function R_TRIG.

1.6.1.7.5 Remarks

This function is equivalent to RISING_TRIG. Recommend using RISING_TRIG.

The R_TRIG function can detect rising edges in the CLK input signal. This signal has to be a
BOOL type signal. When the function detects a rising edge, it produces a pulse in its Q output.

1.6.1.7.6 Example

PROGRAM Example

VAR

(*R_TRIG*)

RisingEdgePulse :R_TRIG;

OutputPulsesCounter:INT := 0;

nTest:INT:=0;

END_VAR

CASE nTest OF

1: (* RisingEdgePulse :R_TRIG *)

RisingEdgePulse(CLK:=FALSE );

IF(RisingEdgePulse.Q)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

2: (* Detects rising edges in the In_BL input signal *)

RisingEdgePulse(CLK:=TRUE);

Ingeteam Proprietary All Rights Reserved Pag. 196


IF(RisingEdgePulse.Q)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.6.1.8 SR

1.6.1.8.1 Description

Bistable function, set dominant.

The SR function is a bistable function with priority SET. The input variables can be used to
request the SET status (TRUE status at the output) or the RESET status (FALSE status at the
output). In the event of a conflict the SET command will prevail.

1.6.1.8.2 Syntax

FUNCTION_BLOCK SR

VAR_INPUT

SET1:BOOL;

RESET:BOOL;

END_VAR

VAR_OUTPUT

Q1:BOOL;

END_VAR

1.6.1.8.3 Input parameters

Input Parameter Name Type Description


SET1 BOOL Input variable that contains the SET command.
RESET BOOL Input variable that contains the RESET command.
Tbl. 1.145 Input parameters of function SR.

Ingeteam Proprietary All Rights Reserved Pag. 197


1.6.1.8.4 Output parameters

Output Parameter Name Type Description


Q1 BOOL Output variable with the status requested by the input variables.
Tbl. 1.146 Output parameters of function SR.

1.6.1.8.5 Remarks

This function is equivalent to SET_RESET. Recommend using SET_RESET.

The SR function must have two BOOL type input parameters. One of the variables will be
assigned to the SET command and the other to the RESET command. The function will calculate
the status for the output according to the logic, with the SET command having priority.

SET1 RESET Q1

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE TRUE

1.6.1.8.6 Example

(*PROGRAM Example*)

VAR

(*SR*)

FlipFlopSR: SR:=(Q1 :=0);

nTest:DINT:= 0;

END_VAR

CASE nTest OF

1:(* FlipFlop:SR*)

(*Use a FlipFlop*)

FlipFlopSR( SET1:= TRUE );(* =>Q1=1*)

2:FlipFlopSR( SET1:= FALSE );(* =>Q1= No change *)

3:FlipFlopSR( RESET := TRUE );(* =>Q1=0*)

4:FlipFlopSR( RESET := FALSE );(* =>Q1=0*)

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 198


1.6.1.9 TOF

1.6.1.9.1 Description

Timer Off Delay.

The TOF function has the same purpose as the TOF_RELATIVE function, which is timing the
disconnection of a boolean input variable. However, unlike TOF_RELATIVE, the TOF function
considers absolute execution time and is not affected by whether the function block is called or
not to count the time.

Function output will be at 1 while the input is also at 1. As soon as a falling edge is detected in
the input, the function begins timing based on the established parameter. The function output will
pass to 0 a time after the falling edge has occurred in the input.

If the input does not remain at 0 during the period set for timing, the output will at no time change
to 0. The function will wait for a repeated falling edge to perform new complete timing.

Advice: The TOF function considers absolute time, regardless of whether the function block is
called or not. If the block is not being called, but the time has run out, when the function is called
for the first time the output will show timing complete status.

1.6.1.9.2 Syntax

FUNCTION_BLOCK TOF

VAR_INPUT

IN:BOOL;

PT:TIME;

END_VAR

VAR_OUTPUT

Q:BOOL;

ET:TIME;

END_VAR

1.6.1.9.3 Input parameters

Input Parameter Name Type Description


IN BOOL Input variable to the function for disconnection timing.
PT TIME Value of the time for which the disconnection timing is required.
Tbl. 1.147 Input parameters of function TOF.

Ingeteam Proprietary All Rights Reserved Pag. 199


1.6.1.9.4 Output parameters

Output Parameter Name Type Description


Q BOOL Output variable that is the result of performing the disconnection timing.
ET TIME Time elapsed since timing started.
Tbl. 1.148 Output parameters of function TOF.

1.6.1.9.5 Remarks

This function is equivalent to TOF_ABSOLUTE. Recommend using TOF_ABSOLUTE.

The purpose OF the TOF FUNCTION is TO obtain in an output variable (Q), the equivalent OF
disconnection timing OF a digital input signal (IN). This timing is performed according TO the PT
TIME parameter.

AT the start, the FUNCTION sets its output TO 1 AT the same instant that the input signal
changes TO 1.

Once this occurs, the function remains waiting to detect a falling edge in the input. When this
edge occurs, timing begins counting internally. The function continues counting time as long as
the input is set at 0. Once the pre-established time has run out, the function will set the output to
0. This output will remain at 0 while the input continues at the low value.

If once the falling edge has occurred in the input, the input does not remain inactive during the
time established for timing, then the function will at no point set the output to 0. The function will
remain on standby to detect a falling edge in the input.

The time elapsed during timing can be ascertained at any time by referring to the values of the
ET output variable.

1.6.1.9.6 Example

PROGRAM Example

VAR

(*TOF*)

TimerOff TOF;

nTest: DINT := 0;

END_VAR

CASE nTest OF

1: (*Reset timer*)

TimerOff( IN :=TRUE );

2: (* TimerOff : TOF *)

Ingeteam Proprietary All Rights Reserved Pag. 200


(*Get an output signal on 5 seconds with TImerOff *)

TimerOff(IN :=FALSE,

PT:= T#5s) ;

(* TimerOn.Q = FALSE until time elapsed *)

(* TimerOn.ET = timer value increasing *)

END_CASE

1.6.1.10 TON

1.6.1.10.1 Description

Timer on delay.

The TON function has the same purpose as the TON_RELATIVE function, which is timing the
connection of a boolean input variable. However, unlike TON_RELATIVE, the TON function
considers absolute execution time and is not affected by whether the function block is called or
not to count the time.

As soon as a rising edge is detected in the input, the function begins timing based on the
established parameter. Once the time has run out, the function will set the output to 1.

If the input does not remain at 1 during the period set for timing, the output will at no time change
to 1. The function will wait for a repeated rising edge to perform new complete timing.

1.6.1.10.2 Syntax

FUNCTION_BLOCK TON

VAR_INPUT

IN:BOOL;

PT:TIME;

END_VAR

VAR_OUTPUT

Q:BOOL;

ET:TIME;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 201


1.6.1.10.3 Input parameters

Input Parameter Name Type Description


IN BOOL Input variable to the function for connection timing.
PT TIME Time value for which the connection timing is required.
Tbl. 1.149 Input parameters of function TON.

1.6.1.10.4 Output parameters

Output Parameter Name Type Description


Q BOOL Output variable that is the result of performing the connection timing.
ET TIME Time elapsed since timing started.
Tbl. 1.150 Output parameters of function TON.

1.6.1.10.5 Remarks

This function is equivalent to TON_ABSOLUTE. Recommend using TON_ABSOLUTE.

The TON function considers absolute time, regardless of whether the function block is called or
not. If the block is not being called, but the time has run out, when the function is called for the
first time the output will show the timing complete status.

The purpose of the TON function is to obtain in an output variable (Q), the equivalent of
connection timing of a digital input signal (IN). This timing is performed according to the PT time
parameter.

The function will remain waiting to detect a rising edge in the input. When this edge occurs,
timing begins counting internally. The function continues counting time as long as the input is set
at 1. Once the pre-established time has run out, the function will set the output to 1. This output
will remain at 1 while the input continues at the high value.

If once rising edge has occurred in the input, the input does not remain active during the time
established for timing, then the function will at no point set the output to 1. The function will
remain on standby to detect a rising edge in the input.

The time elapsed during timing can be ascertained at any time by referring to the values of the
ET output variable.

1.6.1.10.6 Example

PROGRAM TON_Example

VAR

(*TON*)

TimerOn : TON;

Ingeteam Proprietary All Rights Reserved Pag. 202


nTest : DINT := 0;

END_VAR

CASE nTest OF

1: (*Reset timer*)

TimerOn( IN :=FALSE );

2: (* TimerOn : TON *)

(*Get an output signal on 5 seconds with TImerOn *)

TimerOn(IN :=TRUE,

PT:= T#5s) ;

(* TimerOn.Q = FALSE until time elapsed *)

(* TimerOn.ET = timer value increasing *)

END_CASE

1.6.1.11 TP

1.6.1.11.1 Description

Timer Pulse.

The TP function generates a pulse of a certain duration on detecting an input rising edge.

1.6.1.11.2 Syntax

FUNCTION_BLOCK TP

VAR_INPUT

IN:BOOL;

PT:TIME;

END_VAR

VAR_OUTPUT

Q:BOOL;

ET:TIME;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 203


1.6.1.11.3 Input parameters

Input Parameter Name Type Description


IN BOOL Input variable to the function to detect the rising edge and begin timing.
PT TIME Period of time to maintain the output pulse at TRUE.
Tbl. 1.151 Input parameters of function TP.

1.6.1.11.4 Output parameters

Output Parameter Name Type Description


Q BOOL The output variable that is a result of maintaining the value established in PT at TRUE.
ET TIME Time elapsed from when timing started.
Tbl. 1.152 Output parameters of function TP.

1.6.1.11.5 Remarks

This function is equivalent to TIMER_PULSE. Recommend using TIMER_PULSE.

The use of the TP function is similar to that of timing.

A BOOL type variable must be assigned to the IN input. When a rising edge occurs in this
variable, the function sets the Q output to TRUE and begins counting the time (output variable
ET). As soon as this time (ET) matches the time set in the PT input parameter, the function will
set the Q output variable to FALSE.

If the IN input is not set to TRUE for a time equal to PT, the function will maintain the Q output to
TRUE until the time has elapsed. If during this time span when IN:=FALSE and Q:=TRUE,
another rising edge occurs in the IN input, then the function will not take it into consideration and
will continue with the original timing.

1.6.1.11.6 Example

PROGRAM Example

VAR

(*TP*)

TimerPulse : TP;

nTest:INT := 0;

END_VAR

CASE nTest OF

1: (*Reset timer*)

TimerPulse( IN :=FALSE ) ;

Ingeteam Proprietary All Rights Reserved Pag. 204


2: (* TimerPulse : TP *)

(*Get an pulse output signal on 3 seconds with TimerOn *)

TimerPulse( IN :=TRUE,

PT:= T#3s) ;

(* TimerPulse.Q = FALSE until time elapsed *)

(* TimerPulse.ET = timer value increasing *)

END_CASE;

1.7 Regulation_01

The following tables sumarize the entities contained in Regulation_01:

Name Description
BLINK_SIGNAL Function block to simulate a square wave signal.
Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring
DELAY_COUNTER
the delay between two input signals
DERIVATIVE_R Function block to approximate the derivative of a real variable.
FREQUENCY_MEASURE Function that measures the frequency of a signal.
GENERATION Function block for generating some periodic functions.
HYSTERESIS_REG Hysteresis function block.
INTEGRAL_R Function block to approximate the integral of In_R over the time.
LIMIT_ALARM_REG Function for variable limit surveillance.
LINEAR_TRAFO_R Linear transformation.
PD_REG PD controller.
Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring
PERIOD_COUNTER
the period of the signal connected to a GATE
PID_FIXCYCLE_REG PID controller.
PID_REG PID controller.
Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring
POSITION_COUNTER
a position of a signal on input channel
RAMP_I Function block to limit the slope of a value to a certain value.
RAMP_R Function block to limit the slope of a value to a certain value.
READ_SSI_COUNTER Function to read an SSI_COUNTER
Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring
SPEED_COUNTER
the speed of a signal on input channel
STATISTICS_I Function block for statistics.
STATISTICS_R Function block for statistics.
VARIANCE_R Function block to calculate the mathematical variance of a variable.
Tbl. 1.153 Functions, Function Blocks, and Programs.

Ingeteam Proprietary All Rights Reserved Pag. 205


1.7.1 Functions

1.7.1.1 BLINK_SIGNAL

1.7.1.1.1 Description

Function block to simulate a square wave signal.

The BLINK_SIGNAL function generates a sequence of pulses with high and low status times that
can be configured.

1.7.1.1.2 Syntax

FUNCTION_BLOCK BLINK_SIGNAL

VAR_INPUT

Enable_BL:BOOL;

TimeLow_T:TIME;

TimeHigh_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.7.1.1.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enables the generation of the pulse sequence.
TimeLow_T TIME Time that the signal will remain in low status.
TimeHigh_T TIME Time that the signal will remain in high status.
Tbl. 1.154 Input parameters of function BLINK_SIGNAL.

1.7.1.1.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output signal generated.
Tbl. 1.155 Output parameters of function BLINK_SIGNAL.

Ingeteam Proprietary All Rights Reserved Pag. 206


1.7.1.1.5 Remarks

The BLINK_SIGNAL function generates a pulse sequence with the parameters established in
TimeLow_T and TimeHigh_T while the input variable Enable_BL is TRUE.

The pulse sequence is generated taking into account a high status time (TimeHigh_T) and
another low status time (TimeLow_T).

The output will be a BOOL type variable.

1.7.1.1.6 Example

PROGRAM Example

VAR

(*BLINK*)

BlinkValue:BLINK_SIGNAL := ( Enable_BL :=TRUE,

TimeLow_T := T#1000ms,

TimeHigh_T := T#1500ms ) ;

OutputBlinkSignal :BOOL;

END_VAR

(*Generate a blink signal*)

BlinkValue( Out_BL => OutputBlinkSignal );

1.7.1.2 COUNTER_DOWN

1.7.1.2.1 Description

The COUNTER_DOWN function performs a decrement operation on detecting edges in one of


its inputs. When the value to count down reaches 0, the function activates an indication flag.

1.7.1.2.2 Syntax

FUNCTION_BLOCK COUNTER_DOWN

VAR_INPUT

CounterDown_BL:BOOL;

Load_BL:BOOL;

StartValue_W:WORD;

Ingeteam Proprietary All Rights Reserved Pag. 207


END_VAR

VAR_OUTPUT

Out_BL:BOOL;

CounterValue_W:WORD;

END_VAR

1.7.1.2.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterDown_BL BOOL TRUE: On detection of the rising edge of the signal, the function decrements the value
of the CounterValue_W output variable by 1.
If TRUE The function loads the value of the StartValue_W variable in the internal
Load_BL BOOL
function count variable.
StartValue_W WORD A variable with the value to preload in the internal function count variable.
Tbl. 1.156 Input parameters of function COUNTER_DOWN.

1.7.1.2.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is greater than 0.
Out_BL BOOL
TRUE: The value of the CounterValue_W variable has reached 0.
CounterValue_W WORD Current value of the decremented variable.
Tbl. 1.157 Output parameters of function COUNTER_DOWN.

1.7.1.2.5 Remarks

When the Load_BL variable is TRUE, the CounterValue_W count variable initialises with the
value set in the StartValue_W input parameter. When the function detects a rising edge in the
CounterDown_BL input variable, the CounterValue_W variable decrements by 1 on each edge.
Once CounterValue_W has reached 0, the variable will not continue to count down to negative
values. When CounterValue_W=0, the function activates the flag and sets the Out_BL output to
TRUE.

1.7.1.2.6 Example

PROGRAM Example

VAR

CounterDown : COUNTER_DOWN;

nTest:INT := 0;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 208


CASE nTest OF

1: (* CounterDown : CTD *)

(*Use a CounterDown*)

CounterDown(Load_BL:=TRUE, StartValue_W := 2) ;

2:CounterDown(Load_BL:=FALSE);

3:CounterDown(CounterDown_BL:=TRUE); (*CounterValue_W=1*)

4:CounterDown(CounterDown_BL:=FALSE);

5:CounterDown(CounterDown_BL:=TRUE);

6:CounterDown(CounterDown_BL:=FALSE);

7CounterDown(CounterDown_B :=TRUE);(*---Out_BL=TRUE CounterValue_W = 0 ---*)

8:CounterDown(CounterDown_BL :=FALSE);

END_CASE;

1.7.1.3 COUNTER_UP

1.7.1.3.1 Description

The COUNTER_UP function increments an output variable on detecting rising edges in one of its
inputs. The function returns an indication flag when the count variable exceeds the value defined
as the upper limit.

1.7.1.3.2 Syntax

FUNCTION_BLOCK COUNTER_UP

VAR_INPUT

CounterUp_BL:BOOL;

Reset_BL:BOOL;

CounterLimit_W:WORD;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

CounterValue_W:WORD;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 209


1.7.1.3.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterUp_BL BOOL TRUE: On detection of the rising edge of the signal, the function increments the value of the
CounterValue_W output variable by 1.
Reset_BL BOOL If TRUE the function loads the value 0 in the internal function count variable.
CounterLimit_W WORD Variable with the value that the function is compared with.
Tbl. 1.158 Input parameters of function COUNTER_UP.

1.7.1.3.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is lower than the CounterLimit_W upper
Out_BL BOOL limit.TRUE:
The value of the CounterValue_W variable has reached the CounterLimit_W upper limit.
CounterValue_W WORD Current value of the incremented variable.
Tbl. 1.159 Output parameters of function COUNTER_UP.

1.7.1.3.5 Remarks

When the value of the Reset_BL variable is TRUE, the function sets the value of the
CounterValue_W count variable to 0. Each time there is a rising edge in the CounterUp_BL input
variable, the function will increment the CounterValue_W variable by 1. When the value of
CounterValue_W reached the limit set by the CounterLimit_W parameter, the function will
activate the Out_BL flag.

1.7.1.3.6 Example

PROGRAM Example

VAR

CounterDown : COUNTER_DOWN;

nTest:INT := 0;

END_VAR

CASE nTest OF

1: (* CounterUp : COUNTER_UP *)

(*Use a CounterUp*)

CounterUp( Reset_BL :=TRUE, CounterLimit_W := 2) ;

2:CounterUp( Reset_BL :=FALSE);

3:CounterUp( CounterUp_BL :=TRUE);(* CounterValue_W=1 *)

Ingeteam Proprietary All Rights Reserved Pag. 210


4:CounterUp( CounterUp_BL :=FALSE);

5:CounterUp( CounterUp_BL :=TRUE);

6:CounterUp( CounterUp_BL :=FALSE);

7:CounterUp( CounterUp_BL :=TRUE);(*------- Out_BL=TRUE CounterValue_W = 2 ---------*)

8:CounterUp( CounterUp_BL :=FALSE);

END_CASE;

1.7.1.4 COUNTER_UP_DOWN

1.7.1.4.1 Description

The COUNTER_UP_DOWN function is a combination of the COUNTER_DOWN function for the


decrement counter and the COUNTER_UP function for the increment counter.

The function performs a decrement operation on detecting edges in one of its inputs. When the
value to decrement reaches 0, the function activates an indication flag.

The function increments an output variable on detecting rising edges in one of its inputs. The
function returns an indication flag when the count variable exceeds the value defined as the
upper limit

1.7.1.4.2 Syntax

FUNCTION_BLOCK COUNTER_UP_DOWN

VAR_INPUT

CounterUp_BL:BOOL;

CounterDown_BL:BOOL;

Reset_BL:BOOL;

Load_BL:BOOL;

Value_W:WORD;

END_VAR

VAR_OUTPUT

OutUp_BL:BOOL;

OutDown_BL:BOOL;

CounterValue_W:WORD;

Ingeteam Proprietary All Rights Reserved Pag. 211


END_VAR

1.7.1.4.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterUp_BL BOOL TRUE: On detection of the rising edge of the signal, the function increments the
value of the CounterValue_W output variable by 1.
FALSE: The function is waiting to detect the leading edge.
CounterDown_BL BOOL TRUE: On detection of the rising edge of the signal, the function decrements the
value of the CounterValue_W output variable by 1.
Reset_BL BOOL If TRUE: the function loads the value 0 in the internal function count variable.
The function loads the value of the Value_W variable in the internal function count
Load_BL BOOL
variable.
Variable with the value to preload in the internal function count variable, which will
Value_W WORD
be taken as the upper limit.
Tbl. 1.160 Input parameters of function COUNTER_UP_DOWN.

1.7.1.4.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is lower than the
CounterLimit_W upper limit.
OutUp_BL BOOL
TRUE: The value of the CounterValue_W variable has reached the CounterLimit_W
upper limit.
FALSE: The value of the CounterValue_W variable is greater than 0.
OutDown_BL BOOL
TRUE: The value of the CounterValue_W variable has reached 0.
CounterValue_W WORD Current value of the count variable.
Tbl. 1.161 Output parameters of function COUNTER_UP_DOWN.

1.7.1.4.5 Remarks

The COUNTER_UP_DOWN function increments/decrements a count variable depending on the


rising edges that occur in its inputs.

When the Load_BL variable is TRUE, the CounterValue_W count variable is initialised with the
value set in the Value_W input parameter. When the function detects a rising edge in the
CounterDown_BL input variable, the CounterValue_W variable decrements by 1 on each edge.
Once CounterValue_W has reached 0, the variable will not continue to count down to negative
values. When CounterValue_W=0, the function activates the flag, setting the OutDown_BL
output to TRUE.

When the value of the Reset_BL variable is TRUE, the function sets the value of the
CounterValue_W count variable to 0. Each time there is a rising edge in the CounterUp_BL input
variable, the function will increment the CounterValue_W variable by 1. When the value of
CounterValue_W reached the limit set by the Value_W parameter, the function will activate the
OutUp_BL flag.

Ingeteam Proprietary All Rights Reserved Pag. 212


1.7.1.4.6 Example

PROGRAM Example

VAR

(*COUNTER_UP_DOWN *)

CounterUpDown : COUNTER_UP_DOWN;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(* CounterUpDown : COUNTER_UP_DOWN *)

(*Use a CounterUpDown*)

CounterUpDown(Load_BL :=TRUE, Value_W := 2) ;

2:CounterUpDown(Load_BL :=FALSE);

3:CounterUpDown(CounterDown_BL :=TRUE);

4:CounterUpDown(CounterDown_BL :=FALSE);

5:CounterUpDown(CounterDown_BL:=TRUE);(*-------OutDown_BL=TRUE
CounterValue_W = 0 ---------*)

6:CounterUpDown(CounterDown_BL:=FALSE);

7:CounterUpDown(CounterDown_BL:=TRUE);

8:CounterUpDown(CounterDown_BL:=FALSE);

9:CounterUpDown(Reset_BL:=TRUE, Value_W := 2) ;

10:CounterUpDown(Reset_BL:=FALSE);

11:CounterUpDown(CounterUp_BL:=TRUE);

12:CounterUpDown(CounterUp_BL:=FALSE);

13:CounterUpDown(CounterUp_BL:=TRUE);

14:CounterUpDown(CounterUp_BL:=FALSE);

15:CounterUpDown(CounterUp_BL:=TRUE);(*-------OutuUp_BL=FALSECounterValue_W=
2 ---------*)

16:CounterUpDown(CounterUp_BL:=FALSE);

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 213


1.7.1.5 DELAY_COUNTER

1.7.1.5.1 Description

Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring the
delay between two input signals

1.7.1.5.2 Syntax

FUNCTION_BLOCK DELAY_COUNTER

VAR_INPUT

Enable_BL:BOOL;

CounterType_enCounterType:enCounterType;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterConfigure_ADR:DWORD;

CounterConfigureSizeBy_DI:DINT;

CounterOverflowUs_R:REAL:=30000000;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

DelayUs_R:REAL;

Status_enCounterRet:enCounterRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 214


1.7.1.5.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Flag to Enable the function.
CounterType_enCounterType enCounterType Counter module type.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
Pointer to the memory buffer where configuration structure is stored.
CounterConfigure_ADR DWORD For the IC3325 module use stIC3325Delay.
For the IC3391 module use stIC3391Delay.
CounterConfigureSizeBy_DI DINT Size of the configuration structure in bytes.
Maximum delay time that can be measured in microseconds.
CounterOverflowUs_R REAL If the delay time measured is bigger, the function will return the status
Counter Overflow.
Tbl. 1.162 Input parameters of function DELAY_COUNTER.

1.7.1.5.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Execution of the FB has finished
DelayUs_R REAL Measured delay in microseconds
Result of the FB execution.
Status_enCounterRet enCounterRet
The data structure is in the Regulation02.lib library
Tbl. 1.163 Output parameters of function DELAY_COUNTER.

1.7.1.5.5 Data Types

1.7.1.5.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.164 Enumerator enCounterType.

1.7.1.5.5.2 enIC3391InputSignal

Value Description
IN0 (0) Input 0
IN1 (1) Input 1
IN2 (2) Input 2
IN3 (3) Input 3
IN4 (4) Input 4
IN5 (5) Input 5
Tbl. 1.165 Enumerator enIC3391InputSignal.

Ingeteam Proprietary All Rights Reserved Pag. 215


1.7.1.5.5.3 stIC3325Delay

Field Name Type Description


CounterNum_DI DINT Counter number to use for the delay measuring.
InputSignal1_enIC3325InputSignal enIC3325InputSignal Input Signal 1 (Conected to one of the Gates (G0G7)).
Logic of the Input Signal 1 (TRUE--> Inverted Logic,
Signal1Inverted_BL BOOL
FALSE-->Direct Logic).
InputSignal2_enIC3325InputSignal enIC3325InputSignal Input Signal 2 (Conected to one of the Gates (G0G7)).
Logic of the Input Signal 2 (TRUE--> Inverted Logic,
Signal2Inverted_BL BOOL
FALSE--> Direct Logic).
Tbl. 1.166 Fields of the stIC3325Delay structure.

1.7.1.5.5.4 stIC3391Delay

Field Name Type Description


CounterNum_DI DINT Counter number to use for the delay measuring.
InputSignal1_enIC3391InputSignal enIC3391InputSignal Input signal 1 (IN0IN5).
Logic of the Input Signal 1 (TRUE--> Inverted Logic,
Signal1Inverted_BL BOOL
FALSE--> Direct Logic).
InputSignal2_enIC3391InputSignal enIC3391InputSignal Input signal 2 (IN0IN5).
Logic of the Input Signal 2 (TRUE--> Inverted Logic,
Signal2Inverted_BL BOOL
FALSE--> Direct Logic).
Tbl. 1.167 Fields of the stIC3391Delay structure.

Ingeteam Proprietary All Rights Reserved Pag. 216


1.7.1.5.5.5 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.168 Enumerator enCounterRet.

1.7.1.5.6 Example

PROGRAM Example_DELAY_COUNTER

(*This example measures the delay between signals connected to the IN1 and IN2 inputs of a
IC3391 module.*)

VAR

DelayCounter: DELAY_COUNTER;(*Function to measure the delay*)

EnDelayCounter: BOOL;(*Enable to measure the delay*)

(*Configuration to define the counter and inputs to use to measure the delay*)

DelayCounterConf: stIC3391Delay := (CounterNum_DI:=1(*Counter number 1*)

InputSignal1_enIC3391InputSignal:=IN1,(*Signal connected to input 1 of the


module*)

Signal1Inverted_BL:=FALSE,(*Not inverted*)

Ingeteam Proprietary All Rights Reserved Pag. 217


InputSignal2_enIC3391InputSignal:=IN2,(*Signal connected to input 2 of the
module*)

Signal2Inverted_BL:=FALSE); (*Not inverted*)

END_VAR

(*Call to the DELAY_COUNTER function*)

DelayCounter(

Enable_BL:=EnDelayCounter,(*Enable to measure the delay*)

CounterType_enCounterType:=IC3391,(*Module type*)

ChassisNum_DI:=0,(*Chasis number*)

SlotNum_DI:=7,(*Slot number*)

CounterConfigure_ADR:=ADR(DelayCounterConf),(*Address to configuration structure*)

CounterConfigureSizeBy_DI:=SIZEOF(DelayCounterConf),(*Size of configuration
structure*)

CounterOverflowUs_R:=1000000,(*Maximum delay for returning overflow in the measure


(1 Sec)*)

Done_BL=> ,(*The FB has finished*)

DelayUs_R=> , (*Measured delay*)

Status_enCounterRet=> );(*Finished status of FB*)

1.7.1.6 DERIVATIVE_R

1.7.1.6.1 Description

Function block to approximate the derivative of a real variable.

The DERIVATIVE_R function approximates the mathematical derivative of an input variable. To


do so, an input signal and the time that elapses between calls to functions are entered.

1.7.1.6.2 Syntax

FUNCTION_BLOCK DERIVATIVE_R

VAR_INPUT

In_R:REAL;

TimeMsec_DW:DWORD;

Ingeteam Proprietary All Rights Reserved Pag. 218


Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

END_VAR

1.7.1.6.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input variable to operate on.
TimeMsec_DW DWORD Time between calls to function in milliseconds.
Reset_BL BOOL If TRUE resets the DERIVATIVE_R function.
Tbl. 1.169 Input parameters of function DERIVATIVE_R.

1.7.1.6.4 Output parameters

Output Parameter Name Type Description


Function output variable.
Out_R REAL
This will correspond to the input variable derivative.
Tbl. 1.170 Output parameters of function DERIVATIVE_R.

1.7.1.6.5 Remarks

To use the DERIVATIVE_R function all that is required is the entry of a signal to derive (In_R)
and the time between calls to function (TimeMsec_DW) in milliseconds.

Fig. 1.6 .

Ingeteam Proprietary All Rights Reserved Pag. 219


1.7.1.6.6 Example

PROGRAM Example

VAR

(*RAMP_R*)

(*DERIVATIVE_R*)

(*Inputs*)

SamplesCounter:INT:=0;

InputTriangle : ARRAY [1..100] OF REAL := -5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4,

-5,-4,-3,-2,-1, 0, 1, 2, 3, 4,

5, 4 ,3 ,2 ,1, 0,-1,-2,-3,-4;

(*output variables*)

OutputDerivate : ARRAY [1..100] OF REAL;

(*function*)

DeltaOp: DERIVATIVE_R := (TimeMsec_DW :=10);

END_VAR

(*Samples Counter*)

IF(SamplesCounter>0 AND SamplesCounter<100 )

THEN SamplesCounter := SamplesCounter+1;

ELSE SamplesCounter:=1;

END_IF

(*Get Input Derivate*)

DeltaOp( In_R:=InputTriangle[ SamplesCounter ],

Out_R => OutputDerivate[ SamplesCounter ]);

Ingeteam Proprietary All Rights Reserved Pag. 220


1.7.1.7 FALLING_TRIG

1.7.1.7.1 Description

Falling Edge detection.

The FALLING_TRIG function detects falling edges in a BOOL type signal at the input.

1.7.1.7.2 Syntax

FUNCTION_BLOCK FALLING_TRIG

VAR_INPUT

In_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.7.1.7.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Function input variable for detecting the falling edge.
Tbl. 1.171 Input parameters of function FALLING_TRIG.

1.7.1.7.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the pulse in the falling edge.
Tbl. 1.172 Output parameters of function FALLING_TRIG.

1.7.1.7.5 Remarks

The F_TRIG function can detect falling edges in the In_BL input signal. This signal has to be a
BOOL type signal. When the function detects a falling edge, it produces a pulse in its Out_BL
output.

Ingeteam Proprietary All Rights Reserved Pag. 221


1.7.1.7.6 Example

PROGRAM Example

VAR

(*FALLING_TRIG*)

FallingEdgePulse :FALLING_TRIG;

OutputPulsesCounter:INT := 0;

nTest:INT :=0;

END_VAR

CASE nTest OF

1:(* FallingEdgePulse:F_TRIG *)

FallingEdgePulse( In_BL :=TRUE );

IF(FallingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

2:(*Detects falling edges in the In_BL input signal.*)

FallingEdgePulse( In_BL :=FALSE );

IF(FallingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.7.1.8 FREQUENCY_MEASURE

1.7.1.8.1 Description

Function that measures the frequency of a signal.

The FREQUENCY_MEASURE function measures the frequency of a BOOL type input signal. It
is possible to define over how many cycles the output frequency should be measured.

Ingeteam Proprietary All Rights Reserved Pag. 222


1.7.1.8.2 Syntax

FUNCTION_BLOCK FREQUENCY_MEASURE

VAR_INPUT

In_BL:BOOL;

Periods_I:INT(1..10);

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

Valid_BL:BOOL;

END_VAR

1.7.1.8.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Input signal for which the frequency is to be measured.
Number of periods used to calculate the frequency (1..10).
Periods_I INT(1..10)
A period is considered as the time between two rising edges.
Reset_BL BOOL If TRUE, resets the frequency calculation performed up to this moment.
Tbl. 1.173 Input parameters of function FREQUENCY_MEASURE.

1.7.1.8.4 Output parameters

Output Parameter Name Type Description


Out_R REAL Value of the average frequency measured for the input signal in Hz
FALSE: This will be false until the first measurement has been performed or if the
Valid_BL BOOL period is > 3*Out_R.This indicates something is wrong with the inputs.
TRUE: The calculation of frequency has been completed correctly.
Tbl. 1.174 Output parameters of function FREQUENCY_MEASURE.

1.7.1.8.5 Remarks

To measure the frequency of a boolean signal, the signal must be entered in In_R. To start all
the calculation values from 0, the Reset_BL input can be activated with the TRUE value.

With the Reset_BL value deactivated, the function will begin to calculate the average frequency
of the input signal during the number of periods indicated in the Periods_I parameter. This value
must be between 1 and 10.

Ingeteam Proprietary All Rights Reserved Pag. 223


Once the calculation has been completed, the function will return the value in the Out_R signal. If
there has been an error during the calculation, or it has not yet ended, this will be indicated by
the Valid_BL output variable.

1.7.1.8.6 Example

PROGRAM Example

VAR

nTest:INT;

(*FREQUENCY_MEASURE*)

MeasureFreq:FREQUENCY_MEASURE:=(Periods_I :=8 );

Signal:BLINK_SIGNAL:= (Enable_BL :=TRUE);

ErrorOnMeasure:INT;

Tau:TIME :T#30ms;

END_VAR

CASE nTest OF

1:(* MeasureFreq : FREQUENCY_MEASURE *)(*Prepare Measurement*)

MeasureFreq(Reset_BL:=TRUE);

2:(* Generate a blink signal and start*)

Signal( TimeLow_T := Tau,

TimeHigh_T := Tau );

(*Measure Signal Frequency*)

MeasureFreq( In_BL:=Signal.Out_BL,

Reset_BL:=FALSE);

(*MeasureFreq.Out_R = 1/60 HZ *)

IF( FALSE = MeasureFreq.Valid_BL)

THEN ErrorOnMeasure :=ErrorOnMeasure +1;

END_IF

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 224


1.7.1.9 GENERATION

1.7.1.9.1 Description

Function block for generating some periodic functions.

The GENERATION function generates several typical waveforms with the parameters chosen by
the user. Among the waveforms that can be generated are the triangle, positive triangle,
sawtooth (rising and falling), rectangle, sinusoidal (sine or cosine).

1.7.1.9.2 Syntax

FUNCTION_BLOCK GENERATION

VAR_INPUT

enMode:GEN_MODE;

Base_BL:BOOL;

Period_T:TIME;

Cycles_I:INT;

Amplitude_I:INT;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_I:INT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 225


1.7.1.9.3 Input parameters

Input Parameter Name Type Description


TRIANGLE(0) The form of the generated wave will be triangular between -
Amplitude_I and + Amplitude_I.
TRIANGLE_POS(1) The form of the generated wave will be triangular between 0 and
+Amplitude_I.
SAWTOOTH_RISE(2) The form of the wave will be sawtooth with a rising slope
between -Amplitude_I and +Amplitude_I.
SAWTOOTH_FALL(3) The form of the wave will be sawtooth with a falling slope
enMode GEN_MODE
between -Amplitude_I and +Amplitude_I.
RECTANGLE(4) The form of the wave will be rectangular between -Amplitude_I and
+Amplitude_I.
SINUS(5) The form of the wave will be sinusoidal between -Amplitude_I and
+Amplitude_I.
COSINUS(6) The form of the wave will be cosinusoidal between -Amplitude_I and
+Amplitude_I. . .
FALSE The cycle time refers to a particular number of cycles associated with the
calls to the function block. This choice is associated with the value of the Cycles_I
Base_BL BOOL parameter.
TRUE The cycle time refers to a specific times base. This choice is associated with
the value of the Period_T parameter.
This defines the time period of the signal to generate.
Period_T TIME
This is only applicable if the selection is Base_BL:=TRUE.
This defines the cycle period of the signal to generate.
Cycles_I INT
This is only applicable if the selection is Base_BL:=FALSE.
Amplitude_I INT This defines the amplitude of the signal to generate.
Reset_BL BOOL This sets the generated signal to 0.
Tbl. 1.175 Input parameters of function GENERATION.

1.7.1.9.4 Output parameters

Output Parameter Name Type Description


Variable with the values of the waveforms to generate according to the parameters
Out_I INT
established.
Tbl. 1.176 Output parameters of function GENERATION.

1.7.1.9.5 Remarks

The GENERATION function makes it possible to establish parameters for a waveform and
automatically obtain the values of the subsequent points of that signal.

To do this, an available waveform must be entered (TRIANGLE:=0, TRIANGLE_POS:=1,


SAWTOOTH_RISE:=2, SAWTOOTH_FALL:=3, RECTANGLE:=4, SINUS:=5, COSINUS:=6) in
the enMode variable. This waveform can be entered either by using its name from the list or by
using the corresponding number.

The next step is to define how the function is going to interpret the times base for the wave
generation process. This is done with the Base_BL parameter. If FALSE is selected, the function
will perform the calculations based on the call to function cycles. If, on the contrary, TRUE is
selected, the function will perform the calculations based on the time elapsed.

The Period_T and Cycles_I parameters are associated with this Base_BL parameter. Both refer
to the signal period. However, the function will use the time value entered in Period_T if

Ingeteam Proprietary All Rights Reserved Pag. 226


Base_BL:=TRUE has been selected. Alternatively, the function will use the cycle value entered
in Cycles_I if Base_BL:=FALSE has been selected.

Finally we must define the amplitude of the signal to be generated. This is done using the
Amplitude_I parameter.

If the waveform requires resetting at any time, the value of Reset_BL can be activated and the
function will return 0 at its output.

1.7.1.9.6 Example

PROGRAM Example

VAR

(*GEN_MODE*)

SignalMode: GEN_MODE;

SignalPeriod: TIME;

SignalAmplitude: INT;

SignalReset: BOOL;

(*function declaration*)

SignalGenerator: GENERATION:=(Base_BL:=TRUE,Period_T:=t#10s,Amplitude_I:=100);

(*Output Parameters*)

GeneratedSignal: INT;

END_VAR

(* SignalMode: GEN_MODE *)

(*calling of the function*)

SignalGenerator( enMode:=SignalMode, Reset_BL:=SignalReset );

(*output signal*)

GeneratedSignal:=SignalGenerator.Out_I;;

Ingeteam Proprietary All Rights Reserved Pag. 227


1.7.1.10 HYSTERESIS_REG

1.7.1.10.1 Description

Hysteresis function block.

The HYSTERESIS_REG function controls whether the value of the input variable falls below an
established limit. If the signal falls below this limit, the function will activate a flag.

It also has a hysteresis band to reset the signal flag. Therefore, the flag will not return to 0 until
the signal exceeds an upper limit.

1.7.1.10.2 Syntax

FUNCTION_BLOCK HYSTERESIS_REG

VAR_INPUT

In_I:INT;

High_I:INT;

Low_I:INT;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.7.1.10.3 Input parameters

Input Parameter Name Type Description


In_I INT Input variable of which value is to be supervised.
High_I INT Threshold to be exceeded by the variable in order to set the output flag to FALSE.
Low_I INT Lower threshold below which the variable causes the output flag to be set to TRUE.
Tbl. 1.177 Input parameters of function HYSTERESIS_REG.

1.7.1.10.4 Output parameters

Output Parameter Name Type Description


FALSE: The input variable has not fallen below the lower limit or has exceeded the
upper reset limit.
Out_BL BOOL
TRUE The input variable has fallen below the lower limit and has not yet exceeded
the upper reset limit.
Tbl. 1.178 Output parameters of function HYSTERESIS_REG.

Ingeteam Proprietary All Rights Reserved Pag. 228


1.7.1.10.5 Remarks

Use of the HYSTERESIS_REG is very simple for users. The user simply needs to establish the
values for the upper and lower limits that will determine the hysteresis range. Once these limits
are set, the function will supervise the variable included in the In_I parameter and establish the
correct statuses for the output flag via the Out_BL variable.

Function logic is based on monitoring the value of the input value compared to the lower limit. If
the value falls under this limit, the function returns the output flag as TRUE. The TRUE status will
not change until the input variable reaches the upper limit value. The output flag will then return
to FALSE.

Fig. 1.7 .

1.7.1.10.6 Example

PROGRAM Example

VAR

(*HYSTERESIS_REG*)

(*function declaration*)

Thermostat: HYSTERESIS_REG;

(*input parameters*)

UpperLimit: INT;

LowerLimit: INT;

InputVariable: INT;

Ingeteam Proprietary All Rights Reserved Pag. 229


(*output variable*)

HeaterOn: BOOL;

END_VAR

(* Contol heater thermostat to turn the heater on when the temperature drops below LowerLimit
degrees, but not turn it off until the temperature rises above UpperLimit degrees*)

Thermostat( (*input assignment*)

High_I:=UpperLimit,

Low_I:=LowerLimit,

In_I:=InputVariable,

(*Output*)

Out_BL => HeaterOn);

1.7.1.11 INTEGRAL_R

1.7.1.11.1 Description

Function block to approximate the integral of In_R over the time.

The INTEGRAL_R function approximately determines the integration operation of an input


variable.

1.7.1.11.2 Syntax

FUNCTION_BLOCK INTEGRAL_R

VAR_INPUT

In_R:REAL;

TimeMsec_DW:DWORD;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

Overflow_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 230


1.7.1.11.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input variable to operate on.
TimeMsec_DW DWORD Time between calls to function in milliseconds.
Reset_BL BOOL If TRUE resets the INTEGRAL_R function.
Tbl. 1.179 Input parameters of function INTEGRAL_R.

1.7.1.11.4 Output parameters

Output Parameter Name Type Description


Function output variable.
Out_R REAL
This will correspond to the input variable integral.
Overflow_BL BOOL Indicates if an overflow has occurred in the integral calculation.
Tbl. 1.180 Output parameters of function INTEGRAL_R.

1.7.1.11.5 Remarks

To use the INTEGRAL_R function all that is required is the entry of a signal to integrate (In_R)
and the time between calls to function (TimeMsec_DW) in milliseconds.

Fig. 1.8 .

1.7.1.11.6 Example

PROGRAM Example

VAR

(*INTEGRAL_R*)

(*Inputs*)

(*SamplesCounter:INT:=0;*)

InputSquare:ARRAY [1..100] OF REAL := 1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

Ingeteam Proprietary All Rights Reserved Pag. 231


-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,

1,1,1,1,1, 1,1,1,1,1,

-1,-1,-1,-1,-1, -1,-1,-1,-1,-1;

(*output variables*)

OutputIntegral : ARRAY [1..100] OF REAL;

(*function*)

IntegralWave : INTEGRAL_R := (TimeMsec_DW :=10);

END_VAR

(*Samples Counter*)

IF(SamplesCounter>0 AND SamplesCounter<100 )

THEN SamplesCounter := SamplesCounter+1;

ELSE SamplesCounter:=1;

END_IF

(*Get Input Derivate*)

IntegralWave( In_R:=InputSquare[ SamplesCounter ],

Out_R => OutputIntegral[ SamplesCounter ]);

1.7.1.12 LIMIT_ALARM_REG

1.7.1.12.1 Description

Function for variable limit surveillance.

The LIMIT_ALARM_REG function compares the value of an input variable in relation to a range
of values set with an upper and lower limit.

The function will return different indications depending on whether the value is within, above or
below the range.

Ingeteam Proprietary All Rights Reserved Pag. 232


1.7.1.12.2 Syntax

FUNCTION_BLOCK LIMIT_ALARM_REG

VAR_INPUT

In_I:INT;

High_I:INT;

Low_I:INT;

END_VAR

VAR_OUTPUT

O_BL:BOOL;

U_BL:BOOL;

IL_BL:BOOL;

END_VAR

1.7.1.12.3 Input parameters

Input Parameter Name Type Description


In_I INT Input variable of which the value is to be supervised.
High_I INT Upper limit of the supervision range.
Low_I INT Lower limit of the supervision range.
Tbl. 1.181 Input parameters of function LIMIT_ALARM_REG.

1.7.1.12.4 Output parameters

Output Parameter Name Type Description


FALSE The input variable is not above the specified upper value.
O_BL BOOL
TRUE The input variable is above the specified upper value.
FALSE The input variable is not below the specified lower value.
U_BL BOOL
TRUE The input variable is below the specified lower value.
FALSE The input variable is not within the specified upper and lower limit range.
IL_BL BOOL
TRUE The input variable is within the specified upper and lower limit range.
Tbl. 1.182 Output parameters of function LIMIT_ALARM_REG.

Ingeteam Proprietary All Rights Reserved Pag. 233


1.7.1.12.5 Remarks

To use the LIMIT_ALARM_REG function, you simply need to set upper and lower limits for the
operating range (High_I and Low_I), and assign the variable to be supervised to the input
variable (In_I) of the function.

Fig. 1.9 .

1.7.1.12.6 Example

PROGRAM Example

VAR

(*LIMIT_ALARM_REG*)

InputVariable: INT;

(*Output Parameters*)

VarOverflow: BOOL;

VarUnderflow: BOOL;

VarInLimit: BOOL;

(* function declaration and supervision range *)

LimitSupervision: LIMIT_ALARM_REG:=( High_I:=+10, Low_I:=-5 );

Ingeteam Proprietary All Rights Reserved Pag. 234


END_VAR

LimitSupervision( In_I:=InputVariable,

(*output assignment*)

O_BL=>VarOverflow,

U_BL=>VarUnderflow,

IL_BL=>VarInLimit);

1.7.1.13 LINEAR_TRAFO_R

1.7.1.13.1 Description

Linear transformation.

The LINEAR_TRAFO_R function transforms a value in a range defined by a minimum and a


maximum value into another range with another minimum and maximum value.

1.7.1.13.2 Syntax

FUNCTION_BLOCK LINEAR_TRAFO_R

VAR_INPUT

In_R:REAL;

InMin_R:REAL;

InMax_R:REAL;

OutMin_R:REAL;

OutMax_R:REAL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

Error_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 235


1.7.1.13.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input variable to transform from one range into another.
InMin_R REAL Minimum value of the original range.
InMax_R REAL Maximum value of the original range.
OutMin_R REAL Minimum value of the destination range.
OutMax_R REAL Maximum value of the destination range.
Tbl. 1.183 Input parameters of function LINEAR_TRAFO_R.

1.7.1.13.4 Output parameters

Output Parameter Name Type Description


Out_R REAL Value of the input variable referenced to the new range.
FALSE: The function shows no errors.
Error_BL BOOL TRUE: The values of InMin_R=InMax_R or the value of In_R is outside the range
between InMin_R and InMax_R.
Tbl. 1.184 Output parameters of function LINEAR_TRAFO_R.

1.7.1.13.5 Remarks

To use the LINEAR_TRAFO_R function you simply need to consider the correct set up of the
minimum and maximum values of the source and destination ranges. The value of the In_R
variable that is to be transformed must also be within the limits of the destination range.

The function performs the conversion using the following equation:

(IN-IN_MIN)/(IN-MAX_IN)=(OUT-OUT_MIN)/(OUT-MAX_OUT)

For example, we have a temperature sensor that delivers its measurements in voltages and we
want these readings converted into C. The range of voltage readings is between 0V and 10V
and the temperature range is between -20C and 40C.

Therefore, we have:

If the sensor is delivering a reading of 5V, the value after transformation will be 10C.

1.7.1.13.6 Example

PROGRAM Example

VAR

(*LINEAR_TRAFO_R*)

Voltage2Degrees :LINEAR_TRAFO_R := (InMin_R := 0, InMax_R := 10, OutMin_R :=-20,


OutMax_R := 40);

Volts:REAL;

Ingeteam Proprietary All Rights Reserved Pag. 236


Temperature: REAL;

END_VAR

Voltage2Degrees(In_R:= Volts,

(*output assignments*)

Out_R=>Temperature );

IF( TRUE = Voltage2Degrees.Error_BL )

THEN

Temperature := -273; (* 0 K*)

END_IF

1.7.1.14 PD_REG

1.7.1.14.1 Description

PD controller.

The PD_REG function performs Proportional-Derivative control of a controlled variable to obtain


a given setpoint.

1.7.1.14.2 Syntax

FUNCTION_BLOCK PD_REG

VAR_INPUT

Actual_R:REAL;

SetPoint_R:REAL;

KP_R:REAL;

TV_R:REAL;

YManual_R:REAL;

YOffset_R:REAL;

YMin_R:REAL;

YMax_R:REAL;

Manual_BL:BOOL;

Reset_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 237


VAR_OUTPUT

Y_R:REAL;

LimitsActive_BL:BOOL;

END_VAR

1.7.1.14.3 Input parameters

Input Parameter Name Type Description


Actual_R REAL Actual value, process variable.
SetPoint_R REAL Desired value, set point.
KP_R REAL Proportionality const. (P).
TV_R REAL Rate time, derivative time (D) in seconds.
YManual_R REAL Y is set to this value as long as Manual_BL=TRUE.
YOffset_R REAL Offset for manipulated variable.
Lowest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is lower than this limit, it will be restricted by YMin_R
YMin_R REAL
and the LimitsActive_BL output flag will be activated.
This control will work only if YMin_R.
Highest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is higher than this limit, it will be restricted by YMax_R
YMax_R REAL
and the LimitsActive_BL output flag will be activated.
This control will work only if YMin_R&lt;YMAX_R.
FALSE: The manual function is deactivated.
The Y_R output will take on the value calculated in the function.
Manual_BL BOOL
TRUE: The manual function is activated.
The Y_R output will take on the value of the YManual_R variable.
Reset_BL BOOL If TRUE, sets Y output to YOffset_R.
Tbl. 1.185 Input parameters of function PD_REG.

1.7.1.14.4 Output parameters

Output Parameter Name Type Description


Y_R REAL Manipulated variable, set value.
FALSE: This indicates that the calculation of the Y output valuable has not exceeded
the limits established in YMin_R and YMax_R.
LimitsActive_BL BOOL
TRUE: This indicates that the calculation of the Y output valuable has exceeded one
of the limits established in YMin_R or YMax_R.
Tbl. 1.186 Output parameters of function PD_REG.

1.7.1.14.5 Remarks

The PD_REG function provides Proportional-Derivative control of a controlled variable


(ACTUAL_R). The function can be completely parameterized to set the values of the proportional
constant (KP_R) and of the derivative time value value (TV_R).

The FUNCTION will calculate the manipulated variable (Y_R) according TO the following
equation:

Y=KP(e +TVde / dt)+Y_OFFSET

Ingeteam Proprietary All Rights Reserved Pag. 238


Where:

e=SET_POINT-ACTUAL

The derivative part of the function can be easily avoided by assigning the value of TV_R=0.

The Manual_R can be used to force the value of Y_R output with the value assigned to
YManual_R.

The YMin_R and YMax_R parameters can be used to set a range of minimum and maximum
values for the Y_R manipulated variable. To disable this restriction, a value of 0 must be
assigned to YMin_R and YMax_R.

1.7.1.14.6 Example

PROGRAM PD_REG_Example

VAR

rOutput:REAL:=0 ;

Kp:REAL:=0.2;

Ki:REAL:=0.05;

Kd:REAL:=1.0;

Td:REAL:=0.1;

Tn:REAL:=2;

(* PD controller *)

RegPD:PD_REG;

(*BLINK*)

GetInputBlinkValue:BLINK_SIGNAL:=(Enable_BL :=TRUE,

TimeLow_T := T#10000ms,

TimeHigh_T := T#10000ms ) ;

bBlinkSignal :BOOL;

rInputBlinkSignal :REAL;

END_VAR

(*Generate a REAL blink signal*)

GetInputBlinkValue( Out_BL => bBlinkSignal );

rInputBlinkSignal := 1.0 * BOOL_TO_REAL(bBlinkSignal);

(*PD_REG*)(* PD controller *)

Ingeteam Proprietary All Rights Reserved Pag. 239


RegPD(Actual_R:=rOutput,(* actual value, process variable *)

SetPoint_R:=rInputBlinkSignal,(* desired value, set point *)

KP_R:= Kp,(* proportionality const. (P)*) (* 20 0.5 100 *)

TV_R:= Td,(* rate time, derivative time (D) in sec *)

YManual_R:=0,(* Y is set to this value as long as Manual_BL=TRUE *)

YOffset_R:=0.1234,(* offset for manipulated variable *)

YMin_R:=-100.0,(* minimum value for manipulated variable *)

YMax_R:=+100.0,(* maximum value for manipulated variable *)

Manual_BL:=FALSE,(* TRUE: manual: Y is not influenced by controller,


FALSE: controller determines Y *)

Reset_BL:=FALSE,(* Reset: set Y output to YOffset_R *)

Y_R=> rOutput);(* Manipulated variable, set value*)

1.7.1.15 PERIOD_COUNTER

1.7.1.15.1 Description

Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring the
period of the signal connected to a GATE

1.7.1.15.2 Syntax

FUNCTION_BLOCK PERIOD_COUNTER

VAR_INPUT

Enable_BL:BOOL;

CounterType_enCounterType:enCounterType;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterConfigure_ADR:DWORD;

CounterConfigureSizeBy_DI:DINT;

CounterOverflowUs_R:REAL:=30000000;

END_VAR

VAR_OUTPUT

Ingeteam Proprietary All Rights Reserved Pag. 240


Done_BL:BOOL;

PeriodUs_R:REAL;

Status_enCounterRet:enCounterRet;

END_VAR

1.7.1.15.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Flag to Enable the function.
CounterType_enCounterType enCounterType Counter Type.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
Pointer to the memory buffer where configuration structure is stored.
CounterConfigure_ADR DWORD For the IC3325 module use stIC3325Period.
For the IC3391 module use stIC3391Period.
CounterConfigureSizeBy_DI DINT Size of the configuration structure in bytes.
Maximum period time that can be measured in microseconds.
CounterOverflowUs_R REAL If the period time measured is bigger, the function will return the status
Counter Overflow.
Tbl. 1.187 Input parameters of function PERIOD_COUNTER.

1.7.1.15.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Execution of the FB has finished
PeriodUs_R REAL Measured period in microseconds
Result of the FB execution.
Status_enCounterRet enCounterRet
The data structure is in the Regulation02.lib library
Tbl. 1.188 Output parameters of function PERIOD_COUNTER.

1.7.1.15.5 Data Types

1.7.1.15.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.189 Enumerator enCounterType.

Ingeteam Proprietary All Rights Reserved Pag. 241


1.7.1.15.5.2 enIC3391InputSignal

Value Description
IN0 (0) Input 0
IN1 (1) Input 1
IN2 (2) Input 2
IN3 (3) Input 3
IN4 (4) Input 4
IN5 (5) Input 5
Tbl. 1.190 Enumerator enIC3391InputSignal.

1.7.1.15.5.3 stIC3325Period

Field Name Type Description


CounterNum_DI DINT Counter number to use for the period measuring.
InputSignal1_enIC3325InputSignal enIC3325InputSignal Input Signal 1 (Conected to one of the Gates (G0G7)).
Logic of the Input Signal 1 (TRUE--> Inverted Logic,
Signal1Inverted_BL BOOL
FALSE-->Direct Logic).
Tbl. 1.191 Fields of the stIC3325Period structure.

1.7.1.15.5.4 stIC3391Period

Field Name Type Description


CounterNum_DI DINT Counter number to use for the period measuring.
InputSignal1_enIC3391InputSignal enIC3391InputSignal Input Signal 1 (IN0IN5).
Logic of the Input Signal 1 (TRUE--> Inverted Logic,
Signal1Inverted_BL BOOL
FALSE--> Direct Logic).
Tbl. 1.192 Fields of the stIC3391Period structure.

Ingeteam Proprietary All Rights Reserved Pag. 242


1.7.1.15.5.5 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.193 Enumerator enCounterRet.

1.7.1.15.6 Example

PROGRAM Example_PERIOD_COUNTER

(*This example measures the period of signal connected to the IN0 input of a IC3391 module.*)

VAR

PeriodCounter: PERIOD_COUNTER;(*Function to measure the period*)

EnPeriodCounter: BOOL;(*Enable to measure the period*)

(*Configuration to define the counter and inputs to use to measure the period*)

PeriodCounterConf: stIC3391Period:=(CounterNum_DI:=0,(*Counter number 0*)

InputSignal1_enIC3391InputSignal:=IN0,(*Signal connected to input 0 of the module*)

Signal1Inverted_BL:=FALSE);(*Not inverted*)

END_VAR

(*Call to the Period_COUNTER function*)

Ingeteam Proprietary All Rights Reserved Pag. 243


PeriodCounter(

Enable_BL:=EnPeriodCounter ,(*Enable to measure the period*)

CounterType_enCounterType:=IC3391,(*Module type*)

ChassisNum_DI:=0,(*Chasis number*)

SlotNum_DI:=7,(*Slot number*)

CounterConfigure_ADR:=ADR(PeriodCounterConf),(*Address to configuration structure*)

CounterConfigureSizeBy_DI:=SIZEOF(PeriodCounterConf),(*Size of configuration
structure*)

CounterOverflowUs_R:=1000000 ,(*Maximum period for returning overflow in the measure


(1 Sec)*)

Done_BL=> ,(*The FB has finished*)

PeriodUs_R=> ,(*Measured period*)

Status_enCounterRet=> );(*Finished status of FB*)

1.7.1.16 PID_FIXCYCLE_REG

1.7.1.16.1 Description

PID controller.

The PID_FIXCYCLE_REG function corresponds to the PID_REG function, although with this
function the cycle time is not measured internally but is entered into the function as another input
parameter.

The function performs Proportional-Integral-Derivative control of a controlled variable to obtain a


given setpoint.

1.7.1.16.2 Syntax

FUNCTION_BLOCK PID_FIXCYCLE_REG

VAR_INPUT

Actual_R:REAL;

SetPoint_R:REAL;

KP_R:REAL;

TN_R:REAL;

TV_R:REAL;

Ingeteam Proprietary All Rights Reserved Pag. 244


YManual_R:REAL;

YOffset_R:REAL;

YMin_R:REAL;

YMax_R:REAL;

Manual_BL:BOOL;

Reset_BL:BOOL;

Cycle_R:REAL;

END_VAR

VAR_OUTPUT

Y_R:REAL;

LimitsActive_BL:BOOL;

Overflow_BL:BOOL;

END_VAR

1.7.1.16.3 Input parameters

Input Parameter Name Type Description


Actual_R REAL Actual value, process variable.
SetPoint_R REAL Desired value, set point.
KP_R REAL Proportionality const. (P).
TN_R REAL Integral time of action in seconds.
TV_R REAL Derivative time in seconds.
YManual_R REAL Y is set to this value as long as Manual_BL=TRUE.
YOffset_R REAL Offset for manipulated variable.
Lowest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is lower than this limit, it will be restricted by YMin_R
YMin_R REAL
and the LimitsActive_BL output flag will be activated.
This control will work only if YMin_R.
Highest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is higher than this limit, it will be restricted by
YMax_R REAL
YMax_R and the ?LimitsActive_BL output flag will be activated.
This control will work only if YMin_R.
FALSE: The manual function is deactivated.
The Y_R output will take on the value calculated in the function.
Manual_BL BOOL
TRUE: The manual function is activated.
The Y_R output will take on the value of the YManual_R variable.
Reset_BL BOOL If TRUE, set Y output to YOffset_R and reset integral part.
Cycle_R REAL Value of the cycle time for the PID controller in seconds.
Tbl. 1.194 Input parameters of function PID_FIXCYCLE_REG.

Ingeteam Proprietary All Rights Reserved Pag. 245


1.7.1.16.4 Output parameters

Output Parameter Name Type Description


Y_R REAL Manipulated variable, set value.
FALSE: This indicates that the calculation of the Y_R output valuable has not
exceeded the limits established in YMin_R and YMax_R.
LimitsActive_BL BOOL
TRUE: This indicates that the calculation of the Y_R output valuable has exceeded
one of the limits established in YMin_R or YMax_R.
FALSE: The function does not show an overflow in its integral part.
TRUE: The function has detected an overflow in the integral part.
Overflow_BL BOOL
The controller will be interrupted and will only run again after it is reset by the
Reset_BL input.
Tbl. 1.195 Output parameters of function PID_FIXCYCLE_REG.

1.7.1.16.5 Remarks

Use of the PID_FIXCYCLE_REG function is very similar to that of the PID_REG function. The
difference is that the input parameter of the PID_FIXCYCLE_REG function is the cycle time in
the controller call expressed in seconds (Cycle_R).

The function provides Proportional-Integral-Derivative control of a controlled variable (Actual_R).


The function can be completely parameterized to set the values of the proportional constant
(KP_R) of the derivative time value (TV_R) and the integration time value (TN_R).

The function will calculate the manipulated variable (Y_R) according to the following equation:

Y = KP (e + 1/TN integral( edt ) + TVde / dt) + Y_OFFSET

Where:

e = SET_POINT - ACTUAL

The derivative part of the function can be easily avoided by assigning the value of TV_R=0.

The Manual_BL parameter can be used TO force the value OF Y_R output with the value
assigned TO YManual_R.

The YMin_R and YMax_R parameters can be used to set a range of minimum and maximum
values for the Y_R manipulated variable. To disable this restriction, a value of 0 must be
assigned to YMin_R and YMax_R.

Given the integral part of the function, poor parameterisation of the controller may result in an
overflow if the error integral becomes very large. To avoid this, there is an output flag
(Overflow_R) that is activated if this value is too high. When this occurs, the controller is disabled
until it is reset (Reset_BL).

Ingeteam Proprietary All Rights Reserved Pag. 246


1.7.1.16.6 Example

PROGRAM PID_FIXCYCLE_REG_Example

VAR

rOutput : REAL:=0;

Kp: REAL:=0.2;

Ki: REAL:=0.05;

Kd: REAL:=1.0;

Td: REAL:=0.1;

Tn: REAL:=2;

(* PID_FIXCYCLE controller *)

RegPIDFIXCYCLE:PID_FIXCYCLE_REG;

(*BLINK*)

GetInputBlinkValue:BLINK_SIGNAL := (Enable_BL:=TRUE,

TimeLow_T:=T#10000ms,

TimeHigh_T:=T#10000ms ) ;

bBlinkSignal:BOOL;

rInputBlinkSignal :REAL;

END_VAR

(*Generate a REAL blink signal*)

GetInputBlinkValue( Out_BL => bBlinkSignal );

rInputBlinkSignal := 1.0 * BOOL_TO_REAL(bBlinkSignal);

(*PID_REG*)(* PID_REG controller *)

RegPID(Actual_R:=rOutput,(* actual value, process variable *)

SetPoint_R:=rInputBlinkSignal,(* desired value, set point *)

KP_R:= Kp,(* proportionality const. (P)*) (* 20 0.5 100 *)

TN_R:= Tn,(* reset time (I) in sec *)

TV_R:= Td,(* rate time, derivative time (D) in sec *)

YManual_R:=0,(* Y is set to this value as long as Manual_BL=TRUE *)

YOffset_R:=0.1234,(* offset for manipulated variable *)

YMin_R:=-25.0, (* minimum value for manipulated variable *)

Ingeteam Proprietary All Rights Reserved Pag. 247


YMax_R:=+25.0,(* maximum value for manipulated variable *)

Manual_BL:=FALSE,(* TRUE: manual: Y is not influenced by controller,


FALSE: controller determines Y *)

Reset_BL:=FALSE,(* Reset: set Y output to YOffset_R *)

Y_R=> rOutput );(* Manipulated variable, set value*)

1.7.1.17 PID_REG

1.7.1.17.1 Description

PID controller.

The PID_REG function performs Proportional-Integral-Derivative control of a controlled variable


to obtain a given setpoint.

1.7.1.17.2 Syntax

FUNCTION_BLOCK PID_REG

VAR_INPUT

Actual_R:REAL;

SetPoint_R:REAL;

KP_R:REAL;

TN_R:REAL;

TV_R:REAL;

YManual_R:REAL;

YOffset_R:REAL;

YMin_R:REAL;

YMax_R:REAL;

Manual_BL:BOOL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Y_R:REAL;

LimitsActive_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 248


Overflow_BL:BOOL;

END_VAR

1.7.1.17.3 Input parameters

Input Parameter Name Type Description


Actual_R REAL Actual value, process variable.
SetPoint_R REAL Desired value, set point.
KP_R REAL Proportionality const. (P).
TN_R REAL Integral time of action in seconds.
TV_R REAL Derivative time in seconds.
YManual_R REAL Y is set to this value as long as Manual_BL=TRUE.
YOffset_R REAL Offset for manipulated variable.
Lowest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is lower than this limit, it will be restricted by YMin_R
YMin_R REAL
and the LimitsActive_BL output flag will be activated.
This control will work only if YMin_R.
Highest value that can be accepted by the manipulated variable Y_R.
If the value calculated for Y_R is higher than this limit, it will be restricted by YMax_R
YMax_R REAL
and the LimitsActive_BL output flag will be activated.
This control will work only if YMin_R.
FALSE: The manual function is deactivated.
The Y_R output will take on the value calculated in the function.
Manual_BL BOOL
TRUE: The manual function is activated.
The Y_R output will take on the value of the YManual_R variable.
Reset_BL BOOL If TRUE, set Y output to YOffset_R and reset integral part.
Tbl. 1.196 Input parameters of function PID_REG.

1.7.1.17.4 Output parameters

Output Parameter Name Type Description


Y_R REAL Manipulated variable, set value.
FALSE: This indicates that the calculation of the Y_R output valuable has not
exceeded the limits established in YMin_R and YMax_R.
LimitsActive_BL BOOL
TRUE: This indicates that the calculation of the Y_R output valuable has exceeded
one of the limits established in YMin_R or YMax_R.
FALSE: The function does not show an overflow in its integral part.
TRUE: The function has detected an overflow in the integral part.
Overflow_BL BOOL
The controller will be interrupted and will only run again after it is reset by the
Reset_BL input.
Tbl. 1.197 Output parameters of function PID_REG.

1.7.1.17.5 Remarks

The PID_REG function provides Proportional-Integral-Derivative control of a controlled variable


(Actual_R). The function can be completely parameterized to set the values of the proportional
constant (KP_R), the derivative time value (TV_R) and the integration time value (TN_R).

The function will calculate the manipulated variable (Y_R) according to the following equation:

Y =KP(e + 1/TN integral( edt ) + TVde / dt) + Y_OFFSET

Ingeteam Proprietary All Rights Reserved Pag. 249


Where:

e=SET_POINT- ACTUAL

The derivative part of the function can be easily avoided by assigning the value of TV_R=0.

The Manual_BL parameter can be used to force the value of the Y_R output with the value
assigned to YManual_R.

The YMin_R and YMax_R parameters can be used to set a range of minimum and maximum
values for the Y_R manipulated value. To disable this restriction, a value of 0 must be assigned
to YMin_R and YMax_R.

Given the integral part of the function, poor parameterisation of the controller may result in an
overflow if the error integral becomes very large. To avoid this, there is an output flag
(Overflow_R) that is activated if this value is too high. When this occurs, the controller is disabled
until it resets (Reset_BL).

1.7.1.17.6 Example

PROGRAM PID_REG_Example

VAR

rOutput:REAL:=0 ;

Kp:REAL:=0.2;

Ki:REAL:=0.05;

Kd:REAL:=1.0;

Td:REAL:=0.1;

Tn:REAL:=2;

(* PID controller *)

RegPID :PID_REG;

(*BLINK*)

GetInputBlinkValue:BLINK_SIGNAL := (Enable_BL :=TRUE,

TimeLow_T := T#10000ms,

TimeHigh_T := T#10000ms ) ;

bBlinkSignal:BOOL;

rInputBlinkSignal :REAL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 250


(*Generate a REAL blink signal*)

GetInputBlinkValue( Out_BL => bBlinkSignal );

rInputBlinkSignal := 1.0 * BOOL_TO_REAL(bBlinkSignal);

(*PID_REG*)(* PID_REG controller *)

RegPID(Actual_R:=rOutput,(* actual value, process variable *)

SetPoint_R:=rInputBlinkSignal,(* desired value, set point *)

KP_R:= Kp,(* proportionality const. (P)*) (* 20 0.5 100 *)

TN_R:= Tn,(* reset time (I) in sec *)

TV_R:= Td,(* rate time, derivative time (D) in sec *)

YManual_R:=0, (* Y is set to this value as long as Manual_BL=TRUE *)

YOffset_R:=0.1234,(* offset for manipulated variable *)

YMin_R:=-5.0, (* minimum value for manipulated variable *)

YMax_R:=+5.0, (* maximum value for manipulated variable *)

Manual_BL:=FALSE,(* TRUE: manual: Y is not influenced by controller,


FALSE: controller determines Y *)

Reset_BL:=FALSE,(* Reset: set Y output to YOffset_R *)

Y_R=> rOutput );(* Manipulated variable, set value*)

1.7.1.18 POSITION_COUNTER

1.7.1.18.1 Description

Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring a
position of a signal on input channel

1.7.1.18.2 Syntax

FUNCTION_BLOCK POSITION_COUNTER

VAR_INPUT

Enable_BL:BOOL;

CounterType_enCounterType:enCounterType;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

Ingeteam Proprietary All Rights Reserved Pag. 251


Read_BL:BOOL;

Write_BL:BOOL;

ValueToWrite_R:REAL;

CounterConfigure_ADR:DWORD;

CounterConfigureSizeBy_DI:DINT;

PulsesPerRotation_R:REAL;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

CurrentPositionRad_R:REAL;

HoldPositionRad_R:REAL;

Status_enCounterRet:enCounterRet;

Status_stCounterFlags:stCounterFlags;

END_VAR

1.7.1.18.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Flag to Enable the function.
CounterType_enCounterType enCounterType Counter Type.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
Read_BL BOOL Read mode.
Write_BL BOOL Write mode.
ValueToWrite_R REAL Write value in radianes.
Pointer to the memory buffer where configuration structure is stored.
CounterConfigure_ADR DWORD For the IC3325 module use stIC3325Position.
For the IC3391 module use stIC3391Position.
CounterConfigureSizeBy_DI DINT Size of the configuration structure in bytes.
PulsesPerRotation_R REAL Number of pulses per rotation.
Tbl. 1.198 Input parameters of function POSITION_COUNTER.

1.7.1.18.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Execution of the FB has finished
CurrentPositionRad_R REAL Actual Counter Value
HoldPositionRad_R REAL Hold value of the counter
Result of the FB execution.
Status_enCounterRet enCounterRet
The data structure is in the Regulation02.lib library

Ingeteam Proprietary All Rights Reserved Pag. 252


Output Parameter Name Type Description
Status_stCounterFlags stCounterFlags Counter Indication Flags
Tbl. 1.199 Output parameters of function POSITION_COUNTER.

1.7.1.18.5 Data Types

1.7.1.18.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.200 Enumerator enCounterType.

1.7.1.18.5.2 enIC3391InputSignal

Value Description
IN0 (0) Input 0
IN1 (1) Input 1
IN2 (2) Input 2
IN3 (3) Input 3
IN4 (4) Input 4
IN5 (5) Input 5
Tbl. 1.201 Enumerator enIC3391InputSignal.

1.7.1.18.5.3 enInputSignalCodification

Value Description
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time you get the whole
MODE1 (0) sequence CHA rises - CHB rises - CHA falls - CHB falls. The counter is decremented each time you
get the whole sequence CHB rises - CHA rises - CHB falls - CHA falls.
CHA is a pulse input and CHB indicates the direction of counting: Increase if CHB=1 and decrease if
MODE2 (1) CHB=0. The counter is incremented each time CHA rises being CHB=1. The counter is
decremented each time CHA rises being CHB=0
CHA is a decremental pulse input, and CHB is an incremental pulse input. The counter is
MODE3 (2)
incremented each time CHB rises. The counter is decremented each time CHA rises
MODE4 (3) Pulses (incremental always) are generated with an internal clock 10 Mhz frequency
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time CHA rises being
CHB=0, or CHB rises being CHA=1, or CHA falls being CHB=1, or CHB falls being CHA=0. The
MODE5 (4)
counter is decremented each time CHB rises being CHA=0,or CHA rises being CHB=1, or CHB
falls being CHA=1, or CHA falls being CHB=0
CHA is a pulse input and CHB indicates the direction of counting: Increases when CHB=1 and
MODE6 (5) decreases when CHB=0. The counter is incremented each time CHA rises or CHA falls being
CHB=1. The counter is decremented each time CHA rises or CHA falls being CHB=0
CHA is a decremental pulse input, and CHB is a incremental pulse input. The counter is incremented
MODE7 (6) each time CHB rises or CHB falls. The counter is decremented each time CHA rises or CHA
falls
Tbl. 1.202 Enumerator enInputSignalCodification.

Ingeteam Proprietary All Rights Reserved Pag. 253


1.7.1.18.5.4 stCounterFlags

Field Name Type Description


InputSignal1State_BL BOOL State of the physical sign associated to the first GATE.
InputSignal2State_BL BOOL State of the physical sign associated to the second GATE.
CounterOverflow_BL BOOL Variable that indicates overflow on the counter for reaching the setpoint set.
Tbl. 1.203 Fields of the stCounterFlags structure.

1.7.1.18.5.5 stIC3325Position

Field Name Type Description


Counter number to use for the position calculation.
CounterNum_DI DINT
Gate0 parameters.
Input Signal 1 (Conected to one of the Gates
InputSignal1_enIC3325InputSignal enIC3325InputSignal
(G0G7)).
Logic of the Input Signal to the first GATE (TRUE--
Signal1Inverted_BL BOOL
> Inverted Logic, FALSE--> Direct Logic).
Variable that allows me to capture the counter
CaptureCounterSignal1_BL BOOL value of the event in the signal 1. Gate1
parameters.
Input Signal 2 (Conected to one of the Gates
InputSignal2_enIC3325InputSignal enIC3325InputSignal
(G0G7)).
Logic of the Input Signal to the second GATE
Signal2Inverted_BL BOOL
(TRUE--> Inverted Logic, FALSE-->Direct logic).
Enables or disables the preset when there is a
Signal2Preset_BL BOOL
rising edge at the second GATE input.
Variable that allows me to capture the counter
CaptureCounterSignal2_BL BOOL value of the event in the signal 2. SetPoint
parameters.
SetPointValue_R REAL SetPoint value in radians.
Enables or disables the preset when you reach the
PresetSetPoint_BL BOOL
SetPoint. Preset parameters.
PresetValue_R REAL Preset value in radians. Counters parameters.
Type of coding of signals from chanels CHA and
InputSignalCod_enInputSignalCodification enInputSignalCodification
CHB.
Logic of the input signal conected to the CHANEL
CHAInverted_BL BOOL
A (TRUE--> Inverted Logic, FALSE-->Direct Logic).
Logic of the input signal conected to the CHANEL
CHBInverted_BL BOOL
B (TRUE--> Inverted Logic, FALSE-->Direct Logic).
Tbl. 1.204 Fields of the stIC3325Position structure.

Ingeteam Proprietary All Rights Reserved Pag. 254


1.7.1.18.5.6 stIC3391Position

Field Name Type Description


Counter number to use for the position
CounterNum_DI DINT
calculation. Gate0 parameters.
InputSignal1_enIC3391InputSignal enIC3391InputSignal Input Signal 1 (IN0IN5).
Logic of the Input Signal to the Signal 1
Signal1Inverted_BL BOOL (TRUE-->Inverted Logic, FALSE-->
Direct Logic).
Variable that allows to capture the
CaptureCounterSignal1_BL BOOL counter value of the event in the signal
1. Gate1 parameters.
InputSignal2_enIC3391InputSignal enIC3391InputSignal Input Signal 2 (IN0IN5).
Logic of the Input Signal to the Signal 2
Signal2Inverted_BL BOOL (TRUE--> Inverted Logic, FALSE-->
Direct Logic).
Enables or disables the preset when
Signal2Preset_BL BOOL
there is a rising edge at the Signal 2.
Variable that allows to capture the
CaptureCounterSignal2_BL BOOL counter value of the event in the signal
2. SetPoint parameters.
SetPointValue_R REAL SetPoint value in radians.
Enables or disables the preset when
PresetSetPoint_BL BOOL you reach the SetPoint. Preset
parameters.
Preset value in radians. Counters
PresetValue_R REAL
parameters.
Type of coding of signals from chanels
InputSignalCod_enInputSignalCodification enInputSignalCodification
CHA and CHB.
Physical input signal selected like
CHASignal_enIC3391InputSignal enIC3391InputSignal
channel A (IN0IN5)).
Logic of the input signal conected to
CHAInverted_BL BOOL the CHANEL A (TRUE--> Inverted
Logic, FALSE--> Direct Logic).
Physical input signal selected like
CHBSignal_enIC3391InputSignal enIC3391InputSignal
channel B (IN0IN5)).
Logic of the input signal conected to
CHBInverted_BL BOOL the CHANEL B (TRUE--> Inverted
Logic, FALSE--> Direct Logic).
Tbl. 1.205 Fields of the stIC3391Position structure.

Ingeteam Proprietary All Rights Reserved Pag. 255


1.7.1.18.5.7 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.206 Enumerator enCounterRet.

1.7.1.18.6 Example

PROGRAM Example_POSITION_COUNTER

(*This example calculates the azimuth position using a encoder with pulses shifted 90connected
to the IN3 and IN4 inputs of a IC3391 module.

The initial position is set using a inductive sensor connected to the IN5 input of the same
module.*)

VAR

PositionCounter: POSITION_COUNTER;(*Function to calculate the azimuth position*)

EnPositionCounter: BOOL;(*Enable to calculate the azimuth position*)

EnReadPosition: BOOL;(*Enable to read the calculated azimuth position*)

EnWritePosition: BOOL;(*Enable to write the position indicated in ValueToWrite_R*)

Ingeteam Proprietary All Rights Reserved Pag. 256


(*Configuration to define the counter, type of encoder and inputs used to calculate the
azimuth position*)

PositionCounterConf: stIC3391Position := (CounterNum_DI:=3, (*Counter number 3*)

InputSignal1_enIC3391InputSignal:=IN5,(*Signal to capture the azimuth position(Not


used)*)

Signal1Inverted_BL:=FALSE,(*Not inverted*)

CaptureCounterSignal1_BL:=FALSE,(*Activation to capture the azimuth position when


there is a rising edge at signal1(Not used)*)

InputSignal2_enIC3391InputSignal:=IN5,(*Signal of inductive sensor connected to input 5


of the module*)

Signal2Inverted_BL:=FALSE,(*Not inverted*)

Signal2Preset_BL:=TRUE,(*Activation of preset when there is a rising edge at signal2*)

CaptureCounterSignal2_BL:=FALSE,(*Activation to capture the azimuth position when


there is a rising edge at signal2(Not used)*)

SetPointValue_R:=0,(*SetPoint value(Not used)*)

PresetSetPoint_BL:=FALSE,(*Activation of Setpoint(Not used)*)

PresetValue_R:=0,(*Preset value to write at the counter when is a rising edge at signal2*)

InputSignalCod_enInputSignalCodification:=MODE1,(*Type of encoder. MODE1=encoder


with pulses shifted 90*)

CHASignal_enIC3391InputSignal:=IN3, (*Signal of encoder connected to input 3 of the


module*)

CHAInverted_BL:=FALSE,(*Not inverted*)

CHBSignal_enIC3391InputSignal:=IN4, (*Signal of encoder connected to input 4 of the

module*)

CHBInverted_BL:=FALSE );(*Not inverted*)

END_VAR

(*Call to the SPEED_COUNTER function*)

PositionCounter(

Enable_BL:=EnPositionCounter,(*Enable to calculate the azimuth position*)

CounterType_enCounterType:=IC3391,(*Module type*)

ChassisNum_DI:=0,(*Chasis number*)

SlotNum_DI:=7,(*Slot number*)

Ingeteam Proprietary All Rights Reserved Pag. 257


Read_BL:=EnReadPosition,(*Enable to read the calculated azimuth position*)

Write_BL:=EnWritePosition,(*Not used*)

ValueToWrite_R:=0,(*Not used*)

CounterConfigure_ADR:=ADR(PositionCounterConf),(*Address to configuration structure*)

CounterConfigureSizeBy_DI:=SIZEOF(PositionCounterConf),(*Size of configuration
structure*)

PulsesPerRotation_R:=1024,(*Number of pulses per rotation of the encoder*)

Done_BL=>,(*The FB has finished*)

CurrentPositionRad_R=>,(*Calculated azimuth position*)

HoldPositionRad_R=>,(*Not used*)

Status_enCounterRet=>,(*Finished status of FB*)

Status_stCounterFlags=> );(*Status flags of the counter*)

1.7.1.19 RAMP_I

1.7.1.19.1 Description

Function block to limit the slope of a value to a certain value.

The RAMP_I function limits the increment and decrement ratios of a variable to pre-established
maximum values. This restriction can be applied to a defined time interval or an execution cycle.

1.7.1.19.2 Syntax

FUNCTION_BLOCK RAMP_I

VAR_INPUT

In_I:INT;

Ascend_I:INT;

Descend_I:INT;

TimeBase_T:TIME;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_I:INT;

Ingeteam Proprietary All Rights Reserved Pag. 258


END_VAR

1.7.1.19.3 Input parameters

Input Parameter Name Type Description


In_I INT Input variable to be limited.
Ascend_I INT Maximum variable increase of the variable.
Descend_I INT Maximum variable decrease of the variable (this must be a positive value).
0 ms If the value is t#0ms, the limitations will be taken into consideration in each call.
TimeBase_T TIME 1ms..1193h2m47s295ms The time interval required to consider the maximum ascendant
and descendant values.
Reset_BL BOOL If TRUE resets the RAMP_I function.
Tbl. 1.207 Input parameters of function RAMP_I.

1.7.1.19.4 Output parameters

Output Parameter Name Type Description


Value of the output variable with the restrictions on the ascendant and descendant
Out_I INT
slopes.
Tbl. 1.208 Output parameters of function RAMP_I.

1.7.1.19.5 Remarks

When using the RAMP_I function, the following points should be remembered:

The maximum ascendant (Ascend_I) and descendant (Descend_I) values are associated with a
times base (TimeBase_T). To apply a restriction per cycle, assign the value t#0ms to the
TimeBase_T variable.

The value of the Descend_I parameter should be positive as it defines a maximum descendant
value.

Fig. 1.10 .

Ingeteam Proprietary All Rights Reserved Pag. 259


1.7.1.19.6 Example

PROGRAM Example

VAR

(*RAMP_I*)

InputSignal : ARRAY [1..100] OF INT := 0,0,0,0,0,1,2,3,4,5,

50,51,52,53,54,60,70,80,90,100,

99,98,97,96,95,90,90,90,90,90,

50,49,48,47,46,45,45,45,45,45,

9,8,7,6,5,4,3,2,1,0,

0,0,0,0,0,1,2,3,4,5,

50,51,52,53,54,60,70,80,90,100,

99,98,97,96,95,90,90,90,90,90,

50,49,48,47,46,45,45,45,45,45,

9,8,7,6,5,4,3,2,1,0;

OutputSignal : ARRAY [1..100] OF INT;

MaxAscend: INT := 2;

MaxDescend: INT:=3;

TimeBase: TIME;

Reset: BOOL;

Counter:INT;

RampInteger : RAMP_I := (Ascend_I := 2,

Descend_I := 3);

END_VAR

(* Generating output filtered signal*)

FOR Counter:=1 TO 100 BY 1 DO

RampInteger( In_I:=InputSignal[ Counter ],

Out_I =>OutputSignal[ Counter ]);

END_FOR;

Ingeteam Proprietary All Rights Reserved Pag. 260


1.7.1.20 RAMP_R

1.7.1.20.1 Description

Function block to limit the slope of a value to a certain value.

The RAMP_R function is used for the same purpose as the RAMP_I function, but with this
function the parameters and variables admit REAL type data.

The function limits the increment and decrement ratios of a variable to pre-established maximum
values. This restriction can be applied to a defined time interval or an execution cycle.

1.7.1.20.2 Syntax

FUNCTION_BLOCK RAMP_R

VAR_INPUT

In_R:REAL;

Ascend_R:REAL;

Descend_R:REAL;

TimeBase_T:TIME;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

END_VAR

1.7.1.20.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input variable to be limited.
Ascend_R REAL Maximum variable increase of the variable.
Descend_R REAL Maximum variable decrease of the variable (this must be a positive value).
0 ms If the value is t#0ms, the limitations will be taken into consideration in each call.
TimeBase_T TIME 1ms..1193h2m47s295ms The time interval required to consider the maximum ascendant
and descendant values.
Reset_BL BOOL If TRUE Resets the RAMP_R function.
Tbl. 1.209 Input parameters of function RAMP_R.

Ingeteam Proprietary All Rights Reserved Pag. 261


1.7.1.20.4 Output parameters

Output Parameter Name Type Description


Value of the output variable with the restrictions on the ascendant and descendant
Out_R REAL
slopes.
Tbl. 1.210 Output parameters of function RAMP_R.

1.7.1.20.5 Remarks

When using the RAMP_R function, the following points should be remembered:

The maximum ascendant (Ascend_R) AND descendant (Descend_R) values are associated with
a times base (TimeBase_T). TO apply a restriction per cycle, assign the value t#0ms TO the
TimeBase_T variable.

The value of the Descend_R parameter should be positive as it defines a maximum descendant
value.

Fig. 1.11 .

1.7.1.20.6 Example

PROGRAM Example

VAR

(*RAMP_R*)

InputSignalR : ARRAY [1..100] OF REAL := 0,0,0,0,0,1,2,3,4,5,

50,51,52,53,54,60,70,80,90,100,

99,98,97,96,95,90,90,90,90,90,

50,49,48,47,46,45,45,45,45,45,

9,8,7,6,5,4,3,2,1,0,

0,0,0,0,0,1,2,3,4,5,

50,51,52,53,54,60,70,80,90,100,

Ingeteam Proprietary All Rights Reserved Pag. 262


99,98,97,96,95,90,90,90,90,90,

50,49,48,47,46,45,45,45,45,45,

9,8,7,6,5,4,3,2,1,0;

OutputSignalR : ARRAY [1..100] OF REAL;

MaxAscendR: REAL := 2;

MaxDescendR: REAL:=3;

TimeBase: TIME;

Reset: BOOL;

Counter:INT;

RampReal : RAMP_R := ( Ascend_R := 2,

Descend_R := 3,

TimeBase_T := T#0ms);

END_VAR

(*Generating output filtered signal*)

FOR Counter:=1 TO 100 BY 1 DO

RampReal(In_R:=InputSignalR[ Counter ],

Out_R =>OutputSignalR[ Counter ]);

END_FOR;

1.7.1.21 READ_SSI_COUNTER

1.7.1.21.1 Description

Function to read an SSI_COUNTER

1.7.1.21.2 Syntax

FUNCTION_BLOCK READ_SSI_COUNTER

VAR_INPUT

Enable_BL:BOOL;

CounterType_enCounterType:enCounterType;

ChassisNum_DI:DINT;

Ingeteam Proprietary All Rights Reserved Pag. 263


SlotNum_DI:DINT;

CounterConfigure_ADR:DWORD;

CounterConfigureSizeBy_DI:DINT;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

SSI_Value_DI:DINT;

Status_enCounterRet:enCounterRet;

END_VAR

1.7.1.21.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Flag to Enable the function.
CounterType_enCounterType enCounterType Counter module type.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
CounterConfigure_ADR DWORD Address of the stSSICounterConf_ST structure.
CounterConfigureSizeBy_DI DINT Size of the stSSICounterConf_ST structure.
Tbl. 1.211 Input parameters of function READ_SSI_COUNTER.

1.7.1.21.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Execution of the FB has finished
SSI_Value_DI DINT SSI Counter value
Result of the FB execution.
Status_enCounterRet enCounterRet
The data structure is in the Regulation02.lib library
Tbl. 1.212 Output parameters of function READ_SSI_COUNTER.

1.7.1.21.5 Data Types

1.7.1.21.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.213 Enumerator enCounterType.

Ingeteam Proprietary All Rights Reserved Pag. 264


1.7.1.21.5.2 stIC3392SSI

Field Name Type Description


CounterNum_DI DINT Counter number to use SSI encoder.
ConfSSI_stSSICounterConf_ST stSSICounterConf stSSICounterConf structure to configure the SSI encoder.
Tbl. 1.214 Fields of the stIC3392SSI structure.

1.7.1.21.5.3 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5
ERR_COUNT_CFG_PARAM (11)
or stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.215 Enumerator enCounterRet.

1.7.1.21.5.4 stSSICounterConf

Field Name Type Description


Number of bits from SSI channel. This value has to be between 8 and
EncoderBitNumber_SI SINT
32. Otherwise, the configuration is incorrect.
The period of encoder clock in microseconds and has to be between
EncoderClockPeriodUS_SI SINT
1us and 31us. If period=0 the configuration is incorrect.
Minimun time between the end of one reading and the beginning of
TminBetweenReadingsUS_I INT the next one in microseconds. this value has to be between 1us and
255us, otherwise the configuration is incorrect.
Tbl. 1.216 Fields of the stSSICounterConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 265


1.7.1.21.6 Example

PROGRAM Example_READ_SSI_COUNTER

(*This example reads the value of SSI encoder.*)

VAR

ReadSSICounter: READ_SSI_COUNTER;(*Function to read SSI encoder*)

EnReadSSICounter: BOOL;(*Enable to read SSI encoder*)

(*Configuration to define the configuration of the SSI encoder*)

SSICounterConf: stIC3392SSI := (

CounterNum_DI:=0,(*Counter number 2*)

ConfSSI_stSSICounterConf_ST:=(

EncoderBitNumber_SI:=25,(*Encoder BIT number*)

EncoderClockPeriodUS_SI:=31,(*Encoder clock period*)

TminBetweenReadingsUS_I:=255));(*Minimum time
between readings*)

END_VAR

(*Call to the SPEED_COUNTER function*)

READ_SSI_COUNTER(

Enable_BL:=EnReadSSICounter,(*Enable to read SSI encoder*)

CounterType_enCounterType:=IC3392, (*Module type*)

ChassisNum_DI:=0,(*Chasis number*)

SlotNum_DI:=8,(*Slot number*)

CounterConfigure_ADR:=ADR(SSICounterConf),(*Address to configuration structure*)

CounterConfigureSizeBy_DI:=SIZEOF(SSICounterConf),(*Size of configuration structure*)

Done_BL=>,(*The FB has finished*)

SSI_Value_DI=>,(*Readed encoders value*)

Status_enCounterRet=> );(*Finished status of FB*)

Ingeteam Proprietary All Rights Reserved Pag. 266


1.7.1.22 RISING_TRIG

1.7.1.22.1 Description

Rising Edge detection.

The RISING_TRIG function detects rising edges in a BOOL type signal at the input.

1.7.1.22.2 Syntax

FUNCTION_BLOCK RISING_TRIG

VAR_INPUT

In_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.7.1.22.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Function input variable for detection of the rising edge.
Tbl. 1.217 Input parameters of function RISING_TRIG.

1.7.1.22.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the pulse in the rising edge.
Tbl. 1.218 Output parameters of function RISING_TRIG.

Ingeteam Proprietary All Rights Reserved Pag. 267


1.7.1.22.5 Remarks

The RISING_TRIG function can detect rising edges in the In_BL input signal. This signal has to
be a BOOL type signal. When the function detects a rising edge, it produces a pulse in its
Out_BL output.

Fig. 1.12 .

1.7.1.22.6 Example

PROGRAM Example

VAR

(*RISING_TRIG*)

RisingEdgePulse :RISING_TRIG;

OutputPulsesCounter:INT := 0;

nTest:INT :=0;

END_VAR

CASE nTest OF

1:(* RisingEdgePulse :R_TRIG *)

RisingEdgePulse( In_BL :=FALSE );

IF(RisingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

2:(* Detects rising edges in the In_BL input signal *)

RisingEdgePulse( In_BL :=TRUE);

IF(RisingEdgePulse.Out_BL)

Ingeteam Proprietary All Rights Reserved Pag. 268


THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.7.1.23 RTC_TIMER

1.7.1.23.1 Description

Real Time Counter Timer.

The RTC_TIMER function returns the date and time that have elapsed since a given moment.
The user can start the clock at a specific date and time and the function will return the current
date and time at each call.

1.7.1.23.2 Syntax

FUNCTION_BLOCK RTC_TIMER

VAR_INPUT

Enable_BL:BOOL;

Start_DT:DT;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Current_DT:DT;

END_VAR

1.7.1.23.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is disabled waiting to detect the rising edge.
The Current_DT output will be DT#1970-01-01-00:00:00.
Enable_BL BOOL
TRUE: When the rising edge occurs, it loads the value of Start_DT in Current_DT.
While it remains at TRUE, the function increases the time counter.
Date and time that will be loaded in the Current_DT output variable when a rising
Start_DT DT
edge occurs in the Enable_BL input.
Tbl. 1.219 Input parameters of function RTC_TIMER.

Ingeteam Proprietary All Rights Reserved Pag. 269


1.7.1.23.4 Output parameters

Output Parameter Name Type Description


FALSE: The function is not enabled since the input parameter Enable_BL:=FALSE.
Out_BL BOOL
TRUE The function is enabled and counting the elapsed time.
Current_DT DT Date and time of output calculated by the RTC_TIMER function.
Tbl. 1.220 Output parameters of function RTC_TIMER.

1.7.1.23.5 Remarks

To understand the operation of the RTC_TIMER function, three situations that will produce
different outputs should be considered:

While the input variable Enable_BL:=FALSE, the function will be disabled and therefore will not
increment the time. In this situation, the output Out_BL:=FALSE and the date and time delivered
in Current_DT:=01-01-1970-00:00:00.

When a rising edge occurs in the Enable_BL input, the function sets Out_BL:=TRUE and loads
the value of Start_DT in the Current_DT variable.

While the input variable Enable_BL:=TRUE, the function will be enabled and will therefore
increment the value of the output date and time of the Current_DT variable.

1.7.1.23.6 Example

PROGRAM Example

VAR

RunTimeCounter : RTC_TIMER;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(* RunTimeCounter : RTC_TIMER *)

(* Use a RunTimeCounter*)RunTimeCounter( Enable_BL :=FALSE) ;

(*RunTimeCounter.Out_BL = FALSE *)

2:RunTimeCounter( Enable_BL:=TRUE, Start_DT:=DT#2010-07-14-15:36:30);

(*RunTimeCounter.Out_BL = TRUE *)

(*RunTimeCounter.Current_DT = actual value *)

3:RunTimeCounter( Enable_BL :=FALSE) ;

(*RunTimeCounter.Current_DT = DT#1970-01-01-00:00:00 *)

Ingeteam Proprietary All Rights Reserved Pag. 270


END_CASE;

1.7.1.24 SPEED_COUNTER

1.7.1.24.1 Description

Function to use the Generic counter (IC3325) and reduced counter (IC3391) for measuring the
speed of a signal on input channel

1.7.1.24.2 Syntax

FUNCTION_BLOCK SPEED_COUNTER

VAR_INPUT

Enable_BL:BOOL;

CounterType_enCounterType:enCounterType;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterConfigure_ADR:DWORD;

CounterConfigureSizeBy_DI:DINT;

PulsesPerRotation_R:REAL;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

SpeedRPM_R:REAL;

Status_enCounterRet:enCounterRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 271


1.7.1.24.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Flag to Enable the function.
Counter Type. CONFIGURATION Variables.
CounterType_enCounterType enCounterType
Counter parameters.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
Number of the slot where the module is installed (0..15).
SlotNum_DI DINT
Counter structures.
Pointer to the memory buffer where configuration structure is stored.
CounterConfigure_ADR DWORD For the IC3325 module use stIC3325Speed.
For the IC3391 module use stIC3391Speed.
Size of the configuration structure in bytes.
CounterConfigureSizeBy_DI DINT
Coversion Parameters.
PulsesPerRotation_R REAL Number of pulses per rotation.
Tbl. 1.221 Input parameters of function SPEED_COUNTER.

1.7.1.24.4 Output parameters

Output Parameter Name Type Description


Done_BL BOOL Execution of the FB has finishedREAD Variables
SpeedRPM_R REAL Measured speed in rpm
Result of the FB execution.
Status_enCounterRet enCounterRet
The data structure is in the Regulation02.lib library
Tbl. 1.222 Output parameters of function SPEED_COUNTER.

1.7.1.24.5 Data Types

1.7.1.24.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.223 Enumerator enCounterType.

1.7.1.24.5.2 enIC3391InputSignal

Value Description
IN0 (0) Input 0
IN1 (1) Input 1
IN2 (2) Input 2
IN3 (3) Input 3
IN4 (4) Input 4
IN5 (5) Input 5
Tbl. 1.224 Enumerator enIC3391InputSignal.

Ingeteam Proprietary All Rights Reserved Pag. 272


1.7.1.24.5.3 enInputSignalCodification

Value Description
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time
you get the whole sequence CHA rises - CHB rises - CHA falls - CHB falls. The
MODE1 (0)
counter is decremented each time you get the whole sequence CHB rises - CHA
rises - CHB falls - CHA falls.
CHA is a pulse input and CHB indicates the direction of counting: Increase if
CHB=1 and decrease if CHB=0. The counter is incremented each time CHA
MODE2 (1)
rises being CHB=1. The counter is decremented each time CHA rises being
CHB=0
CHA is a decremental pulse input, and CHB is an incremental pulse input. The
MODE3 (2) counter is incremented each time CHB rises. The counter is decremented each
time CHA rises
Pulses (incremental always) are generated with an internal clock 10 Mhz
MODE4 (3)
frequency
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time
CHA rises being CHB=0, or CHB rises being CHA=1, or CHA falls being
MODE5 (4) CHB=1, or CHB falls being CHA=0. The counter is decremented each time
CHB rises being CHA=0,or CHA rises being CHB=1, or CHB falls being
CHA=1, or CHA falls being CHB=0
CHA is a pulse input and CHB indicates the direction of counting: Increases when
CHB=1 and decreases when CHB=0. The counter is incremented each time
MODE6 (5)
CHA rises or CHA falls being CHB=1. The counter is decremented each time
CHA rises or CHA falls being CHB=0
CHA is a decremental pulse input, and CHB is a incremental pulse input. The
MODE7 (6) counter is incremented each time CHB rises or CHB falls. The counter is
decremented each time CHA rises or CHA falls
Tbl. 1.225 Enumerator enInputSignalCodification.

1.7.1.24.5.4 stIC3325Speed

Field Name Type Description


CounterNum_DI DINT Counter number to use for the speed measuring.
Type of coding of signals from chanels CHA and
InputSignalCod_enInputSignalCodification enInputSignalCodification
CHB.
Logic of the signal conected to the CHANEL A
CHAInverted_BL BOOL
(TRUE--> Inverted Logic, FALSE--> Direct Logic).
Logic of the signal conected to the CHANEL B
CHBInverted_BL BOOL
(TRUE--> Inverted Logic, FALSE--> Direct Logic).
Tbl. 1.226 Fields of the stIC3325Speed structure.

1.7.1.24.5.5 stIC3391Speed

Field Name Type Description


CounterNum_DI DINT Counter number to use for the speed measuring.
Type of coding of signals from chanels CHA and
InputSignalCod_enInputSignalCodification enInputSignalCodification
CHB.
Physical input signal selected like channel A
CHASignal_enIC3391InputSignal enIC3391InputSignal
(IN0IN5)).
Logic of the signal conected to the CHANEL A
CHAInverted_BL BOOL
(TRUE--> Inverted Logic, FALSE--> Direct Logic).
Physical input signal selected like channel B
CHBSignal_enIC3391InputSignal enIC3391InputSignal
(IN0IN5)).
Logic of the signal conected to the CHANEL B
CHBInverted_BL BOOL
(TRUE--> Inverted Logic, FALSE--> Direct Logic).
Tbl. 1.227 Fields of the stIC3391Speed structure.

Ingeteam Proprietary All Rights Reserved Pag. 273


1.7.1.24.5.6 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.228 Enumerator enCounterRet.

1.7.1.24.6 Example

PROGRAM Example_SPEED_COUNTER

(*This example measures the speed of encoder with pulses shifted 90connected to the IN3 and
IN4 inputs of a IC3391 module.*)

VAR

SpeedCounter: SPEED_COUNTER;(*Function to measure the encoders speed*)

EnSpeedCounter: BOOL;(*Enable to measure the encoders speed*)

(*Configuration to define the counter, type of encoder and inputs to use to measure the
encoders speed*)

SpeedCounterConf: stIC3391Speed := (

CounterNum_DI:=2,(*Counter number 2*)

Ingeteam Proprietary All Rights Reserved Pag. 274


InputSignalCod_enInputSignalCodification:=MODE1,(*Type of encoder.
MODE1=encoder with pulses shifted 90*)

CHASignal_enIC3391InputSignal:=IN3, (*Signal connected to input 3 of the


module*)

CHAInverted_BL:=FALSE,(*Not inverted*)

CHBSignal_enIC3391InputSignal:=IN4,(*Signal connected to input 4 of the


module*)

CHBInverted_BL:=FALSE );(*Not inverted*)

END_VAR

(*Call to the SPEED_COUNTER function*)

SpeedCounter(

Enable_BL:=EnSpeedCounter,(*Enable to measure the encoders speed*)

CounterType_enCounterType:=IC3391, (*Module type*)

ChassisNum_DI:=0,(*Chasis number*)

SlotNum_DI:=7,(*Slot number*)

CounterConfigure_ADR:=ADR(SpeedCounterConf),(*Address to configuration structure*)

CounterConfigureSizeBy_DI:=SIZEOF(SpeedCounterConf),(*Size of configuration
structure*)

PulsesPerRotation_R:=1024,(*Number of pulses per rotation of the encoder*)

Done_BL=>,(*The FB has finished*)

SpeedRPM_R=>,(*Measured encoders speed*)

Status_enCounterRet=> );(*Finished status of FB*)

1.7.1.25 STATISTICS_I

1.7.1.25.1 Description

Function block for statistics.

The STATISTICS_I function calculates various statistical data such as the minimum value,
maximum value and average of an input variable.

1.7.1.25.2 Syntax

FUNCTION_BLOCK STATISTICS_I

Ingeteam Proprietary All Rights Reserved Pag. 275


VAR_INPUT

In_I:INT;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Min_I:INT;

Max_I:INT;

Average_I:INT;

END_VAR

1.7.1.25.3 Input parameters

Input Parameter Name Type Description


In_I INT Variable for which to calculate the statistical data.
Reset_BL BOOL If TRUE resets the statistical values calculated up to that point.
Tbl. 1.229 Input parameters of function STATISTICS_I.

1.7.1.25.4 Output parameters

Output Parameter Name Type Description


Min_I INT Minimum value of the input variable.
Max_I INT Maximum value of the input variable.
Average_I INT Average value of the input variable.
Tbl. 1.230 Output parameters of function STATISTICS_I.

1.7.1.25.5 Remarks

The STATISCTICS_I function is very easy to use. All that is required is a call to function with an
INT type variable in the In_Iinput.

The previous calculation can be reset at the start using the Reset_BL input.

The statistical data on minimum, maximum and average values are obtained in the INT type
variables Min_I, Max_I and Average_I respectively.

1.7.1.25.6 Example

PROGRAM Example

VAR

(*STATISTICS_I*)

Ingeteam Proprietary All Rights Reserved Pag. 276


CounterStatistics : STATISTICS_I;

Counter:INT;

END_VAR

FOR Counter:=-10 TO 10 BY 1 DO

CounterStatistics( In_I:= Counter );

END_FOR

(* CounterStatistics.Min_I = -1

CounterStatistics.Max_I = +1

CounterStatistics.Average_I = 0*)

1.7.1.26 STATISTICS_R

1.7.1.26.1 Description

Function block for statistics.

The purpose and structure of the STATISTICS_R function is the same as that of the
STATISTICS_I function, but with this function the inputs and calculations are performed with
REAL type variables.

1.7.1.26.2 Syntax

FUNCTION_BLOCK STATISTICS_R

VAR_INPUT

In_R:REAL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Min_R:REAL:=3E+38;

Max_R:REAL:=-3E+38;

Average_R:REAL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 277


1.7.1.26.3 Input parameters

Input Parameter Name Type Description


In_R REAL Variable for which to calculate the statistical data.
Reset_BL BOOL If TRUE resets the statistical values calculated up to that point.
Tbl. 1.231 Input parameters of function STATISTICS_R.

1.7.1.26.4 Output parameters

Output Parameter Name Type Description


Min_R REAL Minimum value of the input variable.
Max_R REAL Maximum value of the input variable.
Average_R REAL Average value of the input variable.
Tbl. 1.232 Output parameters of function STATISTICS_R.

1.7.1.26.5 Remarks

The STATISTICS_R function is very easy to use. All that is required is a call to function with a
REAL type variable in the In_R input.

The previous calculation can be reset at the start using the Reset_BL input.

The statistical data on minimum, maximum and average values are obtained in the REAL type
variables Min_R, Max_R and Average_R respectively.

1.7.1.26.6 Example

PROGRAM Example

VAR

(*STATISTICS_R*)

TrigonometricStatistics : STATISTICS_R;

Alpha:REAL;

Dummy:REAL;

END_VAR

FOR Counter:=0 TO 63 BY 1 DO (*2*PI*10*)

Alpha:=INT_TO_REAL(Counter)/10;

TrigonometricStatistics( In_R:= SIN( Alpha ) );

END_FOR

(*TrigonometricStatistics.Min_R = -1

TrigonometricStatistics.Max_R = +1

Ingeteam Proprietary All Rights Reserved Pag. 278


TrigonometricStatistics.Average_R = 0

*)

1.7.1.27 TIMER_PULSE

1.7.1.27.1 Description

Timer Pulse.

The TIMER_PULSE function generates a pulse lasting for a certain duration on detecting an
input which generates a rising edge.

1.7.1.27.2 Syntax

FUNCTION_BLOCK TIMER_PULSE

VAR_INPUT

In_BL:BOOL;

Length_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.7.1.27.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Input variable to the function to detect the rising edge and begin timing.
Length_T TIME Period of time to maintain the output pulse at TRUE.
Tbl. 1.233 Input parameters of function TIMER_PULSE.

1.7.1.27.4 Output parameters

Output Parameter Name Type Description


The output variable that is a result of maintaining the value established in
Out_BL BOOL
Length_T at TRUE.
Elapsed_T TIME Time elapsed from when timing started.
Tbl. 1.234 Output parameters of function TIMER_PULSE.

Ingeteam Proprietary All Rights Reserved Pag. 279


1.7.1.27.5 Remarks

The use of the TIMER_PULSE function is similar to that of timing.

A BOOL TYPE variable must be assigned TO the In_BL input. When a rising edge occurs in this
variable, the FUNCTION sets the Out_BL output TO TRUE AND begins counting the TIME
(output variable Elapsed_T). As soon as this TIME (Current_T) matches the TIME set in the
Length_T input parameter, the FUNCTION will set the Out_BL output variable TO FALSE.

If the In_BL input is not set to TRUE for a time equal to Length_T, the function will maintain the
Out_BL output to TRUE until the time has elapsed. If during this time span when In_BL:=FALSE
and Out_BL:=TRUE another rising edge occurs in the In_BL input, then the function will not take
it into consideration and will continue with the original timing.

1.7.1.27.6 Example

PROGRAM Example

VAR

(*TIMER_PULSE*)

TimerPulse : TIMER_PULSE;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(*TimerPulse:TIMER_PULSE*)

(*Get an pulse output signal on 3 seconds with TimerOn *)

TimerPulse(In_BL:=TRUE,Length_T:=T#3s) ;

(*TimerPulse.Out_BL=FALSEuntil time elapsed*)

(*TimerPulse.Elapsed_T=timer value increasing*)

2: (*Reset timer*)

TimerPulse(In_BL :=FALSE ) ;

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 280


1.7.1.28 TOF_ABSOLUTE

1.7.1.28.1 Description

Timer off delay.

The TOF_ABSOLUTE function has the same purpose as the TOF_RELATIVE function, which is
timing the disconnection of a boolean input variable. However, unlike TOF_RELATIVE, the
TOF_ABSOLUTE function considers absolute execution time and is not affected by whether the
function block is called to count the time or not.

The function output will be at 1 while the input is also at 1. As soon as a falling edge is detected
in the input, the function begins timing based on the established parameter. The function output
will pass to 0 a time after the falling edge has occurred in the input.

If the input does not remain at 0 during the period set for timing, the output will at not point
change to 0. The function will wait for a repeated falling edge to perform new complete timing.

1.7.1.28.2 Syntax

FUNCTION_BLOCK TOF_ABSOLUTE

VAR_INPUT

In_BL:BOOL;

DeactivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.7.1.28.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Starts timer with falling edge, resets timer with rising edge.
DeactivationDelay_T TIME Time to pass, before Out_BL is set.
Tbl. 1.235 Input parameters of function TOF_ABSOLUTE.

Ingeteam Proprietary All Rights Reserved Pag. 281


1.7.1.28.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Is FALSE, DeactivationDelay_T seconds after In_BL had a falling edge
Elapsed_T TIME Time elapsed since timing started.
Tbl. 1.236 Output parameters of function TOF_ABSOLUTE.

1.7.1.28.5 Remarks

The TOF_ABSOLUTE function considers absolute time, regardless of whether the function block
is called or not. If the block is not being called, but the time has run out, when the function is
called for the first time the output will show the timing complete status.

The purpose of the TOF_ABSOLUTE function is to obtain in an output variable (Out_BL), the
equivalent of disconnection timing of a digital input signal (In_BL). This timing is performed
according to the time parameter DeactivationDelay_T.

At the start, the function sets its output to 1 at the same instant that the input signal changes to
1.

Once this occurs, the function remains waiting to detect a falling edge in the input. When this
edge occurs, timing begins counting internally. The function continues counting time as long as
the input is set at 0. Once the pre-established time has run out, the function will set the output to
0. This output will remain at 0 while the input continues at the low value.

If once the falling edge has occurred in the input, the input does not remain inactive during the
time established for timing, then the function will at not point set the output to 0. The function will
remain on standby to detect a falling edge in the input.

The time elapsed during timing can be ascertained at any time by referring to the values of the
Elapsed_T output variable.

Fig. 1.13 .

Ingeteam Proprietary All Rights Reserved Pag. 282


1.7.1.28.6 Example

PROGRAM Example

VAR

(*TOF_ABSOLUTE *)

TimerOff: TOF_ABSOLUTE;

nTest: INT :=0;

END_VAR

CASE nTest OF

1: (*Reset timer*)(* Initialize a TOF_ABSOLUTE timer *)

TimerOff(In_BL :=TRUE, DeactivationDelay_T:= T#5s);

2: (*Reset timer*)(*Start timer off *)

TimerOff(In_BL :=FALSE);

END_CASE

Ingeteam Proprietary All Rights Reserved Pag. 283


1.7.1.29 TON_ABSOLUTE

1.7.1.29.1 Description

Timer on delay.

The TON_ABSOLUTE function has the same purpose as the TON_RELATIVE function, which is
timing the connection of a Boolean input variable. However, unlike TON_RELATIVE, the TON
function takes considers absolute execution time and is not affected by whether the function
block is called to count the time or not.

As soon as a rising edge is detected in the input, the function begins timing based on the
established parameter. Once the time has run out, the function will set the output to 1.

If the input does not remain at 1 during the period set for timing, the output will at no point
change to 1. The function will wait for a repeated rising edge to perform new complete timing.

1.7.1.29.2 Syntax

FUNCTION_BLOCK TON_ABSOLUTE

VAR_INPUT

In_BL:BOOL;

ActivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.7.1.29.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Starts timer with rising edge, resets timer with falling edge.
ActivationDelay_T TIME Time to pass, before Out_BL is set.
Tbl. 1.237 Input parameters of function TON_ABSOLUTE.

Ingeteam Proprietary All Rights Reserved Pag. 284


1.7.1.29.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Is TRUE ActivationDelay_Tseconds after In_BL had a rising edge.
Elapsed_T TIME Time elapsed since timing started.
Tbl. 1.238 Output parameters of function TON_ABSOLUTE.

1.7.1.29.5 Remarks

The TON_ABSOLUTE function considers absolute time, regardless of whether the function block
is called or not. If the block is not being called, but the time has run out, when the function is
called for the first time the output will show the timing complete status.

The purpose of the TON_ABSOLUTE function is to obtain in an output variable (Out_BL), the
equivalent of connection timing of a digital input signal (In_BL). This timing is performed
according to the time parameter ActivationDelay_T.

The function will remain on standby to detect a rising edge in the input. When this edge occurs,
timing begins counting internally. The function continues counting time as long as the input is set
at 1. Once the pre-established time has run out, the function will set the output to 1. This output
will remain at 1 while the input continues at the high value.

If once the rising edge has occurred in the input, the input does not remain active during the time
established for timing, then the function will at not point set the output to 1. The function will
remain on standby to detect a rising edge in the input.

Fig. 1.14 .

Ingeteam Proprietary All Rights Reserved Pag. 285


1.7.1.29.6 Example

PROGRAM Example

VAR

(*TOF_ABSOLUTE *)

TimerOn: TON_ABSOLUTE;

nTest: INT :=0;

END_VAR

CASE nTest OF

1:(*Initialize a TON_ABSOLUTE timer*)

TimerOn(In_BL:=FALSE,ActivationDelay_T:=T#5s);

2:(*Start timer on *)

TimerOn (In_BL :=TRUE);

END_CASE

1.7.1.30 VARIANCE_R

1.7.1.30.1 Description

Function block to calculate the mathematical variance of a variable.

1.7.1.30.2 Syntax

FUNCTION_BLOCK VARIANCE_R

VAR_INPUT

In_R:REAL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_R:REAL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 286


1.7.1.30.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input variable.
Reset_BL BOOL If TRUE resets the variance calculated up to that point.
Tbl. 1.239 Input parameters of function VARIANCE_R.

1.7.1.30.4 Output parameters

Output Parameter Name Type Description


Out_R REAL Calculated variance.
Tbl. 1.240 Output parameters of function VARIANCE_R.

1.7.1.30.5 Remarks

The VARIANCE_R function is very easy to use. All that is required is a call to function with a
REAL type variable in the In_R input.

The previous calculation can be reset at the start to TRUE using the Reset_BL input.

The calculated variance value can be obtained from the REAL type Out_R output variable.

1.7.1.30.6 Example

PROGRAM Example

VAR

Dice:INT;

VarianceOnDice : VARIANCE_R;

END_VAR

(*Get the variance when we throw a dice 6 times*)

FOR Dice:=1 TO 6 BY 1 DO

VarianceOnDice( in_R := INT_TO_REAL(Dice));

END_FOR

(* VarianceOnDice.Out_R = 2.91*)

Ingeteam Proprietary All Rights Reserved Pag. 287


1.8 Regulation_02

The following tables sumarize the entities contained in Regulation_02:

Name Description
The ASTAB_OFFON_ASYNC_DISC function outputs a BOOL value starting on 0, according
ASTAB_OFFON_ASYNC_DISC to a time ON and OFF parameters. This function ends asynchronically, if the input goes to
zero, the output will remain on 1 until the TimeON_T finishes.
The ASTAB_OFFON_SYNC_DISC function outputs a BOOL value starting on 0, according to
ASTAB_OFFON_SYNC_DISC a time ON and OFF parameters. This function ends synchronically, if the input goes to zero,
the output will be zero regardless the TimeON_T has finished or not.
The ASTAB_ONOFF_ASYNC_DISC function outputs a BOOL value starting on 1, according
ASTAB_ONOFF_ASYNC_DISC to a time ON and OFF parameters. This function ends asynchronically, if the input goes to
zero, the output will remain on 1 until the TimeON_T finishes.
The ASTAB_ONOFF_SYNC_DISC function outputs a BOOL value starting on 1, according to
ASTAB_ONOFF_SYNC_DISC a time ON and OFF parameters. This function ends synchronically, if the input goes to zero,
the output will be zero regardless the TimeON_T has finished or not.
The CHARCURVE_REAL function interpolates an input value between the points defined in a
CHARCURVE_REAL
table.
CONFIGURE_COUNTER This function is used to configurate a Fast Counter
The COUNTER_DOWN function performs a decrement operation on detecting edges in one
COUNTER_DOWN of its inputs. When the value to count down reaches 0, the function activates an indication
flag.
The COUNTER_UP function increments an output variable on detecting rising edges in one
COUNTER_UP of its inputs. The function returns an indication flag when the count variable exceeds the value
defined as the upper limit.
The COUNTER_UP_DOWN function is a combination of the COUNTER_DOWN function for
COUNTER_UP_DOWN
the decrement counter and the COUNTER_UP function for the increment counter.
FALLING_TRIG Falling Edge detection.
FILTER This function filters the input variable.
PULSE Pulse generation.
READ_COUNTER Function is used to read a Fast Counter.
REARM_PULSE When the input is activated, there is a pulse lasting a programmable length of time.
RISING_TRIG Rising Edge detection.
RTC_TIMER Real Time Counter Timer.
SP_GEN_REG_EMF_V Function that elaborates a Regulator with a PI algorithm.
SPEED_REGULATOR Function to elaborate a Speed Regulator with a PID algorithm.
TIMER_PULSE Timer Pulse.
TOF_ABSOLUTE Timer off delay.
TOF_RELATIVE Timer Off Delay.
TON_ABSOLUTE Timer on delay.
TON_RELATIVE Timer On Delay.
TONOF_RELATIVE Timer On/Off Delay.
WRITE_COUNTER This function is used to write to a Fast Counter.
Tbl. 1.241 Functions, Function Blocks, and Programs.

Ingeteam Proprietary All Rights Reserved Pag. 288


1.8.1 Functions

1.8.1.1 ASTAB_OFFON_ASYNC_DISC

1.8.1.1.1 Description

The ASTAB_OFFON_ASYNC_DISC function outputs a BOOL value starting on 0, according to a


time ON and OFF parameters. This function ends asynchronically, if the input goes to zero, the
output will remain on 1 until the TimeON_T finishes.

1.8.1.1.2 Syntax

FUNCTION_BLOCK ASTAB_OFFON_ASYNC_DISC

VAR_INPUT

Input_BL:BOOL;

TimeON_T:TIME;

TimeOF_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_enAstableRet:enAstableRet;

END_VAR

1.8.1.1.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input wich causes the start of the pulses when a rising edge occurs.
TimeON_T TIME Duration of pulse ON.
TimeOF_T TIME Duration of pulse OFF. Only task time is taken into account.
Tbl. 1.242 Input parameters of function ASTAB_OFFON_ASYNC_DISC.

1.8.1.1.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output with delayed activation and delayed deactivation.
Status_enAstableRet enAstableRet Function Status.
Tbl. 1.243 Output parameters of function ASTAB_OFFON_ASYNC_DISC.

Ingeteam Proprietary All Rights Reserved Pag. 289


1.8.1.1.5 Data Types

1.8.1.1.5.1 enAstableRet

Value Description
OK_ASTABLE (0) Correct Execution
WARNING_TIMEON_T_LESS_THAN_CYCLE_TIME (1) Warning: TimeON_T < Cycle_TIME
WARNING_TIMEOFF_T_LESS_THAN_CYCLE_TIME (2) Warning: TimeOFF_T < Cycle_TIME
ERR_ASTABLE_INTERNAL_ERROR (3) Internal Error
Tbl. 1.244 Enumerator enAstableRet.

1.8.1.1.6 Remarks

This function's output logic states 0 and 1 as soon as the input is activated. The duration of the
pulses can be programmed using the function's parameters. When the input is deactivated
again, if the output is in a positive pulse, it is deactivated after the time assigned to the pulse has
elapsed, asynchronously.

Fig. 1.15 .

1.8.1.1.7 Example

FUNCTION_BLOCK Astab_OffOn_Async_DISC

VAR

AstabInput:BOOL;

Astab:ASTAB_OFFON_ASYNC_DISC;

END_VAR

Astab(

Input_BL:= AstabInput,

TimeON_T:= T#2000ms,

TimeOF_T:= T#3000ms,

Output_BL=>,

Ingeteam Proprietary All Rights Reserved Pag. 290


Status_DI=>);

1.8.1.2 ASTAB_OFFON_SYNC_DISC

1.8.1.2.1 Description

The ASTAB_OFFON_SYNC_DISC function outputs a BOOL value starting on 0, according to a


time ON and OFF parameters. This function ends synchronically, if the input goes to zero, the
output will be zero regardless the TimeON_T has finished or not.

1.8.1.2.2 Syntax

FUNCTION_BLOCK ASTAB_OFFON_SYNC_DISC

VAR_INPUT

Input_BL:BOOL;

TimeON_T:TIME;

TimeOF_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_enAstableRet:enAstableRet;

END_VAR

1.8.1.2.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input.
TimeON_T TIME Duration of pulse ON.
TimeOF_T TIME Duration of pulse OFF. Only task time is taken into account.
Tbl. 1.245 Input parameters of function ASTAB_OFFON_SYNC_DISC.

1.8.1.2.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output with delayed activation and delayed deactivation.
Status_enAstableRet enAstableRet Function Status.
Tbl. 1.246 Output parameters of function ASTAB_OFFON_SYNC_DISC.

Ingeteam Proprietary All Rights Reserved Pag. 291


1.8.1.2.5 Data Types

1.8.1.2.5.1 enAstableRet

Value Description
OK_ASTABLE (0) Correct Execution
WARNING_TIMEON_T_LESS_THAN_CYCLE_TIME (1) Warning: TimeON_T < Cycle_TIME
WARNING_TIMEOFF_T_LESS_THAN_CYCLE_TIME (2) Warning: TimeOFF_T < Cycle_TIME
ERR_ASTABLE_INTERNAL_ERROR (3) Internal Error
Tbl. 1.247 Enumerator enAstableRet.

1.8.1.2.6 Remarks

This function's output logic states 0 and 1 as soon as the input is activated. The duration of the
pulses can be programmed using the function's parameters. When the input is deactivated
again, the output is deactivated at the same time ( synchronously) if it is in a positive pulse.

Fig. 1.16 .

1.8.1.2.7 Example

FUNCTION_BLOCK Astab_OffOn_Sync_DISC

VAR

AstabInput:BOOL;

Astab:ASTAB_OFFON_SYNC_DISC;

END_VAR

Astab(

Input_BL:= AstabInput,

TimeON_T:= T#2000ms,

TimeOF_T:= T#3000ms,

Output_BL=>,

Status_DI=>);

Ingeteam Proprietary All Rights Reserved Pag. 292


1.8.1.3 ASTAB_ONOFF_ASYNC_DISC

1.8.1.3.1 Description

The ASTAB_ONOFF_ASYNC_DISC function outputs a BOOL value starting on 1, according to a


time ON and OFF parameters. This function ends asynchronically, if the input goes to zero, the
output will remain on 1 until the TimeON_T finishes.

1.8.1.3.2 Syntax

FUNCTION_BLOCK ASTAB_ONOFF_ASYNC_DISC

VAR_INPUT

Input_BL:BOOL;

TimeON_T:TIME;

TimeOF_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_enAstableRet:enAstableRet;

END_VAR

1.8.1.3.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input.
TimeON_T TIME Duration of pulse ON.
TimeOF_T TIME Duration of pulse OFF. Only task time is taken into account.
Tbl. 1.248 Input parameters of function ASTAB_ONOFF_ASYNC_DISC.

1.8.1.3.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output with delayed activation and delayed deactivation.
Status_enAstableRet enAstableRet Function Status.
Tbl. 1.249 Output parameters of function ASTAB_ONOFF_ASYNC_DISC.

Ingeteam Proprietary All Rights Reserved Pag. 293


1.8.1.3.5 Data Types

1.8.1.3.5.1 enAstableRet

Value Description
OK_ASTABLE (0) Correct Execution
WARNING_TIMEON_T_LESS_THAN_CYCLE_TIME (1) Warning: TimeON_T < Cycle_TIME
WARNING_TIMEOFF_T_LESS_THAN_CYCLE_TIME (2) Warning: TimeOFF_T < Cycle_TIME
ERR_ASTABLE_INTERNAL_ERROR (3) Internal Error
Tbl. 1.250 Enumerator enAstableRet.

1.8.1.3.6 Remarks

This function's output logic states 1 and 0 as soon as the input is activated. The duration of the
pulses can be programmed using the function's parameters. When the input is deactivated
again, if the output is in a positive pulse, it is deactivated after the time assigned to the pulse has
elapsed, asynchronously.

Fig. 1.17 .

1.8.1.3.7 Example

FUNCTION_BLOCK Astab_OnOff_Async_DISC

VAR

AstabInput:BOOL;

Astab:ASTAB_ONOFF_ASYNC_DISC;

END_VAR

Astab(

Input_BL:= AstabInput,

TimeON_T:= T#2000ms,

TimeOF_T:= T#3000ms,

Output_BL=>,

Status_DI=>);

Ingeteam Proprietary All Rights Reserved Pag. 294


1.8.1.4 ASTAB_ONOFF_SYNC_DISC

1.8.1.4.1 Description

The ASTAB_ONOFF_SYNC_DISC function outputs a BOOL value starting on 1, according to a


time ON and OFF parameters. This function ends synchronically, if the input goes to zero, the
output will be zero regardless the TimeON_T has finished or not.

1.8.1.4.2 Syntax

FUNCTION_BLOCK ASTAB_ONOFF_SYNC_DISC

VAR_INPUT

Input_BL:BOOL;

TimeON_T:TIME;

TimeOF_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_enAstableRet:enAstableRet;

END_VAR

1.8.1.4.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input.
TimeON_T TIME Duration of pulse ON.
TimeOF_T TIME Duration of pulse OFF. Only task time is taken into account.
Tbl. 1.251 Input parameters of function ASTAB_ONOFF_SYNC_DISC.

1.8.1.4.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output with delayed activation and delayed deactivation.
Status_enAstableRet enAstableRet Function Status.
Tbl. 1.252 Output parameters of function ASTAB_ONOFF_SYNC_DISC.

Ingeteam Proprietary All Rights Reserved Pag. 295


1.8.1.4.5 Data Types

1.8.1.4.5.1 enAstableRet

Value Description
OK_ASTABLE (0) Correct Execution
WARNING_TIMEON_T_LESS_THAN_CYCLE_TIME (1) Warning: TimeON_T < Cycle_TIME
WARNING_TIMEOFF_T_LESS_THAN_CYCLE_TIME (2) Warning: TimeOFF_T < Cycle_TIME
ERR_ASTABLE_INTERNAL_ERROR (3) Internal Error
Tbl. 1.253 Enumerator enAstableRet.

1.8.1.4.6 Remarks

This function's output logic states 1 and 0 as soon as the input is activated. The duration of the
pulses can be programmed using the function's parameters. When the input is deactivated
again, the output is deactivated at the same time ( synchronously) if it is in a positive pulse.

Fig. 1.18 .

1.8.1.4.7 Example

FUNCTION_BLOCK Astab_OnOff_Sync_DISC

VAR

AstabInput:BOOL;

Astab:ASTAB_ONOFF_SYNC_DISC;

END_VAR

Astab(

Input_BL:= AstabInput,

TimeON_T:= T#2000ms,

TimeOF_T:= T#3000ms,

Output_BL=>,

Status_DI=>);

Ingeteam Proprietary All Rights Reserved Pag. 296


1.8.1.5 CHARCURVE_REAL

1.8.1.5.1 Description

The CHARCURVE_REAL function interpolates an input value between the points defined in a
table.

The function searches in the abscissas for the point in the table that is immediately below or
above the function input value. It performs a linear interpolation with the values of the ordinates
for each of the points.

The interpolation is performed according to the following formula:

Y-Y0=(Y1 - Y0) (X - X0) / (X1 - X0)

Where:

X:Value of the function input used for the interpolation.

X0:Value OF X in the points table immediately below X.

X1:Value of X in the points table immediately above X.

Y0:Value of Y corresponding to the point in the table immediately below X.

Y1:Value of Y corresponding to the point in the table immediately above X.

1.8.1.5.2 Syntax

FUNCTION_BLOCK CHARCURVE_REAL

VAR_INPUT

In_R:REAL;

PointsNum_I:INT;

TablePoints_stCoordinate_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Out_R:REAL;

Status_BY:BYTE;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 297


1.8.1.5.3 Input parameters

Input Parameter Name Type Description


In_R REAL Input with the value of the X-axis for which the Y-axis is to be obtained.
PointsNum_I INT Number of points defining the characteristic curve (2 &lt;= N &lt;= 1000).
Pointer to the address of an array of structures of the stCoordinate type
TablePoints_stCoordinate_ADDR DWORD
which contains the X and Y points of the curve.
Tbl. 1.254 Input parameters of function CHARCURVE_REAL.

1.8.1.5.4 Output parameters

Output Parameter Name Type Description


Out_R REAL Calculated output value.
Function Status:
0 - Correct Execution
1 - Ordenation table No Valid
Status_BY BYTE
2 - Input No Valid
3- Address No Valid
4 - Number Points No Valid
Tbl. 1.255 Output parameters of function CHARCURVE_REAL.

1.8.1.5.5 Data Types

1.8.1.5.5.1 stCoordinate

Field Name Type Description


X_R REAL X-axis.
Y_R REAL Y-axis.
Tbl. 1.256 Fields of the stCoordinate structure.

1.8.1.5.6 Remarks

The CHARCURVE_REAL function is a continuous execution function. On each call to function a


calculation is performed using Equation 1 with the value of the In_R parameter and based on the
values entered in an array of structures that contains pairs of points on the curve on which the
interpolation is to take place.

The stCoordinate type structure array must follow an incremental order of the abscissa values.

If the input value is outside the limits of the table that has been entered, the function will assign
the Y value that corresponds to the lower or upper limit to the output, depending on whether the
input is under the lower limit or over the upper limit of X.

Fig. 1.19 .

Ingeteam Proprietary All Rights Reserved Pag. 298


1.8.1.5.7 Example

PROGRAM Example

VAR

(*function declaration*)

Interpolation: CHARCURVE_REAL;

(*input parameters*)

inputValue: REAL;

tablePointsNumber: INT := 5;

table : ARRAY [0..4] OF stCoordinate := (*X,Y values in the proper order*)

(X_R:=-10,Y_R:=1),

(X_R:=-5,Y_R:=2),

(X_R:=0,Y_R:=3),

(X_R:=5,Y_R:=4),

(X_R:=10,Y_R:=5);

(*Output Parameters*)

outputValue: REAL;

statusInterpolation: BYTE;

END_VAR

(*Get an interpolated point (inputValue,outputValue) *)

Interpolation( In_R:= inputValue,

PointsNum_I:= tablePointsNumber,

TablePoints_stCoordinate_ADDR:=ADR(table) );

outputValue:= Interpolation.Out_R;

statusInterpolation:= Interpolation.Status_BY;

Ingeteam Proprietary All Rights Reserved Pag. 299


1.8.1.6 CONFIGURE_COUNTER

1.8.1.6.1 Description

This function is used to configurate a Fast Counter

The CONFIGURE_COUNTER function allows the user to configure the fast counter modules.
This function is used both for configuring the generic counter module (IC3325) and the reduced
counter module (IC3391).

Depending on the type of counter module installed, different functionalities and features are
available. During the parametrisation with CONFIGURE_COUNTER the user must use the
correct structures for the counter type.

1.8.1.6.2 Syntax

FUNCTION_BLOCK CONFIGURE_COUNTER

VAR_INPUT

Enable_BL:BOOL;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterNum_DI:DINT;

CounterNum_stCounterConf_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enCounterRet:enCounterRet;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 300


1.8.1.6.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable / disable the execution of the function block.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
CounterNum_DI DINT Number of the counter to configure (0..5).
Pointer to the memory buffer where configuration structure is
stored.
CounterNum_stCounterConf_ADDR DWORD
For the IC3325 module use stGenericCounterConf.
For the IC3391 module use stReducedCounterConf.
Tbl. 1.257 Input parameters of function CONFIGURE_COUNTER.

1.8.1.6.4 Output parameters

Output Parameter Name Type Description


Returns TRUE when the execution is completed.
Done_BL BOOL
Check Status_enCounterRet for the result of the execution.
Status_enCounterRet enCounterRet Result of the FB execution.
Tbl. 1.258 Output parameters of function CONFIGURE_COUNTER.

1.8.1.6.5 Data Types

1.8.1.6.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.259 Enumerator enCounterType.

1.8.1.6.5.2 enIC3325InputSignal

Value Description
G0 (0) Gate 0
G1 (1) Gate 1
G2 (2) Gate 2
G3 (3) Gate 3
G4 (4) Gate 4
G5 (5) Gate 5
G6 (6) Gate 6
G7 (7) Gate 7
Tbl. 1.260 Enumerator enIC3325InputSignal.

Ingeteam Proprietary All Rights Reserved Pag. 301


1.8.1.6.5.3 stIC3325Period

Field Name Type Description


Counter number to use for the period
CounterNum_DI DINT
measuring.
Input Signal 1 (Conected to one of the Gates
InputSignal1_enIC3325InputSignal enIC3325InputSignal
(G0G7)).
Logic of the Input Signal 1 (TRUE--> Inverted
Signal1Inverted_BL BOOL
Logic, FALSE-->Direct Logic).
Tbl. 1.261 Fields of the stIC3325Period structure.

1.8.1.6.5.4 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.262 Enumerator enCounterRet.

1.8.1.6.5.5 stCounterPreset

Field Name Type Description


PresetValue_DI DINT Preset value.
Tbl. 1.263 Fields of the stCounterPreset structure.

Ingeteam Proprietary All Rights Reserved Pag. 302


1.8.1.6.5.6 stCounterSp

Field Name Type Description


SpValue_DI DINT Set Point value.
Conf_stSpConf stSpConf Structure with the configuration of the Set Point.
Tbl. 1.264 Fields of the stCounterSp structure.

1.8.1.6.5.7 stGateConf

Field Name Type Description


Indicates if input Gate is inverted. FALSE: The signal connected to the GATE is
Ig_BL BOOL
direct logic. TRUE: The signal connected to the GATE is invert logic.
Input Number (0..7-Generic Counter or 0..5-Reduced Counter). Generic
Reduced
0 Gate0 IN_0
1 Gate1 IN_1
2 Gate2 IN_2
InputNumberGate_BY BYTE
3 Gate3 IN_3
4 Gate4 IN_4
5 Gate5 IN_5
6 Gate6
7 Gate7.
CountertNumberToChain_BY BYTE Number of the counter to concatenate with the GATE 0..5).
Disarm_BL BOOL See Arm_BL.
These parameters determine the action of the GATE signal over the status of the
counter.
[ARM=0, DRM=0] The status doesnt change.
[ARM=1, DRM=0] Counter armed on GATE event.
[ARM=0, DRM=1] Counter disarmed on GATE event.
Arm_BL BOOL [ARM=1, DRM=1]
If configuring GATE0, the counter is armed while GATE0 is TRUE and disarmed
while GATE0 is FALSE.
IF configuring GATE1 and ARM and DRM bits are TRUE for GATE0, this
configuration has no efect because GATE0 has more priority.
If ARM and DRM bits are not both TRUE for GATE0, the counter is armed while
GATE1 is TRUE and disarmed while GATE1 is FALSE.
FALSE: The GATE trigger event is not registered in the flags register. TRUE The
ActivateFlag_BL BOOL
GATE trigger event is registered in the flags register in the input gate.
Number of the Preset to load the counter with:
IC3325: Number of the PRESET associated to the GATE event, among the 4
PresetNumber_BY BYTE
available (0..3)
IC3391: There is only 1 PRESET, so this value must be always 0.
To Preset or not when a rising edge occurs in the input gate:
FALSE: The PRESET value associated to the GATE will not be used
Preset_BL BOOL
TRUE: The PRESET value associated to the GATE will be loaded into the
counter when the GATE event occur.
Capture or not the value counter when a rising edge occurs in the input gate:
FALSE: The value of the counter wont be stored when the GATE event occur
Capture_BL BOOL
TRUE: The value of the counter is stored in stReducedCounter.HoldValue_DI
when the GATE event occur.
Chain this counter or not with other:
Chain_BL BOOL FALSE: The counter is not concatenated to other counter
TRUE: The counter is concatenated to other counter.
Tbl. 1.265 Fields of the stGateConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 303


1.8.1.6.5.8 stGenericCounter

Field Name Type Description


CounterValue_DI DINT Actual Counter Value.
StsFlags_stGenericSTSFlags stGenericSTSFlags STS and Flags.
Captured value of the counter (this value is captured when a certain
HoldValue_DI DINT
event occur).
If the counter is configured to measure velocity, this variable contains the
TimeValue100ns_UDI UDINT
time value, in 10e-7 seconds.
Tbl. 1.266 Fields of the stGenericCounter structure.

1.8.1.6.5.9 stGenericCounterCfg

Field Name Type Description


Input A inverted:
Ia_BL BOOL FALSE: Channel A (CHA) signal is direct logic (if input signal is low -> CHA is FALSE)
TRUE: Channel A (CHA) signal is inverse logic (if input signal is low -> CHA is TRUE).
Input B inverted:
Ib_BL BOOL FALSE: Channel B (CHB) signal is direct logic (if input signal is low -> CHB is FALSE)
TRUE: Channel B (CHB) signal is inverse logic (if input signal is low -> CHB is TRUE).
M0_BL BOOL Bit 0 Encoder Type. See F_BL.
M1_BL BOOL Bit 1 Encoder Type. See F_BL.
Configuration of how the counter counts.
Bits M0_BL, M1_BL, and F_BL determine the codification type of CHA and CHB signals
and how to understand them.
[F=0, M1=0, M0=0]
CHA and CHB are pulse signals with 90grad delay. The counter increases each time the
sequence CHA rising edge, CHB rising edge, CHA falling edge, CHB falling edge
completes. The counter decreases each time the sequence CHB rising edge, CHA rising
edge, CHB falling edge, CHA falling edge completes.
[F=0, M1=0, M0=1]
CHA is a pulsed input and CHB indicates up (CHB=TRUE) or down (CHB=FALSE)
counting direction. The counter increases on CHA rising edge if CHB=1, and decreases on
CHA rising edge if CHB=0.
[F=0, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on CHB rising edge and decreases
on CHA rising edge.
F_BL BOOL [F=X, M1=1, M0=1]
The pulses are generated in an internal clock which frequency is determined by bits E4 to
E0.
[F=1, M1=0, M0=0]
CHA and CHB are pulse signals with 90deg delay. The counter increases on CHA rising
edge if CHB=0, or on CHB rising edge if CHA=1, or on CHA falling edge if CHB=1, or on
CHB falling edge if CHA=0. The counter decreases on CHB rising edge if CHA=0, or on
CHA rising edge if CHB=1, or on CHB falling edge if CHA=1, or on CHA falling edge if
CHB=0.
[F=1, M1=0, M0=1]
CHA is a pulse signal and CHB indicates the direction of counting. The counter increases
on CHA rising or falling edge if CHB=1. The counter decreases on CHA rising or falling
edge if CHB=0.
[F=1, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on rising or falling edge of CHB,
and decreases on rising or falling edge of CHA.
Bit 0 Programmable divisor .
E0_BL BOOL When M1=1 and M0=1, the internal clock frequency is 10MHz/FD, where FD is (E4..E0 +
1). For example, if E4..E0 = 00000b (0d) => 10MHz, if E4..E0 = 00001b (1d) => 10/2MHz,
..., if E4..E0 = 11111b (31d) => 10/32MHz.
E1_BL BOOL Bit 1 Programmable divisor .
E2_BL BOOL Bit 2 Programmable divisor .
E3_BL BOOL Bit 3 Programmable divisor .
E4_BL BOOL Bit 4 Programmable divisor .

Ingeteam Proprietary All Rights Reserved Pag. 304


Field Name Type Description
Speed Mode.
V_BL BOOL FALSE: Counter NOT configured in velocity measure mode
TRUE: Counter configured in velocity measure mode.
Drm_BL BOOL Disarm Counter. See Arm_BL.
Arm Counter. Enables the CPU to control the status of the pulse counter:
[ARM=0, DRM=0]The status doesnt change.
[ARM=1, DRM=0] The counter is started.
Arm_BL BOOL
[ARM=0, DRM=1] The counter is stopped.
[ARM=1, DRM=1]
Inverts the status of the counter. It starts it if it was stopped, or stops it if it was started.
Tbl. 1.267 Fields of the stGenericCounterCfg structure.

1.8.1.6.5.10 stGenericCounterConf

Field Name Type Description


Conf_stGenericCounterConf stGenericCounterCfg Structure with the configuration of the Counter.
Gate0_stGateConf stGateConf Structure with the configuration of the Gate0.
Gate1_stGateConf stGateConf Structure with the configuration of the Gate1.
SP0_stCounterSp stCounterSp Structure with the configuration of the SP0.
SP1_stCounterSp stCounterSp Structure with the configuration of the SP1.
SP2_stCounterSp stCounterSp Structure with the configuration of the SP2.
SP3_stCounterSp stCounterSp Structure with the configuration of the SP3.
PR0_stCounterPreset stCounterPreset Structure with the configuration of the PR0.
PR1_stCounterPreset stCounterPreset Structure with the configuration of the PR1.
PR2_stCounterPreset stCounterPreset Structure with the configuration of the PR2.
PR3_stCounterPreset stCounterPreset Structure with the configuration of the PR3.
Tbl. 1.268 Fields of the stGenericCounterConf structure.

1.8.1.6.5.11 stGenericSTSFlags

Field Name Type Description


G0_BL BOOL G0's Input State.
G1_BL BOOL G1's Input State.
DIR_BL BOOL 0/1-Counter is increasing/decreasing.
RMD_BL BOOL State Arm Counter.
Reserve1_BL BOOL Reserved.
Reserve2_BL BOOL Reserved.
Reserve3_BL BOOL Reserved.
Reserve4_BL BOOL Reserved.
H0_BL BOOL Is set when a rising edge occurs in G0 if the flag ActivateFlag_BL of G0 configuration is set.
H1_BL BOOL Is set when a rising edge occurs in G1 if the flag ActivateFlag_BL of G1 configuration is set.
Is set when the Counter Value = SP0 values if the flag ActivateFlag_BL of SP0 configuration is
H2_BL BOOL
set.
Is set when the Counter Value = SP1 values if the flag ActivateFlag_BL of SP1 configuration is
H3_BL BOOL
set.
Is set when the Counter Value = SP2 values if the flag ActivateFlag_BL of SP2 configuration is
H4_BL BOOL
set.
Is set when the Counter Value = SP3 values if the flag ActivateFlag_BL of SP3 configuration is
H5_BL BOOL
set.
Reserve5_BL BOOL Reserved.
Reserve6_BL BOOL Reserved.
Tbl. 1.269 Fields of the stGenericSTSFlags structure.

Ingeteam Proprietary All Rights Reserved Pag. 305


1.8.1.6.5.12 stReducedCounterConf

Field Name Type Description


Conf_stReducedCounterConf stReducedCounterCfg Structure with the configuration of the Counter.
Gate0_stGateConf stGateConf Structure with the configuration of the Gate0.
Gate1_stGateConf stGateConf Structure with the configuration of the Gate1.
SP_stCounterSp stCounterSp Structure with the configuration of the SP.
PR_stCounterPreset stCounterPreset Structure with the configuration of the PR.
Tbl. 1.270 Fields of the stReducedCounterConf structure.

1.8.1.6.5.13 stSpConf

Field Name Type Description


FALSE: The counter does not change its armed/diarmed status when the SET-POINT value
Drm_BL BOOL is reached.
TRUE: The counter is disarmed when the value SpValue_DI is reached.
FALSE: The SET-POINT reach event is not stored in the flags register
ActivateFlag_BL BOOL
TRUE: The SET-POINT reach event is stored in the flags register.
IC3325: Number of the PRESET associated to the SET-POINT reach event, among the 4
PresetNumber_BY BYTE available
IC3391: There is only 1 PRESET available, so this parameter must be always 0.
FALSE: The PRESET value is not used
Preset_BL BOOL
TRUE: The PRESET value is loaded to the counter when the SET-POINT reach event occur.
Tbl. 1.271 Fields of the stSpConf structure.

1.8.1.6.6 Remarks

Tips for using CONFIGURE_COUNTER function block:

Identify the counter module type (generic or reduced) and use de appropiate structures

Set the counter configuration parameters

Set the GATEs configuration parameters accordingly to the module type

Set the configuration parameters of the SET-POINTs

Set the configuration parameters of the PRESETs

Once all the values of the parameters of configurationof the counter have been introduced, call
the instance of CONFIGURE_COUNTER function.

The function block indicates completion by the output parameter Done_BL. The result of the
configuration will be indicated in Status_enCounterRet.

1.8.1.6.7 Example

PROGRAM Example_Period

VAR

IC3325Period: PERIOD_COUNTER;

Ingeteam Proprietary All Rights Reserved Pag. 306


stIC3325PeriodConfiguration:stIC3325Period;

Output1:REAL;

Enable: BOOL;

END_VAR

(*Read Period with an IC3325 *)

(* IC3325 Input Signal definition*)

stIC3325PeriodConfiguration.CounterNum_DI:=0;

stIC3325PeriodConfiguration.InputSignal1_enIC3325InputSignal:=G0;

stIC3325PeriodConfiguration.Signal1Inverted_BL:= FALSE;

(*Get Period*)

IC3325Period(

Enable_BL:= Enable,

CounterType_enCounterType:=IC3325 ,

ChassisNum_DI:=0 ,

SlotNum_DI:= 1,

CounterConfigure_ADRR:=ADR(stIC3325PeriodConfiguration) ,

CounterConfigureSizeBy_DI:=SIZEOF(stIC3325PeriodConfiguration) ,

CounterOverflowUs_DI:=20000000 ,

Done_BL=> ,

PeriodUs_R=> ,

Status_enCounterRet=>

);

Output1:= IC3325Period.PeriodUs_R;

(*******************************************************)

(*Low level PERIOD_COUNTER Function Block*)

(*******************************************************)

FUNCTION_BLOCK PERIOD_COUNTER

(*Function to use the Generic counter (IC3325) for measuring the period of the signal on one
GATE*)

VAR_INPUT

Ingeteam Proprietary All Rights Reserved Pag. 307


(*Auxiliar delay counter variables*)

Enable_BL:BOOL;(* Flag to Enable the function *)

CounterType_enCounterType:enCounterType; (*Counter Type*)

(*CONFIGURATION Variables*)

(*Counter parametrs*)

ChassisNum_DI:DINT; (* Chassis Number*)

SlotNum_DI:DINT;(* Slot Number*)

(*Counter structures*)

CounterConfigure_ADRR:DWORD;

CounterConfigureSizeBy_DI:DINT;

(*Set Point Parameters*)

CounterOverflowUs_DI :REAL:=30000000;(*CounterOverflow in us*) (*By default wait 30


seconds before to show error message*)

END_VAR

VAR_OUTPUT

(*Auxiliar period counter variables*)

Done_BL:BOOL :=FALSE;(* Execution of the FB has finished*)

(*READ Variables*)

PeriodUs_R:REAL;(*Measured period in 1e-06s*)

Status_enCounterRet:enCounterRet;(* Result of the FB execution.*)

(*The data structure is in the Regulation_02.lib library*)

(*0 - Correct execution

1-Error nChassis-nSlot

2 Error nonexistent resource

3-Error nCounter

4 Error Gate0 Parameters

5-Error Gate1 Parameters

6-Error SP0 Parameters

7-Error SP1 Parameters

8-Error SP2 Parameters

Ingeteam Proprietary All Rights Reserved Pag. 308


9-Error SP3 Parameters

10- Error Internal

11- Counter Overflow *)

END_VAR

(*{library private}*)

VAR

(*CONFIGURATION Variables*)

CONFIGURATION: CONFIGURE_COUNTER; (*counter configuration function block*)

stIC3325PeriodConf:stIC3325Period;

Pointer_stIC3325PeriodConf:POINTER TO stIC3325Period;

stGenericCounterPeriod:stGenericCounterConf;

stGenericCounterConfiguration:stGenericCounterCfg;

stConfigurationGate0:stGateConf;

stPresetConfiguration:stCounterPreset;

stSPConfiguration:stCounterSp;

READ: READ_COUNTER;(*counter read function block*)

stGenericCounterRead:stGenericCounter;

HoldValue_DI:DINT;

(*AUXILIARY Variables*)

RiseEdgeDetection:RISING_TRIG;(*Function that detects rising edges of an input signal*)

Configuration_BL:BOOL;(* Auxiliary variable used during the configuration process of


counting. Remains TRUE as long as this work is being performed*)

iCounterIC3325:INT;

END_VAR

(* In the cycle in which there is a rising edge signal Enable_BL, there must be the configuration
of the counter *)

RiseEdgeDetection.In_BL:=Enable_BL;(*associate Enable_BL signal FB which is


responsible for detecting rising edges *)

RiseEdgeDetection(); (* FB call that performs the detection of rising edges *)

IF (RiseEdgeDetection.Out_BL) THEN(* This checks if there has been a rising edge signal
Enable_BL *)

Ingeteam Proprietary All Rights Reserved Pag. 309


Configuration_BL:=TRUE;(* Activate the auxiliary variable which allows the
configuration of the counter *)

END_IF;

CASE (CounterType_enCounterType) OF (* Depending on the type of accountant to use


the user configuration is carried out by structures or other *)

0: (*Generic Counter IC3325*)

IF (CounterConfigureSizeBy_DI=SIZEOF(stIC3325PeriodConf)) THEN (*This checks


whether the configuration structure that have passed to the function corresponds to the
type of accountant indicated, and if positive, a corresponding configuration *)

IF (Configuration_BL) THEN (* If the signal is true (there has been a rising edge
signal Enable_BL) proceed to the configuration of the counter *)

(* Since the input of the function is a pointer to a structure configuration, copy the
data associated with the structure of the pointer to a auxiliary structure of the same
type, to handle the same *)

Pointer_stIC3325PeriodConf:=CounterConfigure_ADRR;

stIC3325PeriodConf:=Pointer_stIC3325PeriodConf^;

(*Counter Generic parameters*)

stGenericCounterConfiguration.Arm_BL:=FALSE;(* Arm = FALSE and DRM =


TRUE, initialize the counter*)

stGenericCounterConfiguration.Drm_BL:=TRUE;

stGenericCounterConfiguration.M0_BL:= TRUE;(* Internal 10MHz Clock *) (* 0.1


us * Period*)

stGenericCounterConfiguration.M1_BL:= TRUE;(* M0 = 1 M1 = 1: The pulse input


to the counter clock frequency is a 10MHz/FD, where FD is the value of (E4..
E1)+1 *)

stGenericCounterConfiguration.E0_BL:=0;

stGenericCounterConfiguration.E1_BL:=0;

stGenericCounterConfiguration.E2_BL:=0;

stGenericCounterConfiguration.E3_BL:=0;

stGenericCounterConfiguration.E4_BL:=0;

stGenericCounterPeriod.Conf_stGenericCounterConf:=stGenericCounterConfigura
tion;

(*Gate0 parameters*)

Ingeteam Proprietary All Rights Reserved Pag. 310


stConfigurationGate0.Ig_BL:=stIC3325PeriodConf.Signal1Inverted_BL; (* Select
direct or reverse logic GATE0 *)

stConfigurationGate0.InputNumberGate_BY:=INT_TO_BYTE(stIC3325PeriodConf.
InputSignal1_enIC3325InputSignal);(* physical input that is associated with GATE0
(0 .. 7) *)

stConfigurationGate0.Arm_BL:=TRUE; (* Arm =1 and Disarm = 0: the state


assembly is controlled by counter GATE0 *)

stConfigurationGate0.Disarm_BL:=FALSE;

stConfigurationGate0.ActivateFlag_BL:=TRUE;

(* When the trigger event occurs of GATE0, then collect the flags in the
corresponding structure *)

stConfigurationGate0.PresetNumber_BY:=0;

stConfigurationGate0.Preset_BL:=TRUE;(*active use is associated with GATE0


PRESET *)

stConfigurationGate0.Capture_BL:=TRUE; (*The counter is writed in HoldValue_DI


when GATE0 is activated *)

stConfigurationGate0.Chain_BL:=FALSE;(*The counter is not locked to another


counter *)

stGenericCounterPeriod.Gate0_stGateConf:=stConfigurationGate0;

(*Set Point parameters*)

stSPConfiguration.SpValue_DI:=REAL_TO_DINT(CounterOverflowUs_DI/0.1);(*
Value of SET-POINT *) (* convert time pulses through the period of the internal
clock *)

stSPConfiguration.Conf_stSpConf.ActivateFlag_BL:=TRUE;(* The event that has


reached the setpoint is reflected in the flags *)

stSPConfiguration.Conf_stSpConf.Drm_BL:=FALSE;(*The counter maintains the


state arm / disarm when the set-point is reached*)

stSPConfiguration.Conf_stSpConf.Preset_BL:=TRUE;(*The value associated with


gate1 PRESET is loaded into the counter when the event occurs gate1*)

stSPConfiguration.Conf_stSpConf.PresetNumber_BY:=0;(*Aassociates the
PRESET 0 to gate1 *)

stGenericCounterPeriod.SP0_stCounterSp:=stSPConfiguration;(*Preset
parameters*)

stPresetConfiguration.PresetValue_DI:=1;(* preset value *)

Ingeteam Proprietary All Rights Reserved Pag. 311


stGenericCounterPeriod.PR0_stCounterPreset:=stPresetConfiguration;

CONFIGURATION.Enable_BL:=Configuration_BL;(* This function enables the


couter configuration *)

CONFIGURATION.ChassisNum_DI:=ChassisNum_DI;

CONFIGURATION.SlotNum_DI:=SlotNum_DI;

CONFIGURATION.CounterNum_DI:=stIC3325PeriodConf.CounterNum_DI;

CONFIGURATION.CounterNum_stCounterConf_ADDR:=
ADR(stGenericCounterPeriod);

CONFIGURATION();(*CALL the SETUP function*)

(*Output Values*)

Done_BL:= CONFIGURATION.Done_BL;(*Counter configuration Done*)

Status_enCounterRet:= CONFIGURATION.Status_enCounterRet;(* Configuration


output status*)

END_IF;

(* If the configuration of the accountant has been performed, and the signal Enable_BL of
function following high level, we proceed to the reading of the counter *)

(* NOTE: THE FIRST READING OF THE COUNTER IS AFTER A SETUP *)

IF(Done_BL AND NOT Configuration_BL AND Enable_BL) THEN


READ.Enable_BL:=Enable_BL;(*This function enables the reading*)

READ.CounterNum_DI:=stIC3325PeriodConf.CounterNum_DI;

READ.ChassisNum_DI:=ChassisNum_DI;

READ.SlotNum_DI:=SlotNum_DI;

READ.DeleteFlags_BL:=TRUE;

READ.Counter_stCounter_ADDR:=ADR(stGenericCounterRead);

iCounterIC3325 :=iCounterIC3325+1;

READ();(*CALL the READ function*)

(*Output Values*)

IF (stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL) THEN
Status_enCounterRet:=21;(*COUNTER OVERFLOW*)

ELSE Status_enCounterRet:= READ.Status_enCounterRet;(* read function output


status *)

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 312


(* This checks whether the reading is incorrect or has been an overflow (it has exceeded
the set point indicated or default) of the counter *)

IF((READ.Status_enCounterRet<>0)OR
(stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL)) THEN

(* H2_BL: Variable that is set to TRUE when the counter reaches the value of Set-
Point SP0 .*)

Done_BL:=TRUE;(* Do not update the output keeps the previous successful


reading *)

ELSE(* This verifies that there is a rising edge at the gate 0, the timer is running
and that the function of reading is completed *)

IF(stGenericCounterRead.StsFlags_stGenericSTSFlags.H0_BL AND
stGenericCounterRead.StsFlags_stGenericSTSFlags.RMD_BL AND
READ.Done_BL) THEN

(* H0: Variable that is set to TRUE when a rising edge in signal GATE0 *)

(* RDM: Indicates whether the pulse counter is stopped or running *)

Done_BL:=TRUE;

(*OutputValues*)

HoldValue_DI:=stGenericCounterRead.HoldValue_DI;(*conversion of the
read hold data to 1e-06s*)

PeriodUs_R:=(DINT_TO_REAL(HoldValue_DI))*0.1;(*Multiply the number


of pulses counted by the internal clock time in microseconds (in this case
0.1) in order to return the result in microseconds *)

ELSE

Done_BL:=FALSE;

END_IF;

END_IF;

END_IF;

(* We avoid the occurrence of the configuration and the first meter reading it in the same cycle *)

IF (CONFIGURATION.Done_BL) THEN

Configuration_BL:=FALSE;

END_IF;

ELSE (*If the structure passed to the function, does not match the expected size*)

Done_BL:=TRUE;(* Function worked fine *)

Ingeteam Proprietary All Rights Reserved Pag. 313


Status_enCounterRet:=12;(* Indicates that the configuration structure passed to the
function, does not match the selected counting*)

END_IF;

END_CASE;

1.8.1.7 COUNTER_DOWN

1.8.1.7.1 Description

The COUNTER_DOWN function performs a decrement operation on detecting edges in one of


its inputs. When the value to count down reaches 0, the function activates an indication flag.

1.8.1.7.2 Syntax

FUNCTION_BLOCK COUNTER_DOWN

VAR_INPUT

CounterDown_BL:BOOL;

Load_BL:BOOL;

StartValue_W:WORD;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

CounterValue_W:WORD;

END_VAR

1.8.1.7.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterDown_BL BOOL TRUE: On detection of the rising edge of the signal, the function decrements the
value of the CounterValue_W output variable by 1.
If TRUE The function loads the value of the StartValue_W variable in the internal
Load_BL BOOL
function count variable.
StartValue_W WORD A variable with the value to preload in the internal function count variable.
Tbl. 1.272 Input parameters of function COUNTER_DOWN.

Ingeteam Proprietary All Rights Reserved Pag. 314


1.8.1.7.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is greater than 0.
Out_BL BOOL
TRUE: The value of the CounterValue_W variable has reached 0.
CounterValue_W WORD Current value of the decremented variable.
Tbl. 1.273 Output parameters of function COUNTER_DOWN.

1.8.1.7.5 Remarks

When the Load_BL variable is TRUE, the CounterValue_W count variable initialises with the
value set in the StartValue_W input parameter. When the function detects a rising edge in the
CounterDown_BL input variable, the CounterValue_W variable decrements by 1 on each edge.
Once CounterValue_W has reached 0, the variable will not continue to count down to negative
values. When CounterValue_W=0, the function activates the flag and sets the Out_BL output to
TRUE.

Fig. 1.20 .

Ingeteam Proprietary All Rights Reserved Pag. 315


1.8.1.7.6 Example

PROGRAM Example

VAR

CounterDown : COUNTER_DOWN;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(*CounterDown:CTD*)(*Use a CounterDown*)CounterDown(Load_BL:=TRUE,
StartValue_W := 2) ;

2:CounterDown(Load_BL:=FALSE);

3:CounterDown(CounterDown_BL:=TRUE);(*CounterValue_W=1*)

4:CounterDown(CounterDown_BL:=FALSE);

5:CounterDown(CounterDown_BL:=TRUE);

6:CounterDown(CounterDown_BL:=FALSE);

7CounterDown(CounterDown_BL:=TRUE);(*---Out_BL=TRUECounterValue_W = 0 ---*)

8:CounterDown(CounterDown_BL:=FALSE);

END_CASE;

1.8.1.8 COUNTER_UP

1.8.1.8.1 Description

The COUNTER_UP function increments an output variable on detecting rising edges in one of its
inputs. The function returns an indication flag when the count variable exceeds the value defined
as the upper limit.

1.8.1.8.2 Syntax

FUNCTION_BLOCK COUNTER_UP

VAR_INPUT

CounterUp_BL:BOOL;

Reset_BL:BOOL;

CounterLimit_W:WORD;

Ingeteam Proprietary All Rights Reserved Pag. 316


END_VAR

VAR_OUTPUT

Out_BL:BOOL;

CounterValue_W:WORD;

END_VAR

1.8.1.8.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterUp_BL BOOL TRUE: On detection of the rising edge of the signal, the function increments the value
of the CounterValue_W output variable by 1.
Reset_BL BOOL If TRUE the function loads the value 0 in the internal function count variable.
CounterLimit_W WORD Variable with the value that the function is compared with.
Tbl. 1.274 Input parameters of function COUNTER_UP.

1.8.1.8.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is lower than the CounterLimit_W
upper limit.
Out_BL BOOL
TRUE: The value of the CounterValue_W variable has reached the CounterLimit_W
upper limit.
CounterValue_W WORD Current value of the incremented variable.
Tbl. 1.275 Output parameters of function COUNTER_UP.

Ingeteam Proprietary All Rights Reserved Pag. 317


1.8.1.8.5 Remarks

When the value of the Reset_BL variable is TRUE, the function sets the value of the
CounterValue_W count variable to 0. Each time there is a rising edge in the CounterUp_BL input
variable, the function will increment the CounterValue_W variable by 1. When the value of
CounterValue_W reached the limit set by the CounterLimit_W parameter, the function will
activate the Out_BL flag.

Fig. 1.21 .

Ingeteam Proprietary All Rights Reserved Pag. 318


1.8.1.8.6 Example

PROGRAM Example

VAR

CounterDown : COUNTER_DOWN;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(*CounterUp:COUNTER_UP*)(*Use a CounterUp*)

CounterUp( Reset_BL :=TRUE, CounterLimit_W := 2) ;

2:CounterUp( Reset_BL :=FALSE);

3:CounterUp( CounterUp_BL :=TRUE);(* CounterValue_W=1 *)

4:CounterUp( CounterUp_BL :=FALSE);

5:CounterUp( CounterUp_BL :=TRUE);

6:CounterUp( CounterUp_BL :=FALSE);

7:CounterUp( CounterUp_BL :=TRUE);(*------- Out_BL=TRUE CounterValue_W = 2 ---------*)

8:CounterUp( CounterUp_BL :=FALSE);

END_CASE;

1.8.1.9 COUNTER_UP_DOWN

1.8.1.9.1 Description

The COUNTER_UP_DOWN function is a combination of the COUNTER_DOWN function for the


decrement counter and the COUNTER_UP function for the increment counter.

The function performs a decrement operation on detecting edges in one of its inputs. When the
value to decrement reaches 0, the function activates an indication flag.

The function increments an output variable on detecting rising edges in one of its inputs. The
function returns an indication flag when the count variable exceeds the value defined as the
upper limit

Ingeteam Proprietary All Rights Reserved Pag. 319


1.8.1.9.2 Syntax

FUNCTION_BLOCK COUNTER_UP_DOWN

VAR_INPUT

CounterUp_BL:BOOL;

CounterDown_BL:BOOL;

Reset_BL:BOOL;

Load_BL:BOOL;

Value_W:WORD;

END_VAR

VAR_OUTPUT

OutUp_BL:BOOL;

OutDown_BL:BOOL;

CounterValue_W:WORD;

END_VAR

1.8.1.9.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is waiting to detect the rising edge.
CounterUp_BL BOOL TRUE: On detection of the rising edge of the signal, the function increments the
value of the CounterValue_W output variable by 1.
FALSE: The function is waiting to detect the leading edge.
CounterDown_BL BOOL TRUE: On detection of the rising edge of the signal, the function decrements the
value of the CounterValue_W output variable by 1.
Reset_BL BOOL If TRUE: the function loads the value 0 in the internal function count variable.
The function loads the value of the Value_W variable in the internal function
Load_BL BOOL
count variable.
Variable with the value to preload in the internal function count variable, which will
Value_W WORD
be taken as the upper limit.
Tbl. 1.276 Input parameters of function COUNTER_UP_DOWN.

1.8.1.9.4 Output parameters

Output Parameter Name Type Description


FALSE: The value of the CounterValue_W variable is lower than the
CounterLimit_W upper limit.
OutUp_BL BOOL
TRUE: The value of the CounterValue_W variable has reached the
CounterLimit_W upper limit.
FALSE: The value of the CounterValue_W variable is greater than 0.
OutDown_BL BOOL
TRUE: The value of the CounterValue_W variable has reached 0.
CounterValue_W WORD Current value of the count variable.
Tbl. 1.277 Output parameters of function COUNTER_UP_DOWN.

Ingeteam Proprietary All Rights Reserved Pag. 320


1.8.1.9.5 Remarks

The COUNTER_UP_DOWN function increments/decrements a count variable depending on the


rising edges that occur in its inputs.

When the Load_BL variable is TRUE, the CounterValue_W count variable is initialised with the
value set in the Value_W input parameter. When the function detects a rising edge in the
CounterDown_BL input variable, the CounterValue_W variable decrements by 1 on each edge.
Once CounterValue_W has reached 0, the variable will not continue to count down to negative
values. When CounterValue_W=0, the function activates the flag, setting the OutDown_BL
output to TRUE.

When the value of the Reset_BL variable is TRUE, the function sets the value of the
CounterValue_W count variable to 0. Each time there is a rising edge in the CounterUp_BL input
variable, the function will increment the CounterValue_W variable by 1. When the value of
CounterValue_W reached the limit set by the Value_W parameter, the function will activate the
OutUp_BL flag.

Ingeteam Proprietary All Rights Reserved Pag. 321


Fig. 1.22 .

1.8.1.9.6 Example

PROGRAM Example

VAR

(*COUNTER_UP_DOWN *)

CounterUpDown : COUNTER_UP_DOWN;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(* CounterUpDown : COUNTER_UP_DOWN *)(*Use a CounterUpDown*)CounterUpDown(


Load_BL :=TRUE, Value_W := 2);

2:CounterUpDown( Load_BL :=FALSE);

Ingeteam Proprietary All Rights Reserved Pag. 322


3:CounterUpDown( CounterDown_BL :=TRUE);

4:CounterUpDown( CounterDown_BL :=FALSE);

5:CounterUpDown( CounterDown_BL :=TRUE);(*------- OutDown_BL=TRUE CounterValue_W


= 0 ---------*)

6:CounterUpDown( CounterDown_BL :=FALSE);

7:CounterUpDown( CounterDown_BL :=TRUE);

8:CounterUpDown( CounterDown_BL :=FALSE);

9:CounterUpDown( Reset_BL :=TRUE, Value_W := 2) ;

10:CounterUpDown( Reset_BL :=FALSE);

11:CounterUpDown( CounterUp_BL :=TRUE);

12:CounterUpDown( CounterUp_BL :=FALSE);

13:CounterUpDown( CounterUp_BL :=TRUE);

14:CounterUpDown( CounterUp_BL :=FALSE);

15:CounterUpDown( CounterUp_BL :=TRUE); (*------- OutuUp_BL=FALSE CounterValue_W =


2 ---------*)

16:CounterUpDown( CounterUp_BL :=FALSE);

END_CASE;

1.8.1.10 FALLING_TRIG

1.8.1.10.1 Description

Falling Edge detection.

The FALLING_TRIG function detects falling edges in a BOOL type signal at the input.

1.8.1.10.2 Syntax

FUNCTION_BLOCK FALLING_TRIG

VAR_INPUT

In_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 323


END_VAR

1.8.1.10.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Function input variable for detecting the falling edge.
Tbl. 1.278 Input parameters of function FALLING_TRIG.

1.8.1.10.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the pulse in the falling edge.
Tbl. 1.279 Output parameters of function FALLING_TRIG.

1.8.1.10.5 Remarks

The F_TRIG function can detect falling edges in the In_BL input signal. This signal has to be a
BOOL type signal. When the function detects a falling edge, it produces a pulse in its Out_BL
output.

1.8.1.10.6 Example

PROGRAM Example

VAR

(*FALLING_TRIG*)

FallingEdgePulse :FALLING_TRIG;

OutputPulsesCounter:INT := 0;

nTest:INT :=0;

END_VAR

CASE nTest OF

1:(* FallingEdgePulse:F_TRIG *)

FallingEdgePulse( In_BL :=TRUE );

IF(FallingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

2:(*Detects falling edges in the In_BL input signal.*)

Ingeteam Proprietary All Rights Reserved Pag. 324


FallingEdgePulse( In_BL :=FALSE );

IF(FallingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.8.1.11 FILTER

1.8.1.11.1 Description

This function filters the input variable.

The FILTER function performs first order low pass filtering of the input signal with a user-defined
time constant.

The filtering is performed according to the following formula:

Yn=(t/(t+Tc))(Yn-1-Xn)+Xn

Where:

Xn: Value of the input signal of the current iteration.

Yn-1: Filtered output value from the previous iteration.

Yn: Filtered output value from the current iteration.

t: Filtering time or time constant parameter.

Tc: Task cycle time.

1.8.1.11.2 Syntax

FUNCTION_BLOCK FILTER

VAR_INPUT

Input_R:REAL;

FilterTimeMseg_R:REAL;

END_VAR

VAR_OUTPUT

Output_R:REAL;

Status_DI:DINT;

Ingeteam Proprietary All Rights Reserved Pag. 325


END_VAR

1.8.1.11.3 Input parameters

Input Parameter Name Type Description


Input_R REAL Input signal to be filtered.
Value in milliseconds of the filter time constant.
FilterTimeMseg_R REAL
This value corresponds to the time the output takes to reach 63% of the input.
Tbl. 1.280 Input parameters of function FILTER.

1.8.1.11.4 Output parameters

Output Parameter Name Type Description


Output_R REAL Output filtered signal.
Function Status:
Status_DI DINT 0 - Correct Execution
1 - FilterTimeMseg_R &lt; 0
Tbl. 1.281 Output parameters of function FILTER.

1.8.1.11.5 Remarks

The FILTER function filters the input signal according to the formula in Equation 2. The function
runs continuously and recalculates the value of the output based on the value of the input in that
cycle.

The function parameters are set with the FilterTimeMseg parameter. This value refers to the time
in milliseconds used to filter the input filter. The physical sense of this parameter refers to the
time it takes the output signal to reach 63% of the stepped type input. The following example
shows the function output for a unit step input with a value of 3ms and a cycle time of 1ms.

Fig. 1.23 .

If the value of the FilterTimeMseg parameter is 0, the output will instantly follow the input. In
other words, the filter of the input signal will be avoided.

1.8.1.11.6 Example

PROGRAM Example

VAR

FirstOrderLowPassFilter: FILTER;

Ingeteam Proprietary All Rights Reserved Pag. 326


(*input parameters*)

inputSignal: REAL;

THAU: REAL := 500.0;

(*output Parameters*)

outputSignal: REAL;

statusFilter: DINT;

(*signal generation*)

counter: INT;

THRESHOLD:INT:=1000;END_VAR

END_VAR

(*signal generation 1010101010101010*)

counter:=counter+1;

IF (counter>THRESHOLD) THEN

counter:=0;

END_IF;

InputSignal:=(counter *2) / THRESHOLD;

(*Filter Input signal*)

FirstOrderLowPassFilter( FilterTimeMseg_R:=THAU,Input_R:=inputSignal);

outputSignal:= FirstOrderLowPassFilter.Output_R;

statusFilter := FirstOrderLowPassFilter.Status_DI;

1.8.1.12 PULSE

1.8.1.12.1 Description

Pulse generation.

A high pulse is generated in the inputs rising edge, wich lasts the same length of time as the
scan cycle.

1.8.1.12.2 Syntax

FUNCTION_BLOCK PULSE

VAR_INPUT

Ingeteam Proprietary All Rights Reserved Pag. 327


Input_BL:BOOL;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_DI:DINT;

END_VAR

1.8.1.12.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL When this input is activated, the output pulse is generated.
Tbl. 1.282 Input parameters of function PULSE.

1.8.1.12.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output affected by the pulse.
Function Status:
Status_DI DINT
0 - Correct Execution
Tbl. 1.283 Output parameters of function PULSE.

Ingeteam Proprietary All Rights Reserved Pag. 328


1.8.1.12.5 Remarks

Fig. 1.24 .

1.8.1.12.6 Example

TYPE st_Pulse:

STRUCT

Input_BL:BOOL;

Output_BL:BOOL;

Status_DI:DWORD;

END_STRUCT

END_TYPE

FUNCTION_BLOCK Pulse_Fb

VAR_INPUT

Par_Pulse:st_Pulse;

Pulse:PULSE;

END_VAR

VAR

Output: BOOL;

END_VAR

Pulse(

Input_BL:=Par_Pulse.Input_BL,

Output_BL=>,

Status_DI=>);

Ingeteam Proprietary All Rights Reserved Pag. 329


1.8.1.13 READ_COUNTER

1.8.1.13.1 Description

Function is used to read a Fast Counter.

The READ_COUNTER function allows the user to read the value of a counter of an IC3325 or
IC3391 fast counter module.

1.8.1.13.2 Syntax

FUNCTION_BLOCK READ_COUNTER

VAR_INPUT

Enable_BL:BOOL;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterNum_DI:DINT;

DeleteFlags_BL:BOOL;

Counter_stCounter_ADDR:DWORD;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enCounterRet:enCounterRet;

END_VAR

1.8.1.13.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable / disable the execution of the function block.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
CounterNum_DI DINT Number of the counter to read (0..5).
FALSE: The flags are not deleted when reading the counter.
DeleteFlags_BL BOOL
TRUE: The flags are deleted when reading the counter.
Pointer to the memory buffer where the read value is stored.
The read data is stored in a structure.
Counter_stCounter_ADDR DWORD
The structure is stGenericCounter for an IC3325 module, and
stReducedCounter for an IC3391 module.
Tbl. 1.284 Input parameters of function READ_COUNTER.

Ingeteam Proprietary All Rights Reserved Pag. 330


1.8.1.13.4 Output parameters

Output Parameter Name Type Description


Returns TRUE when the execution is completed.
Done_BL BOOL
Check Status_enCounterRet for the result of the execution.
Status_enCounterRet enCounterRet Result of the FB execution.
Tbl. 1.285 Output parameters of function READ_COUNTER.

1.8.1.13.5 Data Types

1.8.1.13.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.286 Enumerator enCounterType.

1.8.1.13.5.2 enIC3325InputSignal

Value Description
G0 (0) Gate 0
G1 (1) Gate 1
G2 (2) Gate 2
G3 (3) Gate 3
G4 (4) Gate 4
G5 (5) Gate 5
G6 (6) Gate 6
G7 (7) Gate 7
Tbl. 1.287 Enumerator enIC3325InputSignal.

1.8.1.13.5.3 stIC3325Period

Field Name Type Description


CounterNum_DI DINT Counter number to use for the period measuring.
InputSignal1_enIC3325InputSignal enIC3325InputSignal Input Signal 1 (Conected to one of the Gates (G0G7)).
Logic of the Input Signal 1 (TRUE--> Inverted Logic, FALSE--
Signal1Inverted_BL BOOL
>Direct Logic).
Tbl. 1.288 Fields of the stIC3325Period structure.

Ingeteam Proprietary All Rights Reserved Pag. 331


1.8.1.13.5.4 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.289 Enumerator enCounterRet.

1.8.1.13.5.5 stCounterPreset

Field Name Type Description


PresetValue_DI DINT Preset value.
Tbl. 1.290 Fields of the stCounterPreset structure.

1.8.1.13.5.6 stCounterSp

Field Name Type Description


SpValue_DI DINT Set Point value.
Conf_stSpConf stSpConf Structure with the configuration of the Set Point.
Tbl. 1.291 Fields of the stCounterSp structure.

Ingeteam Proprietary All Rights Reserved Pag. 332


1.8.1.13.5.7 stGateConf

Field Name Type Description


Indicates if input Gate is inverted. FALSE: The signal connected to the GATE is
Ig_BL BOOL
direct logic. TRUE: The signal connected to the GATE is invert logic.
Input Number (0..7-Generic Counter or 0..5-Reduced Counter). Generic
Reduced
0 Gate0 IN_0
1 Gate1 IN_1
2 Gate2 IN_2
InputNumberGate_BY BYTE
3 Gate3 IN_3
4 Gate4 IN_4
5 Gate5 IN_5
6 Gate6
7 Gate7.
CountertNumberToChain_BY BYTE Number of the counter to concatenate with the GATE 0..5).
Disarm_BL BOOL See Arm_BL.
These parameters determine the action of the GATE signal over the status of the
counter.
[ARM=0, DRM=0] The status doesnt change.
[ARM=1, DRM=0] Counter armed on GATE event.
[ARM=0, DRM=1] Counter disarmed on GATE event.
Arm_BL BOOL [ARM=1, DRM=1]
If configuring GATE0, the counter is armed while GATE0 is TRUE and disarmed
while GATE0 is FALSE.
IF configuring GATE1 and ARM and DRM bits are TRUE for GATE0, this
configuration has no efect because GATE0 has more priority.
If ARM and DRM bits are not both TRUE for GATE0, the counter is armed while
GATE1 is TRUE and disarmed while GATE1 is FALSE.
FALSE: The GATE trigger event is not registered in the flags register. TRUE The
ActivateFlag_BL BOOL
GATE trigger event is registered in the flags register in the input gate.
Number of the Preset to load the counter with:
IC3325: Number of the PRESET associated to the GATE event, among the 4
PresetNumber_BY BYTE
available (0..3)
IC3391: There is only 1 PRESET, so this value must be always 0.
To Preset or not when a rising edge occurs in the input gate:
FALSE: The PRESET value associated to the GATE will not be used
Preset_BL BOOL
TRUE: The PRESET value associated to the GATE will be loaded into the counter
when the GATE event occur.
Capture or not the value counter when a rising edge occurs in the input gate:
FALSE: The value of the counter wont be stored when the GATE event occur
Capture_BL BOOL
TRUE: The value of the counter is stored in stReducedCounter.HoldValue_DI
when the GATE event occur.
Chain this counter or not with other:
Chain_BL BOOL FALSE: The counter is not concatenated to other counter
TRUE: The counter is concatenated to other counter.
Tbl. 1.292 Fields of the stGateConf structure.

1.8.1.13.5.8 stGenericCounter

Field Name Type Description


CounterValue_DI DINT Actual Counter Value.
StsFlags_stGenericSTSFlags stGenericSTSFlags STS and Flags.
Captured value of the counter (this value is captured when a certain
HoldValue_DI DINT
event occur).
If the counter is configured to measure velocity, this variable contains
TimeValue100ns_UDI UDINT
the time value, in 10e-7 seconds.
Tbl. 1.293 Fields of the stGenericCounter structure.

Ingeteam Proprietary All Rights Reserved Pag. 333


1.8.1.13.5.9 stGenericCounterCfg

Field Name Type Description


Input A inverted:
Ia_BL BOOL FALSE: Channel A (CHA) signal is direct logic (if input signal is low -> CHA is FALSE)
TRUE: Channel A (CHA) signal is inverse logic (if input signal is low -> CHA is TRUE).
Input B inverted:
Ib_BL BOOL FALSE: Channel B (CHB) signal is direct logic (if input signal is low -> CHB is FALSE)
TRUE: Channel B (CHB) signal is inverse logic (if input signal is low -> CHB is TRUE).
M0_BL BOOL Bit 0 Encoder Type. See F_BL.
M1_BL BOOL Bit 1 Encoder Type. See F_BL.
Configuration of how the counter counts.
Bits M0_BL, M1_BL, and F_BL determine the codification type of CHA and CHB signals and
how to understand them.
[F=0, M1=0, M0=0]
CHA and CHB are pulse signals with 90grad delay. The counter increases each time the
sequence CHA rising edge, CHB rising edge, CHA falling edge, CHB falling edge completes.
The counter decreases each time the sequence CHB rising edge, CHA rising edge, CHB
falling edge, CHA falling edge completes.
[F=0, M1=0, M0=1]
CHA is a pulsed input and CHB indicates up (CHB=TRUE) or down (CHB=FALSE) counting
direction. The counter increases on CHA rising edge if CHB=1, and decreases on CHA rising
edge if CHB=0.
[F=0, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on CHB rising edge and decreases
F_BL BOOL on CHA rising edge.
[F=X, M1=1, M0=1]
The pulses are generated in an internal clock which frequency is determined by bits E4 to E0.
[F=1, M1=0, M0=0]
CHA and CHB are pulse signals with 90deg delay. The counter increases on CHA rising edge
if CHB=0, or on CHB rising edge if CHA=1, or on CHA falling edge if CHB=1, or on CHB
falling edge if CHA=0. The counter decreases on CHB rising edge if CHA=0, or on CHA rising
edge if CHB=1, or on CHB falling edge if CHA=1, or on CHA falling edge if CHB=0.
[F=1, M1=0, M0=1]
CHA is a pulse signal and CHB indicates the direction of counting. The counter increases on
CHA rising or falling edge if CHB=1. The counter decreases on CHA rising or falling edge if
CHB=0.
[F=1, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on rising or falling edge of CHB, and
decreases on rising or falling edge of CHA.
Bit 0 Programmable divisor .
E0_BL BOOL When M1=1 and M0=1, the internal clock frequency is 10MHz/FD, where FD is (E4..E0 + 1).
For example, if E4..E0 = 00000b (0d) => 10MHz, if E4..E0 = 00001b (1d) => 10/2MHz, ..., if
E4..E0 = 11111b (31d) => 10/32MHz.
E1_BL BOOL Bit 1 Programmable divisor .
E2_BL BOOL Bit 2 Programmable divisor .
E3_BL BOOL Bit 3 Programmable divisor .
E4_BL BOOL Bit 4 Programmable divisor .
Speed Mode.
V_BL BOOL FALSE: Counter NOT configured in velocity measure mode
TRUE: Counter configured in velocity measure mode.
Drm_BL BOOL Disarm Counter. See Arm_BL.
Arm Counter. Enables the CPU to control the status of the pulse counter:
[ARM=0, DRM=0] The status doesnt change.
[ARM=1, DRM=0] The counter is started.
Arm_BL BOOL
[ARM=0, DRM=1] The counter is stopped.
[ARM=1, DRM=1]
Inverts the status of the counter. It starts it if it was stopped, or stops it if it was started.
Tbl. 1.294 Fields of the stGenericCounterCfg structure.

Ingeteam Proprietary All Rights Reserved Pag. 334


1.8.1.13.5.10 stGenericCounterConf

Field Name Type Description


Conf_stGenericCounterConf stGenericCounterCfg Structure with the configuration of the Counter.
Gate0_stGateConf stGateConf Structure with the configuration of the Gate0.
Gate1_stGateConf stGateConf Structure with the configuration of the Gate1.
SP0_stCounterSp stCounterSp Structure with the configuration of the SP0.
SP1_stCounterSp stCounterSp Structure with the configuration of the SP1.
SP2_stCounterSp stCounterSp Structure with the configuration of the SP2.
SP3_stCounterSp stCounterSp Structure with the configuration of the SP3.
PR0_stCounterPreset stCounterPreset Structure with the configuration of the PR0.
PR1_stCounterPreset stCounterPreset Structure with the configuration of the PR1.
PR2_stCounterPreset stCounterPreset Structure with the configuration of the PR2.
PR3_stCounterPreset stCounterPreset Structure with the configuration of the PR3.
Tbl. 1.295 Fields of the stGenericCounterConf structure.

1.8.1.13.5.11 stGenericSTSFlags

Field Name Type Description


G0_BL BOOL G0's Input State.
G1_BL BOOL G1's Input State.
DIR_BL BOOL 0/1-Counter is increasing/decreasing.
RMD_BL BOOL State Arm Counter.
Reserve1_BL BOOL Reserved.
Reserve2_BL BOOL Reserved.
Reserve3_BL BOOL Reserved.
Reserve4_BL BOOL Reserved.
Is set when a rising edge occurs in G0 if the flag ActivateFlag_BL
H0_BL BOOL
of G0 configuration is set.
Is set when a rising edge occurs in G1 if the flag ActivateFlag_BL
H1_BL BOOL
of G1 configuration is set.
Is set when the Counter Value = SP0 values if the flag
H2_BL BOOL
ActivateFlag_BL of SP0 configuration is set.
Is set when the Counter Value = SP1 values if the flag
H3_BL BOOL
ActivateFlag_BL of SP1 configuration is set.
Is set when the Counter Value = SP2 values if the flag
H4_BL BOOL
ActivateFlag_BL of SP2 configuration is set.
Is set when the Counter Value = SP3 values if the flag
H5_BL BOOL
ActivateFlag_BL of SP3 configuration is set.
Reserve5_BL BOOL Reserved.
Reserve6_BL BOOL Reserved.
Tbl. 1.296 Fields of the stGenericSTSFlags structure.

1.8.1.13.5.12 stReducedCounter

Field Name Type Description


CounterValue_DI DINT Actual Counter Value.
StsFlags_stReducedSTSFlags stReducedSTSFlags This structure contains the flags of the read counter.
Captured value of the counter (this value is captured when a
HoldValue_DI DINT
certain event occur).
If the counter is configured to measure velocity, this variable
TimeValue100ns_UDI UDINT
contains the time value, in 10e-7 seconds.
Tbl. 1.297 Fields of the stReducedCounter structure.

Ingeteam Proprietary All Rights Reserved Pag. 335


1.8.1.13.5.13 stSpConf

Field Name Type Description


FALSE: The counter does not change its armed/diarmed status when the SET-POINT value is
Drm_BL BOOL reached.
TRUE: The counter is disarmed when the value SpValue_DI is reached.
FALSE: The SET-POINT reach event is not stored in the flags register
ActivateFlag_BL BOOL
TRUE: The SET-POINT reach event is stored in the flags register.
IC3325: Number of the PRESET associated to the SET-POINT reach event, among the 4
PresetNumber_BY BYTE available
IC3391: There is only 1 PRESET available, so this parameter must be always 0.
FALSE: The PRESET value is not used
Preset_BL BOOL
TRUE: The PRESET value is loaded to the counter when the SET-POINT reach event occur.
Tbl. 1.298 Fields of the stSpConf structure.

1.8.1.13.6 Remarks

For the use of READ_COUNTER the user must use the correct structures depending of the type
of module (generic or reduced).

The function indicates completion with the output parameter Done_BL. When this occurs the
user can check Status_enCounterRet for the execution result. Note that the value of
Status_enCounterRet has a meaning only when Done_BL is TRUE.

1.8.1.13.7 Example

PROGRAM Example_Period

VAR

IC3325Period:PERIOD_COUNTER;

stIC3325PeriodConfiguration:stIC3325Period;

Output1:REAL;

Enable:BOOL;

END_VAR

(*Read Period with an IC3325 *)

(* IC3325 Input Signal definition*)

stIC3325PeriodConfiguration.CounterNum_DI:=0;

stIC3325PeriodConfiguration.InputSignal1_enIC3325InputSignal:=G0;

stIC3325PeriodConfiguration.Signal1Inverted_BL:= FALSE;

(*Get Period*)

IC3325Period(

Ingeteam Proprietary All Rights Reserved Pag. 336


Enable_BL:= Enable,

CounterType_enCounterType:=IC3325 ,

ChassisNum_DI:=0 ,

SlotNum_DI:= 1,

CounterConfigure_ADRR:=ADR(stIC3325PeriodConfiguration) ,

CounterConfigureSizeBy_DI:=SIZEOF(stIC3325PeriodConfiguration) ,

CounterOverflowUs_DI:=20000000 ,

Done_BL=> ,

PeriodUs_R=> ,

Status_enCounterRet=>

);

Output1:= IC3325Period.PeriodUs_R;

(*******************************************************)

(*Low level PERIOD_COUNTER Function Block*)

(*******************************************************)

FUNCTION_BLOCK PERIOD_COUNTER

(*Function to use the Generic counter (IC3325) for measuring the period of the signal on one
GATE*)

VAR_INPUT

(*Auxiliar delay counter variables*)

Enable_BL: BOOL;(* Flag to Enable the function*)

CounterType_enCounterType:enCounterType;(*Counter Type*)

(*CONFIGURATION Variables*)

(*Counter parametrs*)

ChassisNum_DI:DINT;(* Chassis Number*)

SlotNum_DI:DINT;(* Slot Number*)

(*Counter structures*)

CounterConfigure_ADRR:DWORD;

CounterConfigureSizeBy_DI:DINT;

(*Set Point Parameters*)

Ingeteam Proprietary All Rights Reserved Pag. 337


CounterOverflowUs_DI: REAL:=30000000;(*CounterOverflow in us*) (*By default wait 30
seconds before to show error message*)

END_VAR

VAR_OUTPUT

(*Auxiliar period counter variables*)

Done_BL:BOOL:=FALSE;(* Execution of the FB has finished*)

(*READ Variables*)

PeriodUs_R:REAL;(*Measured period in 1e-06s*)

Status_enCounterRet: enCounterRet;(* Result of the FB execution.*)

(*The data structure is in the Regulation_02 lib library*)

(*0-Correct execution

1-Error nChassis-nSlot

2-Error nonexistent resource

3-Error nCounter

4 Error Gate0 Parameters

5-Error Gate1 Parameters

6-Error SP0 Parameters

7-Error SP1 Parameters

8-Error SP2 Parameters

9-Error SP3 Parameters

10-Error Internal

11-Counter Overflow*)

END_VAR

(*{library private}*)

VAR

(*CONFIGURATION Variables*)

CONFIGURATION: CONFIGURE_COUNTER;(*counter configuration function block*)

stIC3325PeriodConf:stIC3325Period;

Pointer_stIC3325PeriodConf:POINTER TO stIC3325Period;

stGenericCounterPeriod:stGenericCounterConf;

Ingeteam Proprietary All Rights Reserved Pag. 338


stGenericCounterConfiguration:stGenericCounterCfg;

stConfigurationGate0:stGateConf;

stPresetConfiguration:stCounterPreset;

stSPConfiguration:stCounterSp;

READ: READ_COUNTER;(*counter read function block*)

stGenericCounterRead: stGenericCounter;

HoldValue_DI: DINT;

(*AUXILIARY Variables*)

RiseEdgeDetection:RISING_TRIG;(* Function that detects rising edges of an input signal*)

Configuration_BL: BOOL;(* Auxiliary variable used during the configuration process of


counting. Remains TRUE as long as this work is being performed*)

iCounterIC3325:INT;

END_VAR

(* In the cycle in which there is a rising edge signal Enable_BL, there must be the configuration
of the counter *)

RiseEdgeDetection.In_BL:=Enable_BL;(* associate Enable_BL signal FB which is responsible


for detecting rising edges *)

RiseEdgeDetection();(* FB call that performs the detection of rising edges *)

IF (RiseEdgeDetection.Out_BL) THEN (* This checks if there has been a rising edge signal
Enable_BL *)

Configuration_BL:=TRUE;(* Activate the auxiliary variable which allows the configuration of


the counter *)

END_IF;

CASE (CounterType_enCounterType) OF(* Depending on the type of accountant to use the user
configuration is carried out by structures or other *)

0: (*Generic Counter IC3325*)

IF (CounterConfigureSizeBy_DI=SIZEOF(stIC3325PeriodConf)) THEN (*This checks


whether the configuration structure that have passed to the function corresponds to the type of
accountant indicated, and if positive, a corresponding configuration *)

IF (Configuration_BL) THEN

(* If the signal is true (there has been a rising edge signal Enable_BL) proceed to
the configuration of the counter *)

Ingeteam Proprietary All Rights Reserved Pag. 339


(* Since the input of the function is a pointer to a structure configuration, copy the
data associated with the structure of the pointer to a auxiliary structure of the same
type, to handle the same *)

Pointer_stIC3325PeriodConf:=CounterConfigure_ADRR;

stIC3325PeriodConf:=Pointer_stIC3325PeriodConf^;

(*Counter Generic parameters*)

stGenericCounterConfiguration.Arm_BL:=FALSE;(* Arm = FALSE


and DRM = TRUE, initialize the counter*)

stGenericCounterConfiguration.Drm_BL:=TRUE;

stGenericCounterConfiguration.M0_BL:= TRUE;(* Internal 10MHz


Clock *) (* 0.1 us * Period*)

stGenericCounterConfiguration.M1_BL:= TRUE;(* M0 = 1 M1 = 1:
The pulse input to the counter clock frequency is a 10MHz/FD,
where FD is the value of (E4.. E1)+1 *)

stGenericCounterConfiguration.E0_BL:=0;

stGenericCounterConfiguration.E1_BL:=0;

stGenericCounterConfiguration.E2_BL:=0;

stGenericCounterConfiguration.E3_BL:=0;

stGenericCounterConfiguration.E4_BL:=0;

stGenericCounterPeriod.Conf_stGenericCounterConf:=
stGenericCounterConfiguration;

(*Gate0 parameters*)

stConfigurationGate0.Ig_BL:=stIC3325PeriodConf.Signal1Inverted
_BL;(* Select direct or reverse logic GATE0 *)

stConfigurationGate0.InputNumberGate_BY:=INT_TO_BYTE(stIC
3325PeriodConf.InputSignal1_enIC3325InputSignal);(*physical
input that is associated with GATE0 (0 .. 7)*)

stConfigurationGate0.Arm_BL:=TRUE;(* Arm =1 and Disarm = 0:


the state assembly is controlled by counter GATE0 *)

stConfigurationGate0.Disarm_BL:=FALSE;

stConfigurationGate0.ActivateFlag_BL:=TRUE;(*When the trigger


event occurs of GATE0, then collect the flags in the corresponding
structure *)

Ingeteam Proprietary All Rights Reserved Pag. 340


stConfigurationGate0.PresetNumber_BY:=0;

stConfigurationGate0.Preset_BL:=TRUE;(* active use is


associated with GATE0 PRESET *)

stConfigurationGate0.Capture_BL:=TRUE;(* El valor del contador


se guarda en HoldValue_DI al activarse el GATE0 *)

stConfigurationGate0.Chain_BL:=FALSE;(*The counter is not


locked to another counter *)
stGenericCounterPeriod.Gate0_stGateConf:=stConfigurationGate0
;

(*Set Point parameters*)

stSPConfiguration.SpValue_DI:=REAL_TO_DINT(CounterOverflo
wUs_DI/0.1); (* Value of SET-POINT *) (* convert time pulses
through the period of the internal clock *)

stSPConfiguration.Conf_stSpConf.ActivateFlag_BL:=TRUE;(* The
event that has reached the setpoint is reflected in the flags *)

stSPConfiguration.Conf_stSpConf.Drm_BL:=FALSE;(* The
counter maintains the state arm / disarm when the set-point is
reached*)

stSPConfiguration.Conf_stSpConf.Preset_BL:=TRUE;(* The value


associated with gate1 PRESET is loaded into the counter when the
event occurs gate1 *)

stSPConfiguration.Conf_stSpConf.PresetNumber_BY:=0;(*
Aassociates the PRESET 0 to gate1 *)

stGenericCounterPeriod.SP0_stCounterSp:=stSPConfiguration;

(*Preset parameters*)

stPresetConfiguration.PresetValue_DI:=1;(* preset value *)


stGenericCounterPeriod.PR0_stCounterPreset:=

stPresetConfiguration;

CONFIGURATION.Enable_BL:=Configuration_BL;(* This function


enables the couter configuration *)

CONFIGURATION.ChassisNum_DI:=ChassisNum_DI;

CONFIGURATION.SlotNum_DI:=SlotNum_DI;

CONFIGURATION.CounterNum_DI:=

stIC3325PeriodConf.CounterNum_DI;

Ingeteam Proprietary All Rights Reserved Pag. 341


CONFIGURATION.CounterNum_stCounterConf_ADDR:=

ADR(stGenericCounterPeriod);

CONFIGURATION();(*CALL the SETUP function*)

(*Output Values*)

Done_BL:= CONFIGURATION.Done_BL;(* Counter configuration


Done*)

Status_enCounterRet:=

CONFIGURATION.Status_enCounterRet;(* Configuration
output status*)

END_IF;

(* If the configuration of the accountant has been performed, and the signal
Enable_BL of function following high level, we proceed to the reading of the
counter *)

(* NOTE: THE FIRST READING OF THE COUNTER IS AFTER A SETUP *)

IF(Done_BL AND NOT Configuration_BL AND Enable_BL) THEN

READ.Enable_BL:=Enable_BL;(*This function enables the


reading*)

READ.CounterNum_DI:=stIC3325PeriodConf.CounterNum_DI;

READ.ChassisNum_DI:=ChassisNum_DI;

READ.SlotNum_DI:=SlotNum_DI;

READ.DeleteFlags_BL:=TRUE;

READ.Counter_stCounter_ADDR:=ADR(stGenericCounterRead);

iCounterIC3325 :=iCounterIC3325+1;

READ();(*CALL the READ function*)

(*Output Values*)

IF (stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL)

THEN

Status_enCounterRet:=21;(*COUNTER OVERFLOW*)

ELSE

Status_enCounterRet:= READ.Status_enCounterRet;(*
read function output status *)

END_IF;

Ingeteam Proprietary All Rights Reserved Pag. 342


(* This checks whether the reading is incorrect or has been an
overflow (it has exceeded the set point indicated or default) of the
counter *)

IF((READ.Status_enCounterRet<>0) OR
(stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL))
THEN

(* H2_BL: Variable that is set to TRUE when the counter reaches


the value of Set-Point SP0 .*)

Done_BL:=TRUE;(* Do not update the output keeps the


previous successful reading *)

ELSE

(* This verifies that there is a rising edge at the gate 0, the


timer is running and that the function of reading is
completed *)

IF
(stGenericCounterRead.StsFlags_stGenericSTSFlags.H0_
BL AND
stGenericCounterRead.StsFlags_stGenericSTSFlags.RM
D_BL AND READ.Done_BL) THEN

(* H0: Variable that is set to TRUE when a rising edge in


signal GATE0 *)

(* RDM: Indicates whether the pulse counter is stopped or


running *)

Done_BL:=TRUE;

(*Output Values*)

HoldValue_DI:=

stGenericCounterRead.HoldValue_DI;

(*conversion of the read hold data to 1e-06s*)


PeriodUs_R:=

(DINT_TO_REAL(HoldValue_DI))*0.1;(*
Multiply the number of pulses counted by the
internal clock time in microseconds (in this case
0.1) in order to return the result in microseconds *)

ELSE

Done_BL:=FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 343


END_IF;

END_IF;

END_IF;

(* We avoid the occurrence of the configuration and the first meter reading
it in the same cycle *)

IF (CONFIGURATION.Done_BL) THEN

Configuration_BL:=FALSE;

END_IF;

ELSE (*If the structure passed to the function, does not match the expected
size*)

Done_BL:=TRUE;(* Function worked fine *)

Status_enCounterRet:=12;(* Indicates that the configuration structure


passed to the function, does not match the selected counting*)

END_IF;

END_CASE;

1.8.1.14 REARM_PULSE

1.8.1.14.1 Description

When the input is activated, there is a pulse lasting a programmable length of time.

1.8.1.14.2 Syntax

FUNCTION_BLOCK REARM_PULSE

VAR_INPUT

Input_BL:BOOL;

TimeON_T:TIME;

Rearm_BL:BOOL;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_DI:DINT;

Ingeteam Proprietary All Rights Reserved Pag. 344


END_VAR

1.8.1.14.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL When this input is activated, the output pulse is generated.
TimeON_T TIME Duration of pulse ON. Only task time is taken into account.
Rearm_BL BOOL If this input is set to 1, the pulses time will be rearmed.
Tbl. 1.299 Input parameters of function REARM_PULSE.

1.8.1.14.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output with delayed activation and delayed deactivation.
Function Status:
0 - Correct Execution
Status_DI DINT
1 - Warning: TimeON_T &lt; Cycle_TIME
3 - Internal Error
Tbl. 1.300 Output parameters of function REARM_PULSE.

1.8.1.14.5 Remarks

When the input is activated, there is a pulse lasting a programmable length of time. Optionally,
the counter can be rearmed if a rising edge occurs in the input before the pulse has finished.

Fig. 1.25 .

1.8.1.14.6 Example

TYPE st_PulsoRearme:

STRUCT

Entrada_BL: BOOL;

TimeON_T: TIME;

Rearme_BL: BOOL;

Salida_BL: BOOL;

Status_DI: DWORD;

END_STRUCT

Ingeteam Proprietary All Rights Reserved Pag. 345


END_TYPE

FUNCTION_BLOCK PulsoRearme_Fb

VAR_INPUT

Par_PulsoRearme:st_PulsoRearme;

PulsoRearme:REARM_PULSE;

END_VAR

VAR

Salida: BOOL;

END_VAR

Par_PulsoRearme.TempDesconexion_T:= T#5000ms;

PulsoRearme(

TimeON_T:=Par_PulsoRearme.TimeON_T,

Input_BL:=Par_PulsoRearme.Entrada_BL,

Output_BL=>,

Status_DI=>);

1.8.1.15 RISING_TRIG

1.8.1.15.1 Description

Rising Edge detection.

The RISING_TRIG function detects rising edges in a BOOL type signal at the input.

1.8.1.15.2 Syntax

FUNCTION_BLOCK RISING_TRIG

VAR_INPUT

In_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 346


1.8.1.15.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Function input variable for detection of the rising edge.
Tbl. 1.301 Input parameters of function RISING_TRIG.

1.8.1.15.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the pulse in the rising edge.
Tbl. 1.302 Output parameters of function RISING_TRIG.

1.8.1.15.5 Remarks

The RISING_TRIG function can detect rising edges in the In_BL input signal. This signal has to
be a BOOL type signal. When the function detects a rising edge, it produces a pulse in its
Out_BL output.

Fig. 1.26 .

1.8.1.15.6 Example

PROGRAM Example

VAR

(*RISING_TRIG*)

RisingEdgePulse:RISING_TRIG;

OutputPulsesCounter:INT:=0;

nTest:INT:=0;

END_VAR

CASE nTest OF

1:(*RisingEdgePulse:R_TRIG*)

RisingEdgePulse(In_BL:=FALSE);

Ingeteam Proprietary All Rights Reserved Pag. 347


IF(RisingEdgePulse Out_BL)

THEN

OutputPulsesCounter:=OutputPulsesCounter+1;

END_IF;

2:(*Detects rising edges in the In_BL input signal*)

RisingEdgePulse(In_BL:=TRUE);

IF(RisingEdgePulse.Out_BL)

THEN

OutputPulsesCounter := OutputPulsesCounter+1;

END_IF;

END_CASE;

1.8.1.16 RTC_TIMER

1.8.1.16.1 Description

Real Time Counter Timer.

The RTC_TIMER function returns the date and time that have elapsed since a given moment.
The user can start the clock at a specific date and time and the function will return the current
date and time at each call.

1.8.1.16.2 Syntax

FUNCTION_BLOCK RTC_TIMER

VAR_INPUT

Enable_BL:BOOL;

Start_DT:DT;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Current_DT:DT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 348


1.8.1.16.3 Input parameters

Input Parameter Name Type Description


FALSE: The function is disabled waiting to detect the rising edge.
The Current_DT output will be DT#1970-01-01-00:00:00.
Enable_BL BOOL
TRUE: When the rising edge occurs, it loads the value of Start_DT in Current_DT.
While it remains at TRUE, the function increases the time counter.
Date and time that will be loaded in the Current_DT output variable when a rising edge
Start_DT DT
occurs in the Enable_BL input.
Fig. 1.27 Input parameters of function RTC_TIMER.

1.8.1.16.4 Output parameters

Output Parameter Name Type Description


FALSE: The function is not enabled since the input parameter Enable_BL:=FALSE.
Out_BL BOOL
TRUE The function is enabled and counting the elapsed time.
Current_DT DT Date and time of output calculated by the RTC_TIMER function.
Tbl. 1.303 Output parameters of function RTC_TIMER.

1.8.1.16.5 Remarks

To understand the operation of the RTC_TIMER function, three situations that will produce
different outputs should be considered:

While the input variable Enable_BL:=FALSE, the function will be disabled and therefore will not
increment the time. In this situation, the output Out_BL:=FALSE and the date and time delivered
in Current_DT:=01-01-1970-00:00:00.

When a rising edge occurs in the Enable_BL input, the function sets Out_BL:=TRUE and loads
the value of Start_DT in the Current_DT variable.

While the input variable Enable_BL:=TRUE, the function will be enabled and will therefore
increment the value of the output date and time of the Current_DT variable.

1.8.1.16.6 Example

PROGRAM Example

VAR

RunTimeCounter : RTC_TIMER;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(*RunTimeCounter:RTC_TIMER*)

(* Use a RunTimeCounter*)

Ingeteam Proprietary All Rights Reserved Pag. 349


RunTimeCounter(Enable_BL:=FALSE);

(*RunTimeCounter.Out_BL = FALSE*)

2:RunTimeCounter(Enable_BL:=TRUE,Start_DT:=DT#2010-07-14-15:36:30);

(*RunTimeCounter.Out_BL=TRUE*)

(*RunTimeCounter.Current_DT = actual value*)

3:RunTimeCounter( Enable_BL :=FALSE) ;

(*RunTimeCounter.Current_DT = DT#1970-01-01-00:00:00 *)

END_CASE;

1.8.1.17 SP_GEN_REG_EMF_V

1.8.1.17.1 Description

Function that elaborates a Regulator with a PI algorithm.

1.8.1.17.2 Syntax

FUNCTION_BLOCK SP_GEN_REG_EMF_V

VAR_INPUT

NegIntensityfRequest_BL:BOOL;

IntensitySwitchRequest_BL:BOOL;

MinExcIntensityRequest_BL:BOOL;

OnlyProportional_BL:BOOL;

KpEmf_R:REAL;

TnEmf_R:REAL;

AvEmfFilterTime_R:REAL;

SpEmf_R:REAL;

AvEmf_R:REAL;

EmfLowerLimit_R:REAL;

EmfUpperLimit_R:REAL;

NomExcIntensity_R:REAL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 350


VAR_OUTPUT

FluxWeakeningMode_BL:BOOL;

YpEmf_R:REAL;

YiEmf_R:REAL;

SpExcIntensity_R:REAL;

Status_DI:DINT;

END_VAR

1.8.1.17.3 Input parameters

Input Parameter Name Type Description


Negative Intensity Request If TRUE
NegIntensityfRequest_BL BOOL
if (SpExcIntensity_R>0) SpExcIntensity_R = -SpExcIntensity_R.
IntensitySwitchRequest. If TRUE.
IntensitySwitchRequest_BL BOOL
No_PI and goto check NegIntensityfRequest_BL.
Minimun Excitation Intensity Request. If TRUE.
MinExcIntensityRequest_BL BOOL SpExcIntensity_R = EmfLowerLimit_R.
YiEmf_R = EmfLowerLimit_R. YpEmf_R = 0.
OnlyProportional_BL BOOL If TRUE Only Yp.
KpEmf_R REAL Kp value.
TnEmf_R REAL Tn value in msg.
AvEmfFilterTime_R REAL FilterTime in msg.
SpEmf_R REAL Set Point.
AvEmf_R REAL Actual Value.
EmfLowerLimit_R REAL LowerLimit.
EmfUpperLimit_R REAL UpperLimit.
NomExcIntensity_R REAL Nominal Excitation Intensity.
Tbl. 1.304 Input parameters of function SP_GEN_REG_EMF_V.

1.8.1.17.4 Output parameters

Output Parameter Name Type Description


FluxWeakeningMode_BL BOOL TRUE - if (SpExcIntensity_R&lt; NomExcIntensity_R
YpEmf_R REAL YpEmf_R = (SpEmf_R-SpEmf_R)*KpEmf_R
YiEmf_R REAL YiEmf_R = @YiEmf_R+YpEmf_R*CycleTime/TnEmf_R
SpExcIntensity_R REAL SpExcIntensity_R = YpEmf_R + YiEmf_R
Function Status:
Status_DI DINT
0 - Correct Execution
Tbl. 1.305 Output parameters of function SP_GEN_REG_EMF_V.

Ingeteam Proprietary All Rights Reserved Pag. 351


1.8.1.18 SPEED_REGULATOR

1.8.1.18.1 Description

Function to elaborate a Speed Regulator with a PID algorithm.

1.8.1.18.2 Syntax

FUNCTION_BLOCK SPEED_REGULATOR

VAR_INPUT

RegulationEnable_BL:BOOL;

NoPID_BL:BOOL;

NoI_BL:BOOL;

Derivative_BL:BOOL;

Service4Q_BL:BOOL;

MII1QServiceI_BL:BOOL;

Kp_R:REAL;

Tn_R:REAL;

Tv_R:REAL;

Sp_R:REAL;

Av_R:REAL;

ErrorThreshold_R:REAL;

ErrorPermanenceTime_DI:DINT;

Ybias_R:REAL;

InitialYi_R:REAL;

MIService_R:REAL;

MIIService_R:REAL;

MIThermalLimit_R:REAL;

MIIThermalLimit_R:REAL;

MIMechanicalLimit_R:REAL;

MIIMechanicalLimit_R:REAL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 352


VAR_OUTPUT

Sp0_BL:BOOL;

Av0_BL:BOOL;

Xw_R:REAL;

Error_BL:BOOL;

EffLimMI_R:REAL;

EffLimMII_R:REAL;

Yp_R:REAL;

Yi_R:REAL;

Yd_R:REAL;

Y_R:REAL;

MISat_BL:BOOL;

MIISat_BL:BOOL;

Status_DI:DINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 353


1.8.1.18.3 Input parameters

Input Parameter Name Type Description


RegulationEnable_BL BOOL Regulation Permission.
0-PID Regulation
NoPID_BL BOOL
1-NO PID Regulation.
0-I Regulation
NoI_BL BOOL
1- No I Regulation.
0- No D Regulation
Derivative_BL BOOL
1- D Regulation.
0- No 4 Quadrant Service
Service4Q_BL BOOL
1-4 Quadrant Service.
0- No MII 1 Quadrant Service
MII1QServiceI_BL BOOL
1-MII 1 Quadrant Service.
Kp_R REAL Kp value.
Tn_R REAL Tn value in msg.
Tv_R REAL Tv value in csg.
Sp_R REAL Set Point.
Av_R REAL Actual Value.
ErrorThreshold_R REAL Threshold of the Error.
ErrorPermanenceTime_DI DINT PermanenceTime of the Error in msg.
Ybias_R REAL Ybias.
InitialYi_R REAL Yi Initial.
MIService_R REAL MI Service.
MIIService_R REAL MII Service.
MIThermalLimit_R REAL MI Thermal Limit.
MIIThermalLimit_R REAL MII Thermal Limit.
MIMechanicalLimit_R REAL MI Mechanical Limit.
MIIMechanicalLimit_R REAL MII Mechanical Limit.
Tbl. 1.306 Input parameters of function SPEED_REGULATOR.

1.8.1.18.4 Output parameters

Output Parameter Name Type Description


Sp0_BL BOOL TRUE - if Sp = 0
Av0_BL BOOL TRUE - if Av = 0
Xw_R REAL Sp_R - Av_R
Error_BL BOOL TRUE - if /Xw_R/ > ErrorThreshold_R for ErrorPermanenceTime_DI
EffLimMI_R REAL Effective Limit MI =min(MIService_R,MIMechanicalLimit_R,MIThermalLimit_R)
EffLimMII_R REAL Effective Limit MII =Max(MIIService_R,MIIMechanicalLimit_R,MIIThermalLimit_R)
Yp_R REAL Yp_R =Xw_R*Kp_R
Yi_R REAL Yi_R = @Yi + Yp_R*CycleTime/Tn_R
Yd_R REAL Yd_R = (Yp_R-@Yp_R)*Tv_R/CycleTime
Y_R REAL Y = Yp_R + Yi_R + Yd_R + Ybias_R
MISat_BL BOOL MI SaturatedTRUE - if Y_R = EffLimMI_R
MIISat_BL BOOL MII SaturatedTRUE - if Y_R = EffLimMII_R
Function Status
Status_DI DINT
0 - Correct Execution
Tbl. 1.307 Output parameters of function SPEED_REGULATOR.

Ingeteam Proprietary All Rights Reserved Pag. 354


1.8.1.19 TIMER_PULSE

1.8.1.19.1 Description

Timer Pulse.

The TIMER_PULSE function generates a pulse lasting for a certain duration on detecting an
input which generates a rising edge.

1.8.1.19.2 Syntax

FUNCTION_BLOCK TIMER_PULSE

VAR_INPUT

In_BL:BOOL;

Length_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.8.1.19.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Input variable to the function to detect the rising edge and begin timing.
Length_T TIME Period of time to maintain the output pulse at TRUE.
Tbl. 1.308 Input parameters of function TIMER_PULSE.

1.8.1.19.4 Output parameters

Output Parameter Name Type Description


The output variable that is a result of maintaining the value established in Length_T at
Out_BL BOOL
TRUE.
Elapsed_T TIME Time elapsed from when timing started.
Tbl. 1.309 Output parameters of function TIMER_PULSE.

Ingeteam Proprietary All Rights Reserved Pag. 355


1.8.1.19.5 Remarks

The use of the TIMER_PULSE function is similar to that of timing.

A BOOL TYPE variable must be assigned TO the In_BL input. When a rising edge occurs in this
variable, the FUNCTION sets the Out_BL output TO TRUE AND begins counting the TIME
(output variable Elapsed_T). As soon as this TIME (Current_T) matches the TIME set in the
Length_T input parameter, the FUNCTION will set the Out_BL output variable TO FALSE.

If the In_BL input is not set to TRUE for a time equal to Length_T, the function will maintain the
Out_BL output to TRUE until the time has elapsed. If during this time span when In_BL:=FALSE
and Out_BL:=TRUE another rising edge occurs in the In_BL input, then the function will not take
it into consideration and will continue with the original timing.

1.8.1.19.6 Example

PROGRAM Example

VAR

(*TIMER_PULSE*)

TimerPulse : TIMER_PULSE;

nTest:INT := 0;

END_VAR

CASE nTest OF

1:(*TimerPulse:TIMER_PULSE*)

(*Get an pulse output signal on 3 seconds with TimerOn*)

TimerPulse(In_BL:=TRUE,

Length_T:=T#3s);

(*TimerPulse.Out_BL=FALSE until time elapsed*)

(*TimerPulse.Elapsed_T = timer value increasing *)

2: (*Reset timer*)

TimerPulse(In_BL:=FALSE);

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 356


1.8.1.20 TOF_ABSOLUTE

1.8.1.20.1 Description

Timer off delay.

The TOF_ABSOLUTE function has the same purpose as the TOF_RELATIVE function, which is
timing the disconnection of a boolean input variable. However, unlike TOF_RELATIVE, the
TOF_ABSOLUTE function considers absolute execution time and is not affected by whether the
function block is called to count the time or not.

The function output will be at 1 while the input is also at 1. As soon as a falling edge is detected
in the input, the function begins timing based on the established parameter. The function output
will pass to 0 a time after the falling edge has occurred in the input.

If the input does not remain at 0 during the period set for timing, the output will at not point
change to 0. The function will wait for a repeated falling edge to perform new complete timing.

1.8.1.20.2 Syntax

FUNCTION_BLOCK TOF_ABSOLUTE

VAR_INPUT

In_BL:BOOL;

DeactivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.8.1.20.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Starts timer with falling edge, resets timer with rising edge.
DeactivationDelay_T TIME Time to pass, before Out_BL is set.
Tbl. 1.310 Input parameters of function TOF_ABSOLUTE.

Ingeteam Proprietary All Rights Reserved Pag. 357


1.8.1.20.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Is FALSE, DeactivationDelay_T seconds after In_BL had a falling edge
Elapsed_T TIME Time elapsed since timing started.
Tbl. 1.311 Output parameters of function TOF_ABSOLUTE.

1.8.1.20.5 Remarks

The TOF_ABSOLUTE function considers absolute time, regardless of whether the function block
is called or not. If the block is not being called, but the time has run out, when the function is
called for the first time the output will show the timing complete status.

The purpose of the TOF_ABSOLUTE function is to obtain in an output variable (Out_BL), the
equivalent of disconnection timing of a digital input signal (In_BL). This timing is performed
according to the time parameter DeactivationDelay_T.

At the start, the function sets its output to 1 at the same instant that the input signal changes to
1.

Once this occurs, the function remains waiting to detect a falling edge in the input. When this
edge occurs, timing begins counting internally. The function continues counting time as long as
the input is set at 0. Once the pre-established time has run out, the function will set the output to
0. This output will remain at 0 while the input continues at the low value.

If once the falling edge has occurred in the input, the input does not remain inactive during the
time established for timing, then the function will at not point set the output to 0. The function will
remain on standby to detect a falling edge in the input.

The time elapsed during timing can be ascertained at any time by referring to the values of the
Elapsed_T output variable.

Fig. 1.28 .

Ingeteam Proprietary All Rights Reserved Pag. 358


1.8.1.20.6 Example

PROGRAM Example

VAR

(*TOF_ABSOLUTE *)

TimerOff:TOF_ABSOLUTE;

nTest:INT:=0;

END_VAR

CASE nTest OF

1: (*Reset timer*)

(* Initialize a TOF_ABSOLUTE timer *)

TimerOff(In_BL :=TRUE,

DeactivationDelay_T:= T#5s);

2: (*Reset timer*)

(*Start timer off *)

TimerOff(In_BL :=FALSE);

END_CASE

1.8.1.21 TOF_RELATIVE

1.8.1.21.1 Description

Timer Off Delay.

The TOF_RELATIVE function performs timing on the disconnection of a boolean input variable.

The function output will be at 1 while the input is also at 1. As soon as a falling edge is detected
in the input, the function begins timing based on the established parameter. The function output
will pass to 0 a time after the falling edge has occurred in the input.

If the input does not remain at 0 during the period set for timing, the output will not set output to
0. The function will wait for a repeated falling edge to perform new complete timing.

1.8.1.21.2 Syntax

FUNCTION_BLOCK TOF_RELATIVE

VAR_INPUT

Ingeteam Proprietary All Rights Reserved Pag. 359


Input_BL:BOOL;

DeactivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_DI:DINT;

END_VAR

1.8.1.21.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input variable to the function for disconnection timing.
Time value for which the disconnection timing is required.
DeactivationDelay_T TIME
Only task time is taken into account.
Tbl. 1.312 Input parameters of function TOF_RELATIVE.

1.8.1.21.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output variable that is the result of performing the disconnection timing.
Function Status:
0 - Correct Execution
Status_DI DINT
2 - Warning: DeactivationDelay_T &lt; Cycle_TIME
3 - Internal Error
Tbl. 1.313 Output parameters of function TOF_RELATIVE.

1.8.1.21.5 Remarks

The TOF_RELATIVE function will only consider times while it is being called. If it is not called
during several cycles, it will consider that that time has not really elapsed.

The purpose of the TOF_RELATIVE function is to obtain in an output variable (Output_BL), the
equivalent of disconnection timing of a digital input signal (Input_BL). This timing is performed
according to the time parameter DeactivationDelay_T.

At first, the function sets its output to 1 at the same instant that the input signal changes to 1.

Once this occurs, the function remains waiting to detect a falling edge in the input. When this
edge occurs, time begins counting internally. The function continues counting time as long as the
input is set at 0. Once the pre-established time has run out, the function will set the output to 0.
This output will remain at 0 while the input continues at the low value.

Ingeteam Proprietary All Rights Reserved Pag. 360


If once the falling edge has occurred in the input, the input does not remain inactive during the
time established for timing, then the function will at not point set the output to 0. The function will
remain on standby to detect a falling edge in the input.

It should be remembered that the function does not consider the time elapsed during cycles in
which the instance is not called.

Fig. 1.29 .

1.8.1.21.6 Example

PROGRAM Example

VAR

TofRelative:TOF_RELATIVE;;

input:BOOL;(*Input*)

delayedOutputSignal:BOOL;(*Output with delayed deactivation.*)

status:DINT;(*Function Status 0-Correct Execution1-ActivationDelay_T<0*)

END_VAR

(* Get a 10.5 seconds delayed deactivation *)

TofRelative( Input_BL := input,

DeactivationDelay_T:=T#10s500ms);

delayedOutputSignal:=TofRelative.Output_BL;

status:=TofRelative.Status_DI;

Ingeteam Proprietary All Rights Reserved Pag. 361


1.8.1.22 TON_ABSOLUTE

1.8.1.22.1 Description

Timer on delay.

The TON_ABSOLUTE function has the same purpose as the TON_RELATIVE function, which is
timing the connection of a Boolean input variable. However, unlike TON_RELATIVE, the TON
function takes considers absolute execution time and is not affected by whether the function
block is called to count the time or not.

As soon as a rising edge is detected in the input, the function begins timing based on the
established parameter. Once the time has run out, the function will set the output to 1.

If the input does not remain at 1 during the period set for timing, the output will at no point
change to 1. The function will wait for a repeated rising edge to perform new complete timing.

1.8.1.22.2 Syntax

FUNCTION_BLOCK TON_ABSOLUTE

VAR_INPUT

In_BL:BOOL;

ActivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

Elapsed_T:TIME;

END_VAR

1.8.1.22.3 Input parameters

Input Parameter Name Type Description


In_BL BOOL Starts timer with rising edge, resets timer with falling edge.
ActivationDelay_T TIME Time to pass, before Out_BL is set.
Tbl. 1.314 Input parameters of function TON_ABSOLUTE.

Ingeteam Proprietary All Rights Reserved Pag. 362


1.8.1.22.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Is TRUE ActivationDelay_Tseconds after In_BL had a rising edge.
Elapsed_T TIME Time elapsed since timing started.
Tbl. 1.315 Output parameters of function TON_ABSOLUTE.

1.8.1.22.5 Remarks

The TON_ABSOLUTE function considers absolute time, regardless of whether the function block
is called or not. If the block is not being called, but the time has run out, when the function is
called for the first time the output will show the timing complete status.

The purpose of the TON_ABSOLUTE function is to obtain in an output variable (Out_BL), the
equivalent of connection timing of a digital input signal (In_BL). This timing is performed
according to the time parameter ActivationDelay_T.

The function will remain on standby to detect a rising edge in the input. When this edge occurs,
timing begins counting internally. The function continues counting time as long as the input is set
at 1. Once the pre-established time has run out, the function will set the output to 1. This output
will remain at 1 while the input continues at the high value.

If once the rising edge has occurred in the input, the input does not remain active during the time
established for timing, then the function will at not point set the output to 1. The function will
remain on standby to detect a rising edge in the input.

Fig. 1.30 .

1.8.1.22.6 Example

PROGRAM Example

VAR

(*TOF_ABSOLUTE *)

TimerOn:TON_ABSOLUTE;

Ingeteam Proprietary All Rights Reserved Pag. 363


nTest:INT :=0;

END_VAR

CASE nTest OF

1:(*Initialize a TON_ABSOLUTE timer*)

TimerOn(In_BL:=FALSE,ActivationDelay_T:= T#5s);

2:(*Start timer on*)

TimerOn(In_BL:=TRUE);

END_CASE

1.8.1.23 TON_RELATIVE

1.8.1.23.1 Description

Timer On Delay.

The TON_RELATIVE function applies a timing to the connection of a boolean input variable.

When a positive flag is detected in the input, the function starts de timing according to the
estabilished parameter. Once the time is over, the function sets the output to 1.

If the input value doesnt't remain at 1 during the time configured for the timing, the output won't
be set to 1. The function will remain waiting a new positive flag in the input to start a new full
timing.

1.8.1.23.2 Syntax

FUNCTION_BLOCK TON_RELATIVE

VAR_INPUT

Input_BL:BOOL;

ActivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_DI:DINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 364


1.8.1.23.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input variable to the function for connection timing.
Time value for which the connection timing is required.
ActivationDelay_T TIME
Only task time is taken into account.
Tbl. 1.316 Input parameters of function TON_RELATIVE.

1.8.1.23.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output variable that is the result of performing the connection timing.
Function Status:
0 - Correct Execution
Status_DI DINT
1 - Warning: ActivationDelay_T &lt; Cycle_TIME
3 - Internal Error
Tbl. 1.317 Output parameters of function TON_RELATIVE.

1.8.1.23.5 Remarks

The TON_RELATIVE function will only take the times in account while it is being called. If it is
not called during several cycles, it will not consider that that time has passed.

The TON_RELATIVE function has as an objective to obtain in an output variable (Output_BL),


the equivalent to a connection timing of a digital input signal (Input_BL). This timing is done
according to the time parameter ActivationDelay_T.

The function remains waiting to an input positive flag. When this flag occurs, an internal time
count starts. While the input remains at 1, the function continues the time count. Once the fixed
time ends, the function will set the output to 1. This output will remain at 1 while the input has a
high value.

In case of a positive flag in the input that doesn't remain active during the fixed time for the
timing, the function won't set the output to 1. The function will remain waiting for a positive flag in
the input.

It's important to remember the way that the function doesn't consider the time passed between
cycles in which the instance is not called.

Fig. 1.31 .

Ingeteam Proprietary All Rights Reserved Pag. 365


1.8.1.23.6 Example

PROGRAM TON_RELATIVE_Example

VAR

TonRelative:TON_RELATIVE;

input:BOOL;(*Input*)

delayedOutputSignal:BOOL;(*Output with delayed activation.*)

status:DINT;(*Function Status

0-Correct Execution

1-ActivationDelay_T<0*)

END_VAR

(* Get a 10.5 seconds delayed output *)

TonRelative(Input_BL:=input,

ActivationDelay_T :=T#10s500ms );

delayedOutputSignal:= TonRelative.Output_BL;

status:= TonRelative.Status_DI;

1.8.1.24 TONOF_RELATIVE

1.8.1.24.1 Description

Timer On/Off Delay.

The TONOF_RELATIVE function is a combination of the TON_RELATIVE and TOF_RELATIVE


functions. Therefore, it combines the connection and disconnection timing for the same input.

The function executes the two timings sequentially. First it times the input connection with the
rising edge. Once this timing has finished and the output is set at 1, the function stands by for the
falling edge to time the disconnection.

1.8.1.24.2 Syntax

FUNCTION_BLOCK TONOF_RELATIVE

VAR_INPUT

Input_BL:BOOL;

ActivationDelay_T:TIME;

Ingeteam Proprietary All Rights Reserved Pag. 366


DeactivationDelay_T:TIME;

END_VAR

VAR_OUTPUT

Output_BL:BOOL;

Status_DI:DINT;

END_VAR

1.8.1.24.3 Input parameters

Input Parameter Name Type Description


Input_BL BOOL Input variable to the function for connection/disconnection timing.
ActivationDelay_T TIME Time value for which the connection timing is required.
Time value for which the disconnection timing is required.
DeactivationDelay_T TIME
Only task time is taken into account.
Tbl. 1.318 Input parameters of function TONOF_RELATIVE.

1.8.1.24.4 Output parameters

Output Parameter Name Type Description


Output_BL BOOL Output variable that is the result of performing the connection-disconnection timing.
Function Status:
0 - Correct Execution
Status_DI DINT 1 - Warning: ActivationDelay_T &lt; Cycle_TIME
2 - Warning: DeactivationDelay_T &lt; Cycle_TIME
3 - Internal Error
Tbl. 1.319 Output parameters of function TONOF_RELATIVE.

1.8.1.24.5 Remarks

The TONOF_RELATIVE function will only consider times while it is being called. If it is not called
during several cycles, it will consider that the time has not really elapsed.

The purpose of the TONOF_RELATIVE function is first to obtain the equivalent to connection
timing in an output variable (Output_BL), and then the disconnection timing of a digital input
signal (Input_BL). This timing is performed according to the ActivationDelay_T time parameters
for timing the connection and DeactivationDelay_T time parameters for timing the disconnection.

As soon as a rising edge is detected in the input, the function begins timing based on the
parameter established for the connection timing. Once the time has run out, the function will set
the output to 1.

If the input does not remain at 1 during the period set for timing, the output will not change to 1.
The function will wait for a repeated rising edge to perform new complete timing.

Ingeteam Proprietary All Rights Reserved Pag. 367


Once the output is set at 1, it will remain at 1 as long as the input remains at 1. As soon as a
falling edge is detected in the input, the function begins timing based on the parameter
established for the disconnection timing. The function output will pass to 0 a time after the falling
edge has occurred in the input.

If the input does not remain at 0 during the period set for timing, the output will not change to 0.
The function will wait for a repeated falling edge to perform new complete timing.

Fig. 1.32 .

1.8.1.24.6 Example

PROGRAM Example

VAR

TofRelative:TOF_RELATIVE;;

input:BOOL;(*Input*)

delayedOutputSignal:BOOL;(*Output with delayed deactivation.*)

status:DINT;(*Function Status

0-Correct Execution

1-ActivationDelay_T<0*)

END_VAR

(* Get a 10.5 seconds delayed activation and a 3.5 seconds deactivation*)

TonofRelative(Input_BL:=input,

ActivationDelay_T:=T#10s500ms,

DeactivationDelay_T:=T#3s500ms);

delayedOutputSignal:=TonofRelative.Output_BL;

status:=TonofRelative.Status_DI;

Ingeteam Proprietary All Rights Reserved Pag. 368


1.8.1.25 WRITE_COUNTER

1.8.1.25.1 Description

This function is used to write to a Fast Counter.

The WRITE_COUNTER function allows the user to write a value in a counter of an IC3325 or
IC3391 fast counter module.

1.8.1.25.2 Syntax

FUNCTION_BLOCK WRITE_COUNTER

VAR_INPUT

Enable_BL:BOOL;

ChassisNum_DI:DINT;

SlotNum_DI:DINT;

CounterNum_DI:DINT;

Value_DI:DINT;

END_VAR

VAR_OUTPUT

Done_BL:BOOL;

Status_enCounterRet:enCounterRet;

END_VAR

1.8.1.25.3 Input parameters

Input Parameter Name Type Description


Enable_BL BOOL Enable / disable the execution of the function block.
Number of the chassis that contains the module (0..15).
ChassisNum_DI DINT
The CPU chassis corresponds to value 0.
SlotNum_DI DINT Number of the slot where the module is installed (0..15).
CounterNum_DI DINT Number of the counter to write (0..5).
Value_DI DINT Value to write.
Tbl. 1.320 Input parameters of function WRITE_COUNTER.

Ingeteam Proprietary All Rights Reserved Pag. 369


1.8.1.25.4 Output parameters

Output Parameter Name Type Description


Returns TRUE when the execution is completed.
Done_BL BOOL
Check Status_enCounterRet for the result of the execution.
Status_enCounterRet enCounterRet Result of the FB execution.
Tbl. 1.321 Output parameters of function WRITE_COUNTER.

1.8.1.25.5 Data Types

1.8.1.25.5.1 enCounterType

Value Description
IC3325 (0) IC3325 Counter module
IC3391 (1) IC3391 Counter module
IC3392 (2) IC3392 Counter module
Tbl. 1.322 Enumerator enCounterType.

1.8.1.25.5.2 enIC3325InputSignal

Value Description
G0 (0) Gate 0
G1 (1) Gate 1
G2 (2) Gate 2
G3 (3) Gate 3
G4 (4) Gate 4
G5 (5) Gate 5
G6 (6) Gate 6
G7 (7) Gate 7
Tbl. 1.323 Enumerator enIC3325InputSignal.

1.8.1.25.5.3 enInputSignalCodification

Value Description
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time you get the whole sequence
MODE1 (0) CHA rises - CHB rises - CHA falls - CHB falls. The counter is decremented each time you get the whole sequence
CHB rises - CHA rises - CHB falls - CHA falls.
CHA is a pulse input and CHB indicates the direction of counting: Increase if CHB=1 and decrease if CHB=0. The
MODE2 (1) counter is incremented each time CHA rises being CHB=1. The counter is decremented each time CHA rises
being CHB=0
CHA is a decremental pulse input, and CHB is an incremental pulse input. The counter is incremented each time
MODE3 (2)
CHB rises. The counter is decremented each time CHA rises
MODE4 (3) Pulses (incremental always) are generated with an internal clock 10 Mhz frequency
CHA and CHB are pulse inputs shifted 90. The counter is incremented each time CHA rises being CHB=0, or
CHB rises being CHA=1, or CHA falls being CHB=1, or CHB falls being CHA=0. The counter is decremented
MODE5 (4)
each time CHB rises being CHA=0,or CHA rises being CHB=1, or CHB falls being CHA=1, or CHA falls being
CHB=0
CHA is a pulse input and CHB indicates the direction of counting: Increases when CHB=1 and decreases when
MODE6 (5) CHB=0. The counter is incremented each time CHA rises or CHA falls being CHB=1. The counter is
decremented each time CHA rises or CHA falls being CHB=0
CHA is a decremental pulse input, and CHB is a incremental pulse input. The counter is incremented each time
MODE7 (6)
CHB rises or CHB falls. The counter is decremented each time CHA rises or CHA falls

Ingeteam Proprietary All Rights Reserved Pag. 370


Tbl. 1.324 Enumerator enInputSignalCodification.

1.8.1.25.5.4 stCounterFlags

Field Name Type Description


State of the physical sign associated to
InputSignal1State_BL BOOL
the first GATE.
State of the physical sign associated to
InputSignal2State_BL BOOL
the second GATE.
Variable that indicates overflow on the
CounterOverflow_BL BOOL
counter for reaching the setpoint set.
Tbl. 1.325 Fields of the stCounterFlags structure.

1.8.1.25.5.5 stIC3325Position

Field Name Type Description


Counter number to use for the position
CounterNum_DI DINT
calculation. Gate0 parameters.
Input Signal 1 (Conected to one of the
InputSignal1_enIC3325InputSignal enIC3325InputSignal
Gates (G0G7)).
Logic of the Input Signal to the first GATE
Signal1Inverted_BL BOOL (TRUE--> Inverted Logic, FALSE-->
Direct Logic).
Variable that allows me to capture the
CaptureCounterSignal1_BL BOOL counter value of the event in the signal 1.
Gate1 parameters.
Input Signal 2 (Conected to one of the
InputSignal2_enIC3325InputSignal enIC3325InputSignal
Gates (G0G7)).
Logic of the Input Signal to the second
Signal2Inverted_BL BOOL GATE (TRUE--> Inverted Logic, FALSE--
>Direct logic).
Enables or disables the preset when there
Signal2Preset_BL BOOL is a rising edge at the second GATE
input.
Variable that allows me to capture the
CaptureCounterSignal2_BL BOOL counter value of the event in the signal 2.
SetPoint parameters.
SetPointValue_R REAL SetPoint value in radians.
Enables or disables the preset when you
PresetSetPoint_BL BOOL
reach the SetPoint. Preset parameters.
Preset value in radians. Counters
PresetValue_R REAL
parameters.
InputSignalCod_enInputSignalCodifica Type of coding of signals from chanels
enInputSignalCodification
tion CHA and CHB.
Logic of the input signal conected to the
CHAInverted_BL BOOL CHANEL A (TRUE--> Inverted Logic,
FALSE-->Direct Logic).
Logic of the input signal conected to the
CHBInverted_BL BOOL CHANEL B (TRUE--> Inverted Logic,
FALSE-->Direct Logic).
Tbl. 1.326 Fields of the stIC3325Position structure.

Ingeteam Proprietary All Rights Reserved Pag. 371


1.8.1.25.5.6 enCounterRet

Value Description
OK_FastCounter (0) The function has been executed correctly
ERR_COUNT_CHASSIS_SLOT_NUM (1) The slot number is not valid (0..15)
ERR_COUNT_NONEXISTENT_RESOURCE (2) Counter module not found
ERR_COUNT_COUNTER_NUM (3) Invalid counter number (0..5)
GATE0 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE0_PARAM_CONF (4)
CounterNumberToChain_BY or PresetNumber_BY)
GATE1 invalid parameters (InputNumberGate_BY,
ERR_COUNT_GATE1_PARAM_CONF (5)
CounterNumberToChain_BY or PresetNumber_BY)
ERR_COUNT_SP0_PARAM_CONF (6) SET-POINT0 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP1_PARAM_CONF (7) SET-POINT1 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP2_PARAM_CONF (8) SET-POINT2 invalid parameters (PresetNumber_BY)
ERR_COUNT_SP3_PARAM_CONF (9) SET-POINT3 invalid parameters (PresetNumber_BY)
ERR_COUNT_INTERNAL (10) Internal counter error occured
Invalid parameter: stReducedCounterCfg.InputNumberChA_BY > 5 or
ERR_COUNT_CFG_PARAM (11)
stReducedCounterCfg. InputNumberChB_BY > 5
ERR_INVALID_ADDRESS (12) The address in CounterNum_stCounterConf_ADDR is not valid
ERR_COUNT_RESOURCE_ACCESS (13) Can not access the counter module
ERR_BIT_NUMBER_PARAM_ERRONEO (14)
ERR_CLOCK_PERIOD_PARAM_ERRONEO (15)
ERR_T_MIN_PARAM_ERRONEO (16)
ERR_READING_COUNT (17)
ERR_CONFIGURING_COUNT (18)
ERR_MASKED_COUNT (19)
ERR_NO_SSI_PULSE (20)
ERR_OVERFLOW (21) Read value is over the limits
ERR_INPUT_SIGNAL (22) Error in the inpuit signals
ERR_MOD_TYPE (23) Module type erroneous
Tbl. 1.327 Enumerator enCounterRet.

1.8.1.25.5.7 stCounterPreset

Field Name Type Description


PresetValue_DI DINT Preset value.
Tbl. 1.328 Fields of the stCounterPreset structure.

1.8.1.25.5.8 stCounterSp

Field Name Type Description


SpValue_DI DINT Set Point value.
Conf_stSpConf stSpConf Structure with the configuration of the Set Point.
Tbl. 1.329 Fields of the stCounterSp structure.

Ingeteam Proprietary All Rights Reserved Pag. 372


1.8.1.25.5.9 stGateConf

Field Name Type Description


Indicates if input Gate is inverted. FALSE: The signal connected to the
Ig_BL BOOL GATE is direct logic. TRUE: The signal connected to the GATE is invert
logic.
Input Number (0..7-Generic Counter or 0..5-Reduced Counter).
Generic Reduced
0 Gate0 IN_0
1 Gate1 IN_1
2 Gate2 IN_2
InputNumberGate_BY BYTE
3 Gate3 IN_3
4 Gate4 IN_4
5 Gate5 IN_5
6 Gate6
7 Gate7.
CountertNumberToChain_BY BYTE Number of the counter to concatenate with the GATE 0..5).
Disarm_BL BOOL See Arm_BL.
These parameters determine the action of the GATE signal over the
status of the counter.
[ARM=0, DRM=0]
The status doesnt change.
[ARM=1, DRM=0] Counter armed on GATE event.
[ARM=0, DRM=1] Counter disarmed on GATE event.
Arm_BL BOOL [ARM=1, DRM=1]
If configuring GATE0, the counter is armed while GATE0 is TRUE and
disarmed while GATE0 is FALSE.
IF configuring GATE1 and ARM and DRM bits are TRUE for GATE0, this
configuration has no efect because GATE0 has more priority.
If ARM and DRM bits are not both TRUE for GATE0, the counter is
armed while GATE1 is TRUE and disarmed while GATE1 is FALSE.
FALSE: The GATE trigger event is not registered in the flags register.
ActivateFlag_BL BOOL TRUE The GATE trigger event is registered in the flags register in the
input gate.
Number of the Preset to load the counter with:
IC3325: Number of the PRESET associated to the GATE event, among
PresetNumber_BY BYTE
the 4 available (0..3)
IC3391: There is only 1 PRESET, so this value must be always 0.
To Preset or not when a rising edge occurs in the input gate:
FALSE: The PRESET value associated to the GATE will not be used
Preset_BL BOOL
TRUE: The PRESET value associated to the GATE will be loaded into
the counter when the GATE event occur.
Capture or not the value counter when a rising edge occurs in the input
gate:
FALSE: The value of the counter wont be stored when the GATE event
Capture_BL BOOL
occur
TRUE: The value of the counter is stored in
stReducedCounter.HoldValue_DI when the GATE event occur.
Chain this counter or not with other:
Chain_BL BOOL FALSE: The counter is not concatenated to other counter
TRUE: The counter is concatenated to other counter.
Tbl. 1.330 Fields of the stGateConf structure.

Ingeteam Proprietary All Rights Reserved Pag. 373


1.8.1.25.5.10 stGenericCounter

Field Name Type Description


CounterValue_DI DINT Actual Counter Value.
StsFlags_stGenericSTSFlags stGenericSTSFlags STS and Flags.
Captured value of the counter (this value is captured when a certain
HoldValue_DI DINT
event occur).
If the counter is configured to measure velocity, this variable
TimeValue100ns_UDI UDINT
contains the time value, in 10e-7 seconds.
Tbl. 1.331 Fields of the stGenericCounter structure.

1.8.1.25.5.11 stGenericCounterCfg

Field Name Type Description


Input A inverted:
Ia_BL BOOL FALSE: Channel A (CHA) signal is direct logic (if input signal is low -> CHA is FALSE)
TRUE: Channel A (CHA) signal is inverse logic (if input signal is low -> CHA is TRUE).
Input B inverted:
Ib_BL BOOL FALSE: Channel B (CHB) signal is direct logic (if input signal is low -> CHB is FALSE)
TRUE: Channel B (CHB) signal is inverse logic (if input signal is low -> CHB is TRUE).
M0_BL BOOL Bit 0 Encoder Type. See F_BL.
M1_BL BOOL Bit 1 Encoder Type. See F_BL.
Configuration of how the counter counts.
Bits M0_BL, M1_BL, and F_BL determine the codification type of CHA and CHB signals
and how to understand them.
[F=0, M1=0, M0=0]
CHA and CHB are pulse signals with 90grad delay. The counter increases each time the
sequence CHA rising edge, CHB rising edge, CHA falling edge, CHB falling edge
completes. The counter decreases each time the sequence CHB rising edge, CHA rising
edge, CHB falling edge, CHA falling edge completes.
[F=0, M1=0, M0=1]
CHA is a pulsed input and CHB indicates up (CHB=TRUE) or down (CHB=FALSE)
counting direction. The counter increases on CHA rising edge if CHB=1, and decreases on
CHA rising edge if CHB=0.
[F=0, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on CHB rising edge and decreases
on CHA rising edge.
F_BL BOOL [F=X, M1=1, M0=1]
The pulses are generated in an internal clock which frequency is determined by bits E4 to
E0.
[F=1, M1=0, M0=0]
CHA and CHB are pulse signals with 90deg delay. The counter increases on CHA rising
edge if CHB=0, or on CHB rising edge if CHA=1, or on CHA falling edge if CHB=1, or on
CHB falling edge if CHA=0. The counter decreases on CHB rising edge if CHA=0, or on
CHA rising edge if CHB=1, or on CHB falling edge if CHA=1, or on CHA falling edge if
CHB=0.
[F=1, M1=0, M0=1]
CHA is a pulse signal and CHB indicates the direction of counting. The counter increases
on CHA rising or falling edge if CHB=1. The counter decreases on CHA rising or falling
edge if CHB=0.
[F=1, M1=1, M0=0]
CHA and CHB are pulse signals. The counter increases on rising or falling edge of CHB,
and decreases on rising or falling edge of CHA.
Bit 0 Programmable divisor .
E0_BL BOOL When M1=1 and M0=1, the internal clock frequency is 10MHz/FD, where FD is (E4..E0 +
1). For example, if E4..E0 = 00000b (0d) => 10MHz, if E4..E0 = 00001b (1d) => 10/2MHz,
..., if E4..E0 = 11111b (31d) => 10/32MHz.
E1_BL BOOL Bit 1 Programmable divisor .
E2_BL BOOL Bit 2 Programmable divisor .
E3_BL BOOL Bit 3 Programmable divisor .
E4_BL BOOL Bit 4 Programmable divisor .

Ingeteam Proprietary All Rights Reserved Pag. 374


Field Name Type Description
Speed Mode.
V_BL BOOL FALSE: Counter NOT configured in velocity measure mode
TRUE: Counter configured in velocity measure mode.
Drm_BL BOOL Disarm Counter. See Arm_BL.
Arm Counter. Enables the CPU to control the status of the pulse counter:
[ARM=0, DRM=0] The status doesnt change.
[ARM=1, DRM=0] The counter is started.
Arm_BL BOOL
[ARM=0, DRM=1] The counter is stopped.
[ARM=1, DRM=1]
Inverts the status of the counter. It starts it if it was stopped, or stops it if it was started.
Tbl. 1.332 Fields of the stGenericCounterCfg structure.

1.8.1.25.5.12 stGenericCounterConf

Field Name Type Description


Conf_stGenericCounterConf stGenericCounterCfg Structure with the configuration of the Counter.
Gate0_stGateConf stGateConf Structure with the configuration of the Gate0.
Gate1_stGateConf stGateConf Structure with the configuration of the Gate1.
SP0_stCounterSp stCounterSp Structure with the configuration of the SP0.
SP1_stCounterSp stCounterSp Structure with the configuration of the SP1.
SP2_stCounterSp stCounterSp Structure with the configuration of the SP2.
SP3_stCounterSp stCounterSp Structure with the configuration of the SP3.
PR0_stCounterPreset stCounterPreset Structure with the configuration of the PR0.
PR1_stCounterPreset stCounterPreset Structure with the configuration of the PR1.
PR2_stCounterPreset stCounterPreset Structure with the configuration of the PR2.
PR3_stCounterPreset stCounterPreset Structure with the configuration of the PR3.
Tbl. 1.333 Fields of the stGenericCounterConf structure.

1.8.1.25.5.13 stGenericSTSFlags

Field Name Type Description


G0_BL BOOL G0's Input State.
G1_BL BOOL G1's Input State.
DIR_BL BOOL 0/1-Counter is increasing/decreasing.
RMD_BL BOOL State Arm Counter.
Reserve1_BL BOOL Reserved.
Reserve2_BL BOOL Reserved.
Reserve3_BL BOOL Reserved.
Reserve4_BL BOOL Reserved.
H0_BL BOOL Is set when a rising edge occurs in G0 if the flag ActivateFlag_BL of G0 configuration is set.
H1_BL BOOL Is set when a rising edge occurs in G1 if the flag ActivateFlag_BL of G1 configuration is set.
Is set when the Counter Value = SP0 values if the flag ActivateFlag_BL of SP0 configuration
H2_BL BOOL
is set.
Is set when the Counter Value = SP1 values if the flag ActivateFlag_BL of SP1 configuration
H3_BL BOOL
is set.
Is set when the Counter Value = SP2 values if the flag ActivateFlag_BL of SP2 configuration
H4_BL BOOL
is set.
Is set when the Counter Value = SP3 values if the flag ActivateFlag_BL of SP3 configuration
H5_BL BOOL
is set.
Reserve5_BL BOOL Reserved.
Reserve6_BL BOOL Reserved.
Tbl. 1.334 Fields of the stGenericSTSFlags structure.

Ingeteam Proprietary All Rights Reserved Pag. 375


1.8.1.25.5.14 stSpConf

Field Name Type Description


FALSE: The counter does not change its armed/diarmed status when the SET-POINT value
Drm_BL BOOL is reached.
TRUE: The counter is disarmed when the value SpValue_DI is reached.
FALSE: The SET-POINT reach event is not stored in the flags register
ActivateFlag_BL BOOL
TRUE: The SET-POINT reach event is stored in the flags register.
IC3325: Number of the PRESET associated to the SET-POINT reach event, among the 4
PresetNumber_BY BYTE available
IC3391: There is only 1 PRESET available, so this parameter must be always 0.
FALSE: The PRESET value is not used
Preset_BL BOOL TRUE: The PRESET value is loaded to the counter when the SET-POINT reach event
occur.
Tbl. 1.335 Fields of the stSpConf structure.

1.8.1.25.6 Remarks

To write a value, the user must set Value_DI to the desired value and then set Enable_BL to
TRUE. When the function finishes the operation, the user must set Enable_BL to FALSE until a
new write.

The function indicates completion with the output parameter Done_BL. When this occurs the
user can check Status_enCounterRet for the execution result. Note that the value of
Status_enCounterRet has a meaning only when Done_BL is TRUE.

1.8.1.25.7 Example

PROGRAM Example_Position

VAR

IC3325Position:POSITION_COUNTER;

stIC3325PositionConfiguration:stIC3325Position;

Output1:REAL;

PrevCycle:REAL;

Delta:REAL;

Write:BOOL:=FALSE;

END_VAR

(*Read Position with an IC3325 *)

(* IC3325 Input Signal definition*)

stIC3325PositionConfiguration.CounterNum_DI:=0;

stIC3325PositionConfiguration.CHAInverted_BL:=FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 376


stIC3325PositionConfiguration.CHBInverted_BL:=FALSE;

stIC3325PositionConfiguration.InputSignalCod_enInputSignalCodification:=MODE1;

stIC3325PositionConfiguration.InputSignal1_enIC3325InputSignal:=G0;

stIC3325PositionConfiguration.Signal1Inverted_BL:=FALSE;

stIC3325PositionConfiguration.CaptureCounterSignal1_BL:=FALSE;

stIC3325PositionConfiguration.InputSignal2_enIC3325InputSignal:=G1;

stIC3325PositionConfiguration.Signal2Inverted_BL:=FALSE;

stIC3325PositionConfiguration.CaptureCounterSignal2_BL:=FALSE;

stIC3325PositionConfiguration.Signal2Preset_BL:=TRUE;

stIC3325PositionConfiguration.PresetSetPoint_BL:=TRUE;

stIC3325PositionConfiguration.SetPointValue_R:=900000;

stIC3325PositionConfiguration.PresetValue_R:=0;

(*Get Position*)

IC3325Position(

Enable_BL:=TRUE ,

CounterType_enCounterType:=IC3325 ,

ChassisNum_DI:=0 ,

SlotNum_DI:= 1,

Read_BL:= TRUE,

Write_BL:= Write,

ValueToWrite_R:=(*50000*) 54321,(*WRITE this value*)

CounterConfigure_ADRR:=ADR (stIC3325PositionConfiguration),

CounterConfigureSizeBy_DI:= SIZEOF (stIC3325PositionConfiguration),

PulsesPerTurn_I:= 100,

Done_BL=> ,

CurrentPositionRad_R=> ,

HoldPositionRad_R=> ,

Status_enCounterRet=> ,

Status_stCounterFlags=>

);

Ingeteam Proprietary All Rights Reserved Pag. 377


Output1:=IC3325Position.CurrentPositionRad_R;(*READ the writed value*)

(*******************************************************)

(* Low level POSITION_COUNTER Function Block *)

(*******************************************************)

FUNCTION_BLOCK POSITION_COUNTER

(*Function to use the Generic counter (IC3325) for measuring the position of a signal on input
channel*)

VAR_INPUT

(*Auxiliar delay counter variables*)

Enable_BL:BOOL;(*Flag to Enable the function*)

CounterType_enCounterType:enCounterType;(*Counter Type*)

(*CONFIGURATION Variables*)

(*Counter parameters*)

ChassisNum_DI:DINT;(*Chassis Number*)

SlotNum_DI:DINT;(*Slot Number*)

(*Control parameters*)

Read_BL:BOOL;(*Read mode*)

Write_BL:BOOL;(*Write mode*)

(*WRITE Variables*)

ValueToWrite_R:REAL;(*Write value in radians*)

(*Counter structures*)

CounterConfigure_ADRR:DWORD;

CounterConfigureSizeBy_DI:DINT;

(*Coversion Parameters*)

PulsesPerTurn_I:REAL;(*Number of pulses in a whole turn*)

END_VAR

VAR_OUTPUT

(*Auxiliar period counter variables*)

Done_BL:BOOL;(*Execution of the FB has finished*)

(*READ Variables*)

Ingeteam Proprietary All Rights Reserved Pag. 378


CurrentPositionRad_R:REAL;(*Actual Counter Value*)

HoldPositionRad_R:REAL;(*Hold value of the counter*)

Status_enCounterRet:enCounterRet;(*Result of the FB execution.*)

(*The data structure is in the Regulation_02.lib library*)

(*0-Correct execution

1-Error nChassis-nSlot

2-Error nonexistent resource

3-Error nCounter

4-Error Gate0 Parameters

5-Error Gate1 Parameters

6-Error SP0 Parameters

7-Error SP1 Parameters

8-Error SP2 Parameters

9-Error SP3 Parameters

10-Error Internal*)

Status_stCounterFlags:stCounterFlags;(*Counter Indication Flags*)

END_VAR

{library private}

VAR

(*CONFIGURATION Variables*)

CONFIGURATION:CONFIGURE_COUNTER;(*Instance counter configuration function*)

stIC3325PositionConf:stIC3325Position;

Pointer_stIC3325PositionConf:POINTER TO stIC3325Position;

stGenericCounterPosition:stGenericCounterConf;

stGenericCounterConfiguration:stGenericCounterCfg;

stConfigurationGate0:stGateConf;

stConfigurationGate1:stGateConf;

stPresetConfiguration:stCounterPreset;

stSPConfiguration:stCounterSp;

(*READ Variables*)

Ingeteam Proprietary All Rights Reserved Pag. 379


READ:READ_COUNTER;(*Instance counter read function*)

stGenericCounterRead:stGenericCounter;

(*READ Variables*)

WRITE:WRITE_COUNTER;(*Instance to the write function of the counter *)

(*AUXILIARY Variables*)

RiseEdgeDetection:RISING_TRIG;(*Instance to the function that detects rising edges of an


input signal *)

Configuration_BL:BOOL;(*Auxiliary variable used during the configuration process of


counting. Remains TRUE while this work is being performed *)

END_VAR

(* In the cycle in which there is a rising edge signal Enable_BL, there must be the counter
configuration*)

RiseEdgeDetection.In_BL:=Enable_BL;(*Associate Enable_BL signal FB which is responsible for


detecting rising edges *)

RiseEdgeDetection();(*FB call that performs the detection of rising edges*)

IF (RiseEdgeDetection.Out_BL) THEN (*It checks whether there has been a rising edge signal
Enable_BL*)

Configuration_BL:=TRUE;(*Activate the auxiliary variable which allows the configuration of


the counter*)

END_IF;

CASE (CounterType_enCounterType) OF

0: (*Generic Counter IC3325*)

IF (CounterConfigureSizeBy_DI=SIZEOF(stIC3325PositionConf)) THEN (*It


checks whether the configuration structure that have passed to the function corresponds to the
type of counter indicated*)

IF (Configuration_BL) THEN

(*If the auxiliary signal configuration is activated ( there has been a rising
edge signal Enable_BL) then configure the counter *)

(* Copy the data associated with the structure of the pointer to a auxiliary
structure of the same type, to handle them *)

Pointer_stIC3325PositionConf:=CounterConfigure_ADRR;

stIC3325PositionConf:=Pointer_stIC3325PositionConf^;

(*Counter Generic parameters*)

Ingeteam Proprietary All Rights Reserved Pag. 380


stGenericCounterConfiguration.Arm_BL:=FALSE;

(*Arm = FALSE y Drm = FALSE: Armed and disarmed of the counter is not
controlled by the CPU *)

stGenericCounterConfiguration.Drm_BL:=FALSE;

stGenericCounterConfiguration.Ia_BL:=stIC3325PositionConf.CHA
Inverted_BL;(*Indicate whether the signal connected to channel A
should be interpreted with direct or reverse logic*)

stGenericCounterConfiguration.Ib_BL:=stIC3325PositionConf.CHB
Inverted_BL; (*Indicate whether the signal connected to channel
B should be interpreted with direct or reverse logic*)

CASE
(stIC3325PositionConf.InputSignalCod_enInputSignalCodification)
OF (*Set the mode of interpretation for the counting of physical
signals connected to channels A and B counter*)

0:(*MODE 1*)

stGenericCounterConfiguration.M0_BL:= FALSE;

stGenericCounterConfiguration.M1_BL:= FALSE;

stGenericCounterConfiguration.F_BL:=FALSE;

1:(*MODE 2*)

stGenericCounterConfiguration.M0_BL:= TRUE;

stGenericCounterConfiguration.M1_BL:= FALSE;

stGenericCounterConfiguration.F_BL:=FALSE;

2:(*MODE 3*)

stGenericCounterConfiguration.M0_BL:= FALSE;

stGenericCounterConfiguration.M1_BL:= TRUE;

stGenericCounterConfiguration.F_BL:=FALSE;

3:(*MODE 4*)

stGenericCounterConfiguration.M0_BL:= TRUE;

stGenericCounterConfiguration.M1_BL:= TRUE;

stGenericCounterConfiguration.F_BL:=FALSE;

4:(*MODE 5*)

stGenericCounterConfiguration.M0_BL:= FALSE;

Ingeteam Proprietary All Rights Reserved Pag. 381


stGenericCounterConfiguration.M1_BL:= FALSE;

stGenericCounterConfiguration.F_BL:=TRUE;

5:(*MODE 6*)

stGenericCounterConfiguration.M0_BL:= TRUE;

stGenericCounterConfiguration.M1_BL:= FALSE;

stGenericCounterConfiguration.F_BL:=TRUE;

6:(*MODE 7*)

stGenericCounterConfiguration.M0_BL:= FALSE;

stGenericCounterConfiguration.M1_BL:= TRUE;

stGenericCounterConfiguration.F_BL:=TRUE;

END_CASE;

stGenericCounterPosition.Conf_stGenericCounterConf:=

stGenericCounterConfiguration;

(*Gate0 parameters*)

stConfigurationGate0.Ig_BL:=

stIC3325PositionConf.Signal1Inverted_BL;(*
Select direct or reverse logic of GATE0 *)

stConfigurationGate0.InputNumberGate_B
Y:=INT_TO_BYTE(stIC3325PositionConf.I
nputSignal1_enIC3325InputSignal); (*
Physical input that is associated with
GATE0 (0 .. 7) *)

stConfigurationGate0.Arm_BL:=TRUE;(* Arm = 1 y Disarm


= 1: the state of arming / disarming of the counter is
controlled by the GATE0 *)

stConfigurationGate0.Disarm_BL:=TRUE;

stConfigurationGate0.ActivateFlag_BL:=TRUE;(* When the

trigger event of GATE0 occurs, then collect the flags in the


corresponding structure *)

stConfigurationGate0.Capture_BL:=stIC3325PositionConf.
CaptureCounterSignal1_BL;

stConfigurationGate0.Chain_BL:=FALSE;(* The counter is


not locked to another counter*)

Ingeteam Proprietary All Rights Reserved Pag. 382


stGenericCounterPosition.Gate0_stGateConf:=stConfigura
tionGate0;

(*Gate1 parameters*)

stConfigurationGate1.Ig_BL:=stIC3325PositionConf.Signal
2Inverted_BL;(* Select direct or reverse logic of GATE1 *)

stConfigurationGate1.InputNumberGate_BY:=INT_TO_BY
TE(stIC3325PositionConf.InputSignal2_enIC3325InputSig
nal); (* Physical input that is associated with GATE1 (0..7)
*)

stConfigurationGate1.Arm_BL:=FALSE;(* Arm = 0 y
Disarm = 0: the state of arming / disarming of the counter
is controlled by the GATE1*)

stConfigurationGate1.Disarm_BL:=FALSE;

stConfigurationGate1.ActivateFlag_BL:=TRUE;
(* When the trigger event of GATE1 occurs, then collect

the flags in the corresponding structure *)

stConfigurationGate1.PresetNumber_BY:=0;
(* PRESET 0 is associated to GATE1 *)
stConfigurationGate1.Preset_BL:=

stIC3325PositionConf.Signal2Preset_BL;(*
PRESET value is loaded into the counter when the GATE1
event occurs*)

stConfigurationGate1.Capture_BL:=stIC3325PositionConf.
CaptureCounterSignal2_BL;(* The counter value is NOT
saved in HoldValue_DI when activate HoldValue_DI is
activated*)

stConfigurationGate1.Chain_BL:=FALSE;

(* The counter is not locked to another counter*)

stGenericCounterPosition.Gate1_stGateConf:=stConfigura
tionGate1;

(*Set Point parameters*)

stSPConfiguration.SpValue_DI:=

REAL_TO_DINT((stIC3325PositionConf.SetPointV
alue_R*PulsesPerTurn_I)/6.2831853); (*
SetPoint value *)

Ingeteam Proprietary All Rights Reserved Pag. 383


stSPConfiguration.Conf_stSpConf.ActivateFlag_BL:=

TRUE;(* The event that has reached the setpoint


is displayed on the flags *)

stSPConfiguration.Conf_stSpConf.Drm_BL:=FALSE;

(* The counter maintains the state arm / disarm


state when the setpoint is reached *)

stSPConfiguration.Conf_stSpConf.Preset_BL:=TRUE;
(* PRESET value associated with GATE1

is loaded into the counter when the GATE1 event


occurs*)

stSPConfiguration.Conf_stSpConf.PresetNumber_BY:=0;
(* Associate PRESET 0 to GATE1 *)

stGenericCounterPosition.SP0_stCounterSp:=

stSPConfiguration;

(*Preset parameters*)

stPresetConfiguration.PresetValue_DI:=

REAL_TO_DINT((stIC3325PositionConf.PresetVal
ue_R*PulsesPerTurn_I)/6.2831853);(* Valor del
preset *)

stGenericCounterPosition.PR0_stCounterPreset:=

stPresetConfiguration;

CONFIGURATION.Enable_BL:=Configuration_BL;(*Enabl
e the counter configuration function*)

CONFIGURATION.ChassisNum_DI:=ChassisNum_DI;(*C
hassis number in which the counter is placed*)

CONFIGURATION.SlotNum_DI:=SlotNum_DI;(*Slot
number in which the counter is placed*)

CONFIGURATION.CounterNum_DI:=stIC3325PositionCon
f.CounterNum_DI;(*Counter number*)

CONFIGURATION.CounterNum_stCounterConf_ADDR:=
ADR(stGenericCounterPosition);(*Reference to the
configuration structure of the accountant*)

CONFIGURATION();(*CALL SETUP function*)

Ingeteam Proprietary All Rights Reserved Pag. 384


(*Output Values*)

Done_BL:= CONFIGURATION.Done_BL;(*Variable indicating the


completion of the configuration of the coun*)

Status_enCounterRet:= CONFIGURATION.Status_enCounterRet;
(*Exit status of the configuration*)

END_IF;

(* If the configuration of the counter has been performed, and the signal
Enable_BL of function is TRUE, then begin reading the counter *)

(* NOTE: A cycle after configuration, the first read or write to the counter is
performed *)

IF(NOT Configuration_BL AND Enable_BL) THEN

IF (Write_BL) THEN

WRITE.Enable_BL:=Write_BL;(*The write function is


enabled*)
WRITE.CounterNum_DI:=stIC3325PositionConf.CounterN
um_DI;(*Number of counter in which it will be writed*)

WRITE.ChassisNum_DI:=ChassisNum_DI;(*Chassis
number which the counter is connected*)

WRITE.SlotNum_DI:=SlotNum_DI;(*Slot number which the


counter is connected*)

WRITE.Value_DI:=REAL_TO_DINT((ValueToWrite_R*Pul
sesPerTurn_I)/6.2831853);(*Value to write*) (*convert from
radians to number of pulses*)

WRITE();(*CALL the WRITE function*)

(*Output Values*)

Done_BL:=WRITE.Done_BL;

Status_enCounterRet:=

WRITE.Status_enCounterRet;(*Exit status of the


write function*)

END_IF;

IF (Read_BL) THEN

READ.Enable_BL:=Read_BL;(*enables the reading


function*)

Ingeteam Proprietary All Rights Reserved Pag. 385


READ.CounterNum_DI:=stIC3325PositionConf.CounterNu
m_DI;(*Number of counter in which it will be readed*)

READ.ChassisNum_DI:=ChassisNum_DI;(*Chassis
number which the counter is connecteda*)

READ.SlotNum_DI:=SlotNum_DI;(*Slot number which the


counter is connected*)

READ.DeleteFlags_BL:=TRUE;(*Read and clear the value


of flags *)

READ.Counter_stCounter_ADDR:=ADR(stGenericCounter
Read);(*Link to Reading configuration structure*)

READ();(*CALL the READ function*)

(*Output Values*)

Done_BL:=TRUE;

Status_enCounterRet:= READ.Status_enCounterRet;
(*Exit status of the read function*)

(*Flags asociados al contador*)

Status_stCounterFlags.CounterOverflow_BL:=

stGenericCounterRead.StsFlags_stGenericSTSFla
gs.H2_BL;(*Variable that indicates counter
overflow because the setpoint is reached*)

Status_stCounterFlags.InputSignal1State_BL:=stG
enericCounterRead.StsFlags_stGenericSTSFlags.
G0_BL; (*Physical state of the signal associated
with the first GATE*)

Status_stCounterFlags.InputSignal2State_BL:=stG
enericCounterRead.StsFlags_stGenericSTSFlags.
G1_BL; (*Physical state of the signal associated
with the second GATE*)

(*If the reading function is executed successfully convert


the read data to radians*)

IF (READ.Status_enCounterRet=0) THEN

CurrentPositionRad_R:=

((DINT_TO_REAL(stGenericCounterRead.
CounterValue_DI)/PulsesPerTurn_I)*6.283

Ingeteam Proprietary All Rights Reserved Pag. 386


1853); (*Current encoder position in
radians*)

HoldPositionRad_R:=((DINT_TO_REAL(st
GenericCounterRead.HoldValue_DI)/Pulse
sPerTurn_I)*6.2831853);(*Counter value*)

END_IF;

END_IF;

END_IF;

(*Avoid setting up and read the meter in the same cycle*)

IF (CONFIGURATION.Done_BL) THEN

Configuration_BL:=FALSE;

END_IF;

ELSE (*If the structure passed to the function, does not match the expected
size*)

Done_BL:=TRUE;(*End of configuration function*)

Status_enCounterRet:=12;(*Indicates that the configuration structure


passed to the function, does not match the selected counter*)

END_IF;

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 387


1.9 Standard_01

The following tables sumarize the entities contained in Standard_01:

Name Description
BCD_BYTE_TO_INT Function that converts a number in BCD code to its equivalent base 10 integer.
DATE_AND_TOD_TO_stPLCTime Function to make a conversion from DATE and TOD to stPLCTime.
DT_TO_stPLCTime Function to make a conversion from DT to stPLCTime.
EXTRACT_BL Extract a bit out of a dword.
INT_TO_BCD_BYTE The INT_TO_BCD_BYTE function converts a base 10 integer to its equivalent BCD code.
PACK_BL The PACK_BL function groups 8 BOOL type inputs in a BYTE type variable.
The PUTBIT_DW function is used to write a specific boolean value (TRUE or FALSE) in a
PUTBIT_DW
specific bit of a DWORD type variable.
RESET_SET Bistable function, reset dominant.
SET_RESET Bistable function, set dominant.
The stPLCTime_TO_DATE function extracts the date information in stPLCTime format to
stPLCTime_TO_DATE
DATE type data.
stPLCTime_TO_DT Function to make a conversion from stPLCTime to DT.
stPLCTime_TO_TOD Function to make a conversion from stPLCTime to TOD.
UNPACK_BY Function block that unpacks a byte into 8 bits.
Tbl. 1.336 Functions, Function Blocks, and Programs.

1.9.1 Functions

1.9.1.1 BCD_BYTE_TO_INT

1.9.1.1.1 Description

Function that converts a number in BCD code to its equivalent base 10 integer.

1.9.1.1.2 Syntax

FUNCTION BCD_BYTE_TO_INT : INT

VAR_INPUT

Input_BY:BYTE;

END_VAR

1.9.1.1.3 Input parameters

Input Parameter Name Type Description


Input_BY BYTE A variable with its value coded in BCD that we want to convert to its equivalent in INT.
Tbl. 1.337 Input parameters of function FUNCTION BCD_BYTE_TO_INT.

Ingeteam Proprietary All Rights Reserved Pag. 388


1.9.1.1.4 Remarks

To use the BCD_BYTE_TO_INT function, all that is required is the call to the function with an
input parameter containing a value coded in BCD, and a result to be assigned to a variable of the
INT type.

Although the input parameter is coded in BCD, this does NOT imply that it must be represented
in binary format in the PROGRAM. It can be represented in any OF the forms permitted BY the
programming environment.

If an incorrect input parameter is entered, the function will return a result of -1.

The maximum input value is 255 (1111 1111) since it is a BYTE. However, as it is represented in
BCD, the highest integer that can be represented in a BYTE is 99 (0110 0011), which in BCD
corresponds to 153 (1001 1001).

1.9.1.1.5 Example

PROGRAM Example

VAR

(*BCD_BYTE_TO_INT*)

DataIn_BCD: BYTE := 16#93; (* 93 BCD *)

DataOut_INT: INT ;

END_VAR

DataOut_INT:=BCD_BYTE_TO_INT(DataIn_BCD);

(*Output = 93 (16#5c)*)

1.9.1.2 DATE_AND_TOD_TO_stPLCTime

1.9.1.2.1 Description

Function to make a conversion from DATE and TOD to stPLCTime.

1.9.1.2.2 Syntax

FUNCTION DATE_AND_TOD_TO_stPLCTime : stPLCTime

VAR_INPUT

Input_DATE:DATE;

Input_TOD:TOD;

Ingeteam Proprietary All Rights Reserved Pag. 389


END_VAR

1.9.1.2.3 Input parameters

Input Parameter Name Type Description


Input_DATE DATE Input date used to compose the output variable.
Input_TOD TOD Input time used to compose the output variable.
Tbl. 1.338 Input parameters of function FUNCTION DATE_AND_TOD_TO_stPLCTime.

1.9.1.2.4 Data Types

1.9.1.2.4.1 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing, the
WeekDay_I INT PLC_TIME function ignores this field, since the PLC calculates this value and writes it
in the clock automatically.
Tbl. 1.339 Fields of the stPLCTime structure.

1.9.1.2.5 Remarks

Returns a structure with the date and time value consisting of different fields for each element.

All that is required to use the DATE_AND_TOD_TO_stPLCTime function is the separate entry of
the date value in DATE format (Input_DATE) and the time value (Input_TOD). The function will
return a stPLCTime type variable with all the date and time information.

1.9.1.2.6 Example

PROGRAM Example

VAR

(*DATE_AND_TOD_TO_stPLCTime *)

DateVariable: DATE :=DATE#2001-09-11;

HourVariable: TOD := TOD#12:34:56.789;

(*output*)

OutputPLCTime: stPLCTime;

Ingeteam Proprietary All Rights Reserved Pag. 390


END_VAR

OutputPLCTime:=DATE_AND_TOD_TO_stPLCTime(DateVariable,HourVariable);

(*2001-09-11 12:34:56.789 Tuesday*)

1.9.1.3 DT_TO_stPLCTime

1.9.1.3.1 Description

Function to make a conversion from DT to stPLCTime.

1.9.1.3.2 Syntax

FUNCTION DT_TO_stPLCTime : stPLCTime

VAR_INPUT

Input_DT:DT;

END_VAR

1.9.1.3.3 Input parameters

Input Parameter Name Type Description


Input_DT DT Value of the input date and time in DT format.
Tbl. 1.340 Input parameters of function FUNCTION DT_TO_stPLCTime.

1.9.1.3.4 Data Types

1.9.1.3.4.1 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing, the
WeekDay_I INT PLC_TIME function ignores this field, since the PLC calculates this value and writes
it in the clock automatically.
Tbl. 1.341 Fields of the stPLCTime structure.

Ingeteam Proprietary All Rights Reserved Pag. 391


1.9.1.3.5 Remarks

Returns a structure with the date and time value consisting of different fields for each element.

All that is required to use the DT_TO_stPLCTime function is the entry of the date and time
values in DT format (Input_DT). The function will return a stPLCTime type variable with all the
date and time information.

1.9.1.3.6 Example

PROGRAM Example

VAR

(*DT_TO_stPLCTime *)

(*input variable*)

InputDT: DT := DT#2001-09-11-12:34:56.789;

(*output*)

OutputPLCTime: stPLCTime;

END_VAR

OutputPLCTime:=DT_TO_stPLCTime(InputDT);

(*2001-09-11 12:34:56.789 Tuesday*)

1.9.1.4 EXTRACT_BL

1.9.1.4.1 Description

Extract a bit out of a dword.

The EXTRACT_BL function extracts the value of the bit at the position that forms the input
DWORD. The function will return the TRUE or FALSE status of the indicated bit.

1.9.1.4.2 Syntax

FUNCTION EXTRACT_BL : BOOL

VAR_INPUT

Value_DW:DWORD;

BitNumber_BY:BYTE;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 392


1.9.1.4.3 Input parameters

Input Parameter Name Type Description


Value_DW DWORD Source variable from which to extract the value of a bit.
Position of the bit to be extracted.
BitNumber_BY BYTE
The positions will begin at 0 (least significant bit) and increment from right to left (0..31).
Tbl. 1.342 Input parameters of function FUNCTION EXTRACT_BL.

1.9.1.4.4 Remarks

Returns:

FALSE The value of the bit at the indicated position is 0.

TRUE The value OF the bit AT the indicated position is 1.

To use the EXTRACT_BL correctly, simply remember that the function will always return a
BOOL type variable with the value of the specified bit.

The position of the bit for which the status is to be obtained is specified in the BitNumber_BY
variable. The position is determined by considering the value 0 with the least significant bit of the
DWORD type source variable (Value_DW).

For example, if we call the EXTRACT_BL function with Value_DW:=2#110110 and


BitNumber_BY:=2, the function will return TRUE. However, if BitNumber_BY:=3; the function will
return FALSE.

1.9.1.4.5 Example

PROGRAM Example

VAR

Bit_i:BOOL;

Value : DWORD := 2#11110000110010;

Index :BYTE :=0;

END_VAR

(* Extracts one Bit *)

Bit_i := EXTRACT_BL(Value,Index );

Ingeteam Proprietary All Rights Reserved Pag. 393


1.9.1.5 INT_TO_BCD_BYTE

1.9.1.5.1 Description

The INT_TO_BCD_BYTE function converts a base 10 integer to its equivalent BCD code.

1.9.1.5.2 Syntax

FUNCTION INT_TO_BCD_BYTE : BYTE

VAR_INPUT

Input_I:INT;

END_VAR

1.9.1.5.3 Input parameters

Input Parameter Name Type Description


Input_I INT The variable with the value to be converted (0..99) to its representation in BCD.
Tbl. 1.343 Input parameters of function FUNCTION INT_TO_BCD_BYTE.

1.9.1.5.4 Remarks

Returns:

255 The function input parameter can not be represented in BCD in a BYTE.

0..99 (BCD) Value in BCD of the base 10 INT.

To use the INT_TO_BCD_BYTE function, all that is required is the call to the function with an
input parameter containing a value of base 10 INT type and for the result to be assigned to a
BYTE type variable.

Although the output function is coded in BCD, this does not imply that it must be represented in
binary format in the program. It can be represented in any of the forms permitted by the
programming environment.

1.9.1.5.5 Example

PROGRAM Example

VAR

(*INT_TO_BCD_BYTE*)

DataIn_INT: INT := 93 (* 16#5c *);

Ingeteam Proprietary All Rights Reserved Pag. 394


DataOut_BCD: BYTEEND_VAR

DataOut_BCD:=INT_TO_BCD_BYTE(DataIn_INT);

(*Output = 93 (16#93)*)

1.9.1.6 PACK_BL

1.9.1.6.1 Description

The PACK_BL function groups 8 BOOL type inputs in a BYTE type variable.

1.9.1.6.2 Syntax

FUNCTION PACK_BL : BYTE

VAR_INPUT

Bit0_BL:BOOL;

Bit1_BL:BOOL;

Bit2_BL:BOOL;

Bit3_BL:BOOL;

Bit4_BL:BOOL;

Bit5_BL:BOOL;

Bit6_BL:BOOL;

Bit7_BL:BOOL;

END_VAR

1.9.1.6.3 Input parameters

Input Parameter Name Type Description


Bit0_BL BOOL value of bit 0.
Bit1_BL BOOL value of bit 1.
Bit2_BL BOOL value of bit 2.
Bit3_BL BOOL value of bit 3.
Bit4_BL BOOL value of bit 4.
Bit5_BL BOOL value of bit 5.
Bit6_BL BOOL value of bit 6.
Bit7_BL BOOL value of bit 7.
Tbl. 1.344 Input parameters of function FUNCTION PACK_BL.

Ingeteam Proprietary All Rights Reserved Pag. 395


1.9.1.6.4 Remarks

Returns a BYTE with the value formed by the input bits (0..16#FF).

The use of this function is very simple. Simply assign the boolean value TRUE or FALSE
required for each position bit by bit from the Bit0_BL low bit to the Bit7_BL high bit.

1.9.1.6.5 Example

PROGRAM Example

VAR

(* PACK_BL *)

(* PackedValue = 2#00110010; *)

Bit0:BOOL :=0;

Bit1:BOOL :=1;

Bit2:BOOL :=0;

Bit3:BOOL :=0;

Bit4:BOOL :=1;

Bit5:BOOL :=1;

Bit6:BOOL :=0;

Bit7:BOOL :=0;

PackedValue : BYTE;

END_VAR

PackedValue := PACK_BL( Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7 );

(* PackedValue = 2#00110010; *)

1.9.1.7 PUTBIT_DW

1.9.1.7.1 Description

The PUTBIT_DW function is used to write a specific boolean value (TRUE or FALSE) in a
specific bit of a DWORD type variable.

Ingeteam Proprietary All Rights Reserved Pag. 396


1.9.1.7.2 Syntax

FUNCTION PUTBIT_DW : DWORD

VAR_INPUT

Value_DW:DWORD;

BitNumber_BY:BYTE;

BitValue_BL:BOOL;

END_VAR

1.9.1.7.3 Input parameters

Input Parameter Name Type Description


Value_DW DWORD Source variable containing the original value to be modified.
Position of the bit that is to be modified.
BitNumber_BY BYTE
The positions will begin at 0 (least significant bit) and increment from right to left (0..31).
BitValue_BL BOOL Value to be assigned to the selected bit.
Tbl. 1.345 Input parameters of function FUNCTION PUTBIT_DW.

1.9.1.7.4 Remarks

Returns a DWORD value formed by the input bits.

When using the PUTBIT_DW function, keep in mind that the value of a variable is not being
modified, but the composition of a DWORD type variable (Value_DW) is being used to modify
the value of one of its bits specified with BitNumber_BY. The desired value for this bit (TRUE or
FALSE) is indicated by the BitValue_BL variable.

The position of the bit for which the status is to be obtained is specified in the BitNumber_BY
variable. The position is determined by considering the value 0 with the least significant bit of the
DWORD type source variable (Value_DW).

The new modified value is obtained as an output OF the FUNCTION in a DWORD TYPE
variable.

1.9.1.7.5 Example

PROGRAM Example

VAR

(*PUTBIT_DW *)

Bit_i:BOOL:=TRUE;

Value : DWORD := 2#11000000111110000011110000110010;

Ingeteam Proprietary All Rights Reserved Pag. 397


Index :BYTE :=0;

END_VAR

(* Assign the value 5 to the index-th bit*)

Value := PUTBIT_DW(Value,Index,Bit_i);

1.9.1.8 RESET_SET

1.9.1.8.1 Description

Bistable function, reset dominant.

The RESET_SET function is a bistable function with priority RESET. The input variables can be
used to request the SET status (TRUE status at the output) or the RESET status (FALSE status
at the output). In the event of a conflict the RESET command will prevail.

1.9.1.8.2 Syntax

FUNCTION_BLOCK RESET_SET

VAR_INPUT

Set_BL:BOOL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.9.1.8.3 Input parameters

Input Parameter Name Type Description


Set_BL BOOL Input variable that contains the SET command.
Reset_BL BOOL Input variable that contains the RESET command.
Tbl. 1.346 Input parameters of function RESET_SET.

1.9.1.8.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the status requested by the input variables.
Tbl. 1.347 Output parameters of function RESET_SET.

Ingeteam Proprietary All Rights Reserved Pag. 398


1.9.1.8.5 Remarks

The RESET_SET function must have two BOOL type input parameters. One of the variables will
be assigned to the SET command and the other to the RESET command. The function will
calculate the status for the output according to the logic, with the RESET command having
priority.

Set_BL Reset_BL Out_BL

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE FALSE

1.9.1.8.6 Example

PROGRAM RESET_SET_Example

VAR

nTest : INT := 0;

(*RESET_SET*)

FlipFlopRS : RESET_SET := ( Out_BL :=0 );

END_VAR

CASE nTest OF

1: (* FlipFlop:RESET_SET *)

(*Use a FlipFlop*)

FlipFlopRS( Set_BL := TRUE ); (* => Out_BL=1*)

2: FlipFlopRS( Set_BL := FALSE ); (* => Out_BL= No change *)

3: FlipFlopRS( Reset_BL := TRUE ); (* => Out_BL=0*)

4: FlipFlopRS( Reset_BL := FALSE ); (* => Out_BL=0*)

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 399


1.9.1.9 SET_RESET

1.9.1.9.1 Description

Bistable function, set dominant.

The SET_RESET function is a bistable function with priority SET. The input variables can be
used to request the SET status (TRUE status at the output) or the RESET status (FALSE status
at the output). In the event of a conflict the SET command will prevail.

1.9.1.9.2 Syntax

FUNCTION_BLOCK SET_RESET

VAR_INPUT

Set_BL:BOOL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.9.1.9.3 Input parameters

Input Parameter Name Type Description


Set_BL BOOL Input variable that contains the SET command.
Reset_BL BOOL Input variable that contains the RESET command.
Tbl. 1.348 Input parameters of function SET_RESET.

1.9.1.9.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the status requested by the input variables.
Tbl. 1.349 Output parameters of function SET_RESET.

Ingeteam Proprietary All Rights Reserved Pag. 400


1.9.1.9.5 Remarks

The SET_RESET function must have two BOOL type input parameters. One of the variables will
be assigned to the SET command and the other to the RESET command. The function will
calculate the status for the output according to the logic, with the SET command having priority.

Set_BL Reset_BL Out_BL

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE TRUE

1.9.1.9.6 Example

PROGRAM SET_RESET_Example

VAR

nTest : INT := 0;

(*SET_RESET*)

FlipFlopSR : SET_RESET := ( Out_BL :=0 );

END_VAR

CASE nTest OF

1: (* FlipFlop:SET_RESET *)

(*Use a FlipFlop*)

FlipFlopSR( Set_BL:= TRUE ); (* => Out_BL=1*)

2: FlipFlopSR( Set_BL:= FALSE ); (* => Out_BL= No change *)

3: FlipFlopSR( Reset_BL := TRUE ); (* => Out_BL=0*)

4: FlipFlopSR( Reset_BL := FALSE ); (* => Out_BL=0*)

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 401


1.9.1.10 stPLCTime_TO_DATE

1.9.1.10.1 Description

The stPLCTime_TO_DATE function extracts the date information in stPLCTime format to DATE
type data.

1.9.1.10.2 Syntax

FUNCTION stPLCTime_TO_DATE : DATE

VAR_INPUT

Input_stPLCTime:stPLCTime;

END_VAR

1.9.1.10.3 Input parameters

Input Parameter Name Type Description


Structure with the date and time value consisting of different fields for each
Input_stPLCTime stPLCTime
element.
Tbl. 1.350 Input parameters of function FUNCTION stPLCTime_TO_DATE.

1.9.1.10.4 Data Types

1.9.1.10.4.1 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing,
WeekDay_I INT the PLC_TIME function ignores this field, since the PLC calculates this value
and writes it in the clock automatically.
Tbl. 1.351 Fields of the stPLCTime structure.

Ingeteam Proprietary All Rights Reserved Pag. 402


1.9.1.10.5 Remarks

Returns a DATE type structure obtained from the source variable Input_stPLCTime.

All that is required to use the stPLCTime_TO_DATE function is the entry of the date and time
values in stPLCTime format (Input_ stPLCTime). The function will return a DATE type variable
with the date information.

1.9.1.10.6 Example

PROGRAM Example

VAR

(* stPLCTime_TO_DATE *)

(*input variable*)

(* InputDT: DT := DT#2001-09-11-12:34:56.789;*)

InputPLCTime: stPLCTime;

(*output*)

OutputDate :DATE;

END_VAR

(*Prepare Input *)

InputPLCTime:=DT_TO_stPLCTime(InputDT);

(*2001-09-11 12:34:56.789 Tuesday*)

OutputDate:=stPLCTime_TO_DATE(InputPLCTime);

(*DATE#2001-09-11*)

Ingeteam Proprietary All Rights Reserved Pag. 403


1.9.1.11 stPLCTime_TO_DT

1.9.1.11.1 Description

Function to make a conversion from stPLCTime to DT.

1.9.1.11.2 Syntax

FUNCTION stPLCTime_TO_DT : DT

VAR_INPUT

Input_stPLCTime:stPLCTime;

END_VAR

1.9.1.11.3 Input parameters

Input Parameter Name Type Description


Structure with the date and time value consisting of different fields for each
Input_stPLCTime stPLCTime
element.
Tbl. 1.352 Input parameters of function FUNCTION stPLCTime_TO_DT.

1.9.1.11.4 Data Types

1.9.1.11.4.1 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing, the
WeekDay_I INT PLC_TIME function ignores this field, since the PLC calculates this value and writes
it in the clock automatically.
Tbl. 1.353 Fields of the stPLCTime structure.

1.9.1.11.5 Remarks

Returns a DT type structure obtained from the source variable Input_stPLCTime.

All that is required to use the stPLCTime_TO_DT function is the entry of the date and time
values in stPLCTime format (Input_ stPLCTime). The function will return a DT type variable with
all the date and time information.

Ingeteam Proprietary All Rights Reserved Pag. 404


1.9.1.11.6 Example

PROGRAM Example

VAR

(* stPLCTime_TO_DT *)

(*input variable*)

InputDT: DT := DT#2001-09-11-12:34:56.789;

InputPLCTime: stPLCTime;

(*output*)

OutputDT :DT;

END_VAR

(*Prepare Input *)

InputPLCTime:=DT_TO_stPLCTime(InputDT);

(*2001-09-11 12:34:56.789 Tuesday*)

(*Get DT*)

OutputDT:=stPLCTime_TO_DT(InputPLCTime);

(*DT#2001-09-11-12:34:56.789*)

Ingeteam Proprietary All Rights Reserved Pag. 405


1.9.1.12 stPLCTime_TO_TOD

1.9.1.12.1 Description

Function to make a conversion from stPLCTime to TOD.

1.9.1.12.2 Syntax

FUNCTION stPLCTime_TO_TOD : TOD

VAR_INPUT

Input_stPLCTime:stPLCTime;

END_VAR

1.9.1.12.3 Input parameters

Input Parameter Name Type Description


Structure with the date and time value consisting of different fields for each
Input_stPLCTime stPLCTime
element.
Tbl. 1.354 Input parameters of function FUNCTION stPLCTime_TO_TOD.

1.9.1.12.4 Data Types

1.9.1.12.4.1 stPLCTime

Field Name Type Description


Year_I INT Year, eg: 2002.
Month_I INT Month, eg: 1 = january.
Day_I INT Day of Month, eg: 23.
Hour_I INT Hour, eg: 23.
Minute_I INT Minute, eg: 2.
Seconds_I INT Second, eg: 23.
Miliseconds_I INT Milisecond, eg: 934.
Day of the week. 1 corresponds to Monday and 7 to Sunday. When writing, the
WeekDay_I INT PLC_TIME function ignores this field, since the PLC calculates this value and
writes it in the clock automatically.
Tbl. 1.355 Fields of the stPLCTime structure.

1.9.1.12.5 Remarks

Returns a TOD type structure obtained from the source variable Input_stPLCTime.

All that is required TO use the stPLCTime_TO_TOD FUNCTION is the entry OF the DATE AND
TIME values in stPLCTime format (Input_ stPLCTime). The FUNCTION will RETURN a TOD
TYPE variable with the TIME information.

Ingeteam Proprietary All Rights Reserved Pag. 406


1.9.1.12.6 Example

PROGRAM Example

VAR

(* stPLCTime_TO_TOD *)

(*input variable*)

(* InputDT: DT := DT#2001-09-11-12:34:56.789;*)

(* InputPLCTime: stPLCTime;*)

(*output*)

OutputTOD :TOD;

END_VAR

(*Prepare Input *)

InputPLCTime:=DT_TO_stPLCTime(InputDT);

(*2001-09-11 12:34:56.789 Tuesday*)

(*Get TOD*)

OutputTOD:=stPLCTime_TO_TOD(InputPLCTime);

(*TOD#12:34:56.789*)

1.9.1.13 UNPACK_BY

1.9.1.13.1 Description

Function block that unpacks a byte into 8 bits.

1.9.1.13.2 Syntax

FUNCTION_BLOCK UNPACK_BY

VAR_INPUT

Value_BY:BYTE;

END_VAR

VAR_OUTPUT

Bit0_BL:BOOL;

Bit1_BL:BOOL;

Ingeteam Proprietary All Rights Reserved Pag. 407


Bit2_BL:BOOL;

Bit3_BL:BOOL;

Bit4_BL:BOOL;

Bit5_BL:BOOL;

Bit6_BL:BOOL;

Bit7_BL:BOOL;

END_VAR

1.9.1.13.3 Input parameters

Input Parameter Name Type Description


Value_BY BYTE Byte to be unpacked.
Tbl. 1.356 Input parameters of function UNPACK_BY.

1.9.1.13.4 Output parameters

Output Parameter Name Type Description


Bit0_BL BOOL value of bit 0
Bit1_BL BOOL value of bit 1
Bit2_BL BOOL value of bit 2
Bit3_BL BOOL value of bit 3
Bit4_BL BOOL value of bit 4
Bit5_BL BOOL value of bit 5
Bit6_BL BOOL value of bit 6
Bit7_BL BOOL value of bit 7
Tbl. 1.357 Output parameters of function UNPACK_BY.

1.9.1.13.5 Remarks

To use the UNPACK_BY function correctly you must simply remember that the function will
interpret the value of the Value_BY input variable bit by bit. Depending on the value of each of
the bits, it will assign the corresponding TRUE or FALSE status to the Bit0_BL..Bit7_BL output
variables.

1.9.1.13.6 Example

PROGRAM Example

VAR

(*UNPACK_BY *)

Unpack : UNPACK_BY;

Ingeteam Proprietary All Rights Reserved Pag. 408


PackedValue:BYTE:= 2#00110010; (* byte to be unpacked *)

END_VAR

Unpack( Value_BY := PackedValue); (*2#00110010; *)

(* Unpack.Bit0_BL= 0 *)

(* Unpack.Bit1_BL= 1 *)

(* Unpack.Bit2_BL= 0 *)

(* Unpack.Bit3_BL= 0 *)

(* Unpack.Bit4_BL= 1 *)

(* Unpack.Bit5_BL= 1 *)

(* Unpack.Bit6_BL= 0 *)

(* Unpack.Bit7_BL= 0 *)

1.10 Standard_02

The following tables sumarize the entities contained in Standard_02:

Name Description
CONCAT_STR Concatenation of two strings.
DELETE_STR Function that deletes selected characters from a character string.
Function that searches for the position at which a character string begins within another string that is
FIND_STR
the basis of the search.
Function that generates a string with a user-specified format combining strings, data types and
FORMAT_STR
variables.
INSERT_STR Function that inserts a character string into another starting at an established position.
LEFT_STR Leftmost n characters of a given string.
LEN_STR String length function.
Returns a string with the number of characters specified beginning at a particular position of a source
MID_STR
string.
REPLACE_STR Funtion that replaces the characters of a source string.
RESET_SET Bistable function, reset dominant.
RIGHT_STR Function to extract a substring.
SET_RESET Bistable function, set dominant.
XOR_BUFFER This function calculates the exclusive OR of a byte buffer.
Tbl. 1.358 Functions, Function Blocks, and Programs.

Ingeteam Proprietary All Rights Reserved Pag. 409


1.10.1 Functions

1.10.1.1 CONCAT_STR

1.10.1.1.1 Description

Concatenation of two strings.

1.10.1.1.2 Syntax

FUNCTION CONCAT_STR : STRING(255)

VAR_INPUT

In1_STR:STRING(255);

In2_STR:STRING(255);

END_VAR

1.10.1.1.3 Input parameters

Input Parameter Name Type Description


In1_STR STRING(255) The first character string to be concatenated.
In2_STR STRING(255) The second character string to be concatenated.
Tbl. 1.359 Input parameters of function FUNCTION CONCAT_STR.

1.10.1.1.4 Remarks

Returns a STRING containing the result of the contatenation of In1_STR and In2_STR.

When using the CONCAT_STR function, the following should be kept in mind:

The maximum length of the input strings is 255 characters.

The maximum length of the output string is 255 characters. You must remember that the function
will not include the characters that do not fit in the string. Since the maximum length of the input
is also 255 characters, the output might be equal to In1_STR if its size is 255 characters.

If parameter In1_STR:='Hello' and parameter In2_STR:='John', the result of the CONCAT_STR


function will be 'HelloJohn'.

1.10.1.1.5 Example

PROGRAM Example

VAR

Ingeteam Proprietary All Rights Reserved Pag. 410


(*input parameters*)

InputString: STRING(255);

(*output parameter*)

OutputString: STRING(255);

END_VAR

InputString :='World';

OutputString := CONCAT_STR('Hello ' , InputString );

(* Output: 'Hello World' *)

1.10.1.2 DELETE_STR

1.10.1.2.1 Description

Function that deletes selected characters from a character string.

The function returns the modified source string as an output variable.

1.10.1.2.2 Syntax

FUNCTION DELETE_STR : STRING(255)

VAR_INPUT

In_STR:STRING(255);

Len_USI:USINT;

Pos_USI:USINT;

END_VAR

1.10.1.2.3 Input parameters

Input Parameter Name Type Description


In_STR STRING(255) Variable that contains the source character string from which to delete characters.
Len_USI USINT Number of characters that are going to be deleted from the source string.
Position from which to start deleting the characters.
Pos_USI USINT
Position 1 corresponds to the first character of the string, starting from the left.
Tbl. 1.360 Input parameters of function FUNCTION DELETE_STR.

Ingeteam Proprietary All Rights Reserved Pag. 411


1.10.1.2.4 Remarks

Returns the character string resulting from the deletion of the characters selected in the input
parameters.

To use the DELETE_STR correctly, please remember the following:

The maximum length of a source string (In_STR) is 255 characters.

Position 1 corresponds to the first character of the string, starting from the left.

1.10.1.2.5 Example

PROGRAM Example

VAR

(*input parameters*)

InputString: STRING(255);

(*output parameter*)

OutputString: STRING(255);

END_VAR

(*Input: Hello World. *)

(*Output: Hello W.*)

InputString :='Hello World.';

OutputString := DELETE_STR( InputString , 4, 8);

1.10.1.3 FIND_STR

1.10.1.3.1 Description

Function that searches for the position at which a character string begins within another string
that is the basis of the search.

1.10.1.3.2 Syntax

FUNCTION FIND_STR : USINT

VAR_INPUT

In1_STR:STRING(255);

In2_STR:STRING(255);

Ingeteam Proprietary All Rights Reserved Pag. 412


END_VAR

1.10.1.3.3 Input parameters

Input Parameter Name Type Description


In1_STR STRING(255) Variable that contains the source character string.
In2_STR STRING(255) Variable that contains the character string to be located.
Tbl. 1.361 Input parameters of function FUNCTION FIND_STR.

1.10.1.3.4 Remarks

Returns the character position of the beginning of the first occurence of In2_STR in In1_STR. If
no occurence of In2_STR is found, the result is 0. If the result is the first character of In1 STR,
the funtion returns 1.

1.10.1.3.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

FindString: STRING(255);

FoundPosition:INT;

END_VAR

(*BaseString: Hello World. *)

(*FindString: orld.*)

(*FoundPosition is 8*)

BaseString :='Hello World.';

FindString := 'orld';

FoundPosition:= FIND_STR(BaseString, FindString);

Ingeteam Proprietary All Rights Reserved Pag. 413


1.10.1.4 FORMAT_STR

1.10.1.4.1 Description

Function that generates a string with a user-specified format combining strings, data types and
variables.

The content of the string can vary in execution time and therefore a time variant string can be
generated based on the values of the variables that form it.

1.10.1.4.2 Syntax

FUNCTION_BLOCK FORMAT_STR

VAR_INPUT

Elements_stFormat_ADDR:DWORD;

ElementsSize_DI:DINT;

END_VAR

VAR_OUTPUT

FormattedString_STR:STRING(255);

Done_BL:BOOL;

Error_BL:BOOL;

Status_DI:DINT;

END_VAR

1.10.1.4.3 Input parameters

Input Parameter Name Type Description


The memory address of the structure or structure array of the stFormat type
Elements_stFormat_ADDR DWORD
that contains the elements that are to be formatted in the string type.
The size in bytes of the structure that contains the elements that are to be
ElementsSize_DI DINT
formatted in the string type.
Tbl. 1.362 Input parameters of function FORMAT_STR.

Ingeteam Proprietary All Rights Reserved Pag. 414


1.10.1.4.4 Output parameters

Output Parameter Name Type Description


FormattedString_STR STRING(255) Output string with the composition of all the specified data.
FALSE: The output string has not been created.
Done_BL BOOL
TRUE: The output string has not been created.
FALSE: The function has ended with no errors.
Error_BL BOOL
TRUE: The function has ended with errors.
Function Status
0: The function has presented no errors.
1: The value of the Elements_stFormat_ADDR input variable is incorrect.
2: One or more elements of the variable addressed at
Status_DI DINT Elements_stFormat_ADDR has an incorrect value in the FormatArg_STR
field
3: One or more elements of the variable addressed at
Elements_stFormat_ADDR has an incorrect format descriptor in the
FormatArg_STR field.
Tbl. 1.363 Output parameters of function FORMAT_STR.

1.10.1.4.5 Data Types

1.10.1.4.5.1 stFormat

Field Name Type Description


RealValue_R REAL
DintValue_DI DINT
DwordValue_DW DWORD
CharValue_BY BYTE
StrValue_STR STRING(255)
FormatArg_STR STRING(20)
Tbl. 1.364 Fields of the stFormat structure.

1.10.1.4.6 Remarks

The FORMAT_STR function is used to obtain an output of a string of up to 255 characters


consisting of data, variables or strings entered by the user, for which the execution time can be
modified.

The inputs of the function are a pointer to a variable that contains the format and variables that
the user wishes to convert into a string (Elements_stFormat_ADDR) and the size of the
addressed variable (ElementsSize_DI).

This addressed variable must be of a specific data type (stFormat). It can be a simple variable of
this type if a single element is to be converted to a string or a structure array if we wish to
concatenate various fields in a formatted manner.

The stFormat structure consists of a field for each type of data admitted (real, double integer,
double Word, bytes or 255 character string) and a field with a format descriptor
(FormatArg_STR). Each format descriptor is associated with the field for its type of associated

Ingeteam Proprietary All Rights Reserved Pag. 415


data. When selecting a format descriptor from among all the structure fields we are selecting the
structure field that corresponds to that descriptor.

In the case of a structure array, the format descriptor can be varied in each position of the array,
depending on user requirements, so various types of data can be combined in a string.

It is important to remember to maintain the relation between the format descriptor and the
structure field that contains the variable of the specific data type.

When using the format descriptors, extensions can be included to specify the number of digits to
the left and right of the decimal points (in the case of real data). For example, '%2.3f' is used to
obtain two digits to the left of the point (tens) and three to the right (thousandths).

1.10.1.4.7 Example

PROGRAM Example

VAR

(*FUNCTION declaration*)

StringFormat: FORMAT_STR;

(*input parameters*)

BufferFormat: ARRAY [0..9] OF stFormat;

(*Output Parameters*)

FormattedString_STR: STRING(250);

Done: BOOL;

Error: BOOL;

Status_formatStr: DINT;

END_VAR

(*StringFormat: FORMAT_STR;*)

(*preparation OF the formatted data*)

BufferFormat[0].FormatArg_STR:='%s';

BufferFormat[0].StrValue_STR:='Integer formats:\n';

(*---------------------- NUMERICALS---------------------*)

BufferFormat[1].FormatArg_STR:='%s';

BufferFormat[1].StrValue_STR:='Numericals:';

(*---------------------- DINT ----------------------------*)

Ingeteam Proprietary All Rights Reserved Pag. 416


BufferFormat[2].FormatArg_STR:='%d ';

BufferFormat[2].DintValue_DI:=-10;

(*---------------------- DWORD ----------------------------*)

BufferFormat[3].FormatArg_STR:='%u ';

BufferFormat[3].DwordValue_DW:=20;

(*---------------------- REAL ----------------------------*)

BufferFormat[4].FormatArg_STR:='%2f';

BufferFormat[4].RealValue_R:=0.20;

(*---------------------- STRINGS AND CHARACTERS-----*)

BufferFormat[5].FormatArg_STR:='%s';

BufferFormat[5].StrValue_STR:='\nStrings and characters:';

(*---------------------- STRING ----------------------------*)

BufferFormat[6].FormatArg_STR:='%S';

BufferFormat[6].StrValue_STR:='Hello Wor';

(*---------------------- CHAR ----------------------------*)

BufferFormat[7].FormatArg_STR:='%c';

BufferFormat[7].CharValue_BY:=16#6C;

(*---------------------- CHAR ----------------------------*)

BufferFormat[8].FormatArg_STR:='%c';

BufferFormat[8].CharValue_BY:=16#64;

(*---------------------- CHAR ----------------------------*)

BufferFormat[9].FormatArg_STR:='%c\n';

BufferFormat[9].CharValue_BY:=16#2E;

StringFormat(

Elements_stFormat_ADDR:=ADR(BufferFormat),

ElementsSize_DI:=SIZEOF(BufferFormat) ,

FormattedString_STR=>FormattedString_STR ,

Done_BL=>Done,

Error_BL=>Error,

Status_DI=>Status_formatStr );(*

Ingeteam Proprietary All Rights Reserved Pag. 417


Output:

Integer formats: -10 20 0.2

Strings and characters: Hello World.

*)

1.10.1.5 INSERT_STR

1.10.1.5.1 Description

Function that inserts a character string into another starting at an established position.

1.10.1.5.2 Syntax

FUNCTION INSERT_STR : STRING(255)

VAR_INPUT

In1_STR:STRING(255);

In2_STR:STRING(255);

Pos_USI:USINT;

END_VAR

1.10.1.5.3 Input parameters

Input Parameter Name Type Description


Variable that contains the source character string where the second string will be
In1_STR STRING(255)
inserted.
In2_STR STRING(255) Variable that contains the character string to be inserted in the source string.
Position from which the In2_STR string is to be inserted into the In1_STR source
string.
Pos_USI USINT
Pos_I = 0 inserts before the first character.
Pos_I = 1 inserts after the first character.
Tbl. 1.365 Input parameters of function FUNCTION INSERT_STR.

1.10.1.5.4 Remarks

Returns a character string with the In2_STR string inserted into the In1_STR string starting at the
indicated position.

To use the INSERT_STR correctly, remember the following:

The maximum length of the input strings (In1_STR and In2_STR) is 255 characters.

Ingeteam Proprietary All Rights Reserved Pag. 418


The output string has a maximum length of 255. If the composition of In1_STR and In2_STR
exceeds this limit, the output string will only show the first 255 characters.

1.10.1.5.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

IncludeString: STRING(255);

OutputString: STRING(255);

END_VAR

BaseString := 'HowYou?';

IncludeString := ' are ' ;

(*OutputString How are You?*)

OutputString :=INSERT_STR(BaseString,IncludeString, 3);

1.10.1.6 LEFT_STR

1.10.1.6.1 Description

Leftmost n characters of a given string.

Extracts the first (leftmost) Len_USI characters from this STRING and obtains a copy of the
extracted STRING. If Len_USI exceeds the string length, then the entire string is extracted.

1.10.1.6.2 Syntax

FUNCTION LEFT_STR : STRING(255)

VAR_INPUT

In_STR:STRING(255);

Len_USI:USINT;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 419


1.10.1.6.3 Input parameters

Input Parameter Name Type Description


Variable that contains the source character string from which to extract the
In_STR STRING(255)
requested characters.
Number of characters, beginning with the leftmost character, that will be extracted
Len_USI USINT
from the source string.
Tbl. 1.366 Input parameters of function FUNCTION LEFT_STR.

1.10.1.6.4 Remarks

Returns a character string with the string extracted from the In_STR source string.

If, for example, the LEFT_STR function is called with the parameters In_STR:='Hello' and
Len_USI:=2, the function will return the string 'He' as the result.

1.10.1.6.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

OutputString: STRING(255);

END_VAR

BaseString :='Hello.';

(*OutputString He*)

OutputString :=LEFT_STR(BaseString, 2);

1.10.1.7 LEN_STR

1.10.1.7.1 Description

String length function.

1.10.1.7.2 Syntax

FUNCTION LEN_STR : USINT

VAR_INPUT

In_STR:STRING(255);

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 420


1.10.1.7.3 Input parameters

Input Parameter Name Type Description


In_STR STRING(255) Variable that contains the character string that we want to know the length of.
Tbl. 1.367 Input parameters of function FUNCTION LEN_STR.

1.10.1.7.4 Remarks

Returns the number of characters in the string in In_STR.

For example, if the LEN_STR function is called with the input parameter In_STR:='Hello', the
function returns 5.

1.10.1.7.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

LenStr:INT;

END_VAR

BaseString :='Hello';

(*LenStr 5*)

LenStr :=LEN_STR(BaseString);

1.10.1.8 MID_STR

1.10.1.8.1 Description

Returns a string with the number of characters specified beginning at a particular position of a
source string.

1.10.1.8.2 Syntax

FUNCTION MID_STR : STRING(255)

VAR_INPUT

In_STR:STRING(255);

Len_USI:USINT;

Pos_USI:USINT;

Ingeteam Proprietary All Rights Reserved Pag. 421


END_VAR

1.10.1.8.3 Input parameters

Input Parameter Name Type Description


In_STR STRING(255) Variable that contains the character string from which to extract the partial string.
Len_USI USINT Number of characters that are going to be extracted from the source string.
Starting position from which the characters of the source string are going to be
Pos_USI USINT extracted
. Position 1 corresponds to the first character of the string beginning from the left.
Tbl. 1.368 Input parameters of function FUNCTION MID_STR.

1.10.1.8.4 Remarks

To use the MID_STR correctly, the following should be kept in mind:

The maximum length of the source character string (In_STR) is 255 characters.

Position 1 corresponds to the first character of the string beginning from the left.

1.10.1.8.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

OutputString: STRING(255);

END_VAR

BaseString :='Hello'; (*OutputString ll*)

OutputString :=MID_STR(BaseString, 2,3);

1.10.1.9 REPLACE_STR

1.10.1.9.1 Description

Funtion that replaces the characters of a source string.

It replaces the selected number of characters in the chosen position with another string of
characters.

1.10.1.9.2 Syntax

FUNCTION REPLACE_STR : STRING(255)

Ingeteam Proprietary All Rights Reserved Pag. 422


VAR_INPUT

In1_STR:STRING(255);

In2_STR:STRING(255);

Len_USI:USINT;

Pos_USI:USINT;

END_VAR

1.10.1.9.3 Input parameters

Input Parameter Name Type Description


Variable that contains the character string in which to replace the characters with
In1_STR STRING(255)
a new string.
Variable that contains the character string to be inserted in the source string to
In2_STR STRING(255)
replace the other characters.
Len_USI USINT Number of characters that are going to be replaced from the source string.
Starting position from which the characters of the source string are going to be
Pos_USI USINT replaced.
Position 1 corresponds to the first character of the string beginning from the left.
Tbl. 1.369 Input parameters of function FUNCTION REPLACE_STR.

1.10.1.9.4 Remarks

Returns the character string resulting from the replacement of the selected characters in
In1_STR by the new string In2_STR.

To use the REPLACE_STR correctly, the following should be kept in mind:

The maximum length of the input character strings (In1_STR and In2_STR) is 255 characters.

The maximum length of the character string returned by the function is 255 characters. It should
be noted that if the during the process of replacing the characters in In1_STR with the In2_STR
string the 255 characters limit is exceeded, then the function will only return the first 255
characters.

1.10.1.9.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

StringToInclude: STRING(255);

Length: USINT;

Position: USINT;

Ingeteam Proprietary All Rights Reserved Pag. 423


(*Output Parameters*)

OutputString:STRING(255);

END_VAR

BaseString :='HelloXYAll';

StringToInclude:='HowAreYou';

(*OutputString HelloHowAreYouAll*)

OutputString:=REPLACE_STR(BaseString, StringToInclude, 2, 6);

1.10.1.10 RESET_SET

1.10.1.10.1 Description

Bistable function, reset dominant.

The RESET_SET function is a bistable function with priority RESET. The input variables can be
used to request the SET status (TRUE status at the output) or the RESET status (FALSE status
at the output). In the event of a conflict the RESET command will prevail.

1.10.1.10.2 Syntax

FUNCTION_BLOCK RESET_SET

VAR_INPUT

Set_BL:BOOL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

1.10.1.10.3 Input parameters

Input Parameter Name Type Description


Set_BL BOOL Input variable that contains the SET command.
Reset_BL BOOL Input variable that contains the RESET command.
Tbl. 1.370 Input parameters of function RESET_SET.

Ingeteam Proprietary All Rights Reserved Pag. 424


1.10.1.10.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the status requested by the input variables.
Tbl. 1.371 Output parameters of function RESET_SET.

1.10.1.10.5 Remarks

The RESET_SET function must have two BOOL type input parameters. One of the variables will
be assigned to the SET command and the other to the RESET command. The function will
calculate the status for the output according to the logic, with the RESET command having
priority.

Set_BL Reset_BL Out_BL

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE FALSE

1.10.1.10.6 Example

PROGRAM RESET_SET_Example

VAR

nTest : INT := 0;

(*RESET_SET*)

FlipFlopRS : RESET_SET := ( Out_BL :=0 );

END_VAR

CASE nTest OF

1: (* FlipFlop:RESET_SET *)

(*Use a FlipFlop*)

FlipFlopRS( Set_BL := TRUE ); (* => Out_BL=1*)

2: FlipFlopRS( Set_BL := FALSE ); (* => Out_BL= No change *)

3: FlipFlopRS( Reset_BL := TRUE ); (* => Out_BL=0*)

4: FlipFlopRS( Reset_BL := FALSE ); (* => Out_BL=0*)

END_CASE;

Ingeteam Proprietary All Rights Reserved Pag. 425


1.10.1.11 RIGHT_STR

1.10.1.11.1 Description

Function to extract a substring.

Extracts the last (rightmost) Len_USI characters from this STRING and retrieves a copy of the
extracted STRING. If Len_USI exceeds the string length, the entire string is extracted.

1.10.1.11.2 Syntax

FUNCTION RIGHT_STR : STRING(255)

VAR_INPUT

In_STR:STRING(255);

Len_USI:USINT;

END_VAR

1.10.1.11.3 Input parameters

Input Parameter Name Type Description


Variable that contains the source character string from which to extract the
In_STR STRING(255)
requested characters.
Number of characters, beginning with the one furthest right, that will be
Len_USI USINT
extracted from the source string.
Tbl. 1.372 Input parameters of function FUNCTION RIGHT_STR.

1.10.1.11.4 Remarks

Returns a character string with the string extracted from the In_STR source string.

The maximum length of the source string (In_STR), and of the string returned by the function is
255 characters.

1.10.1.11.5 Example

PROGRAM Example

VAR

BaseString: STRING(255);

OutputString: STRING(255);

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 426


BaseString :='Hello';

(*OutputString lo*)

OutputString :=RIGHT_STR(BaseString, 2);

1.10.1.12 SET_RESET

1.10.1.12.1 Description

Bistable function, set dominant.

The SET_RESET function is a bistable function with priority SET. The input variables can be
used to request the SET status (TRUE status at the output) or the RESET status (FALSE status
at the output). In the event of a conflict the SET command will prevail.

1.10.1.12.2 Syntax

FUNCTION_BLOCK SET_RESET

VAR_INPUT

Set_BL:BOOL;

Reset_BL:BOOL;

END_VAR

VAR_OUTPUT

Out_BL:BOOL;

END_VAR

Ingeteam Proprietary All Rights Reserved Pag. 427


1.10.1.12.3 Input parameters

Input Parameter Name Type Description


Set_BL BOOL Input variable that contains the SET command.
Reset_BL BOOL Input variable that contains the RESET command.
Tbl. 1.373 Input parameters of function SET_RESET.

1.10.1.12.4 Output parameters

Output Parameter Name Type Description


Out_BL BOOL Output variable with the status requested by the input variables.
Tbl. 1.374 Output parameters of function SET_RESET.

1.10.1.12.5 Remarks

The SET_RESET function must have two BOOL type input parameters. One of the variables will
be assigned to the SET command and the other to the RESET command. The function will
calculate the status for the output according to the logic, with the SET command having priority.

Set_BL Reset_BL Out_BL

FALSE FALSE FALSE

TRUE FALSE TRUE

FALSE TRUE FALSE

TRUE TRUE TRUE

1.10.1.12.6 Example

PROGRAM SET_RESET_Example

VAR

nTest : INT := 0;

(*SET_RESET*)

FlipFlopSR : SET_RESET := ( Out_BL :=0 );

END_VAR

CASE nTest OF

1: (* FlipFlop:SET_RESET *)

(*Use a FlipFlop*)

FlipFlopSR( Set_BL:= TRUE ); (* => Out_BL=1*)

2: FlipFlopSR( Set_BL:= FALSE ); (* => Out_BL= No change *)

Ingeteam Proprietary All Rights Reserved Pag. 428


3: FlipFlopSR( Reset_BL := TRUE ); (* => Out_BL=0*)

4: FlipFlopSR( Reset_BL := FALSE ); (* => Out_BL=0*)

END_CASE;

1.10.1.13 XOR_BUFFER

1.10.1.13.1 Description

This function calculates the exclusive OR of a byte buffer.

1.10.1.13.2 Syntax

FUNCTION_BLOCK XOR_BUFFER

VAR_INPUT

Buffer_ADDR:DWORD;

BufferSize_DI:DINT;

END_VAR

VAR_OUTPUT

XorValue_BY:BYTE;

Status_enStandardRet:enStandardRet;

END_VAR

1.10.1.13.3 Input parameters

Input Parameter Name Type Description


Buffer_ADDR DWORD Points to the first byte in the buffer.
BufferSize_DI DINT Size, in bytes, ot the Buffer.
Tbl. 1.375 Input parameters of function XOR_BUFFER.

1.10.1.13.4 Output parameters

Output Parameter Name Type Description


XorValue_BY BYTE Value of the calculated Xor.
Status_enStandardRet enStandardRet Status dword wich the function returns when it has finished running.
Tbl. 1.376 Output parameters of function XOR_BUFFER.

Ingeteam Proprietary All Rights Reserved Pag. 429


1.10.1.13.5 Data Types

1.10.1.13.5.1 enStandardRet

Value Description
OK_STANDARD (0)
ERR_INVALID_ADDRESS_BUFFER (1)
ERR_WRONG_FORMAT (2)
ERR_TYPE_UNKNOWN_FORMAT (3)
ERR_NUMBER_OF_BUFFER_BYTES (4)
Tbl. 1.377 Enumerator enStandardRet.

Ingeteam Proprietary All Rights Reserved Pag. 430


1.11 Appendix I: enComsRet

Value Description
OK_COMS (0) The function has been executed correctly.
ERR_USART_BUSY (1) The USART selected is busy.
ERR_MODULE_NOT_PRESENT (2) The MODULE selected is not present.
ERR_USART_UNCONFIGURE (3) The USART selected is not configurable.
OK_COMS_DISCONNECT (4) The USART selected is properly disconnected.
ERR_NO_SPACE_FOR_RX_MESSAGE (5) The message does not fit.
ERR_NO_MSG (6) No message
ERR_INACTIVE_USART (7) The USART selected is inactive.
ERR_IDENTIFIER_USART (8) Erroneous ID Usart.
ERR_TX_TOO_LONG (9) The TX message is too long.
ERR_TX_NOT_FINISHED (10) Tx not finished
ERR_TX_NOT_ENABLED (11) Tx not enabled
ERR_RX_NOT_ENABLED (12) Rx not enabled
ERR_MODULE_TYPE (13) Module type erroneous
ERROR_RESOURCE_NUM (14) Resource module erroneous
ERR_PROTOCOL_TYPE (20) ETHERNET: Protocol type incorrect
ETHERNET: Erroneous value for ConnectionEstablishment_I
ERR_CONNECTION_ESTABLISHMENT (21)
parameter
ERR_NET_NUM (22) ETHERNET: Network connector number error
ERR_CONNECTION_NUM (23) ETHERNET: Connection number error
ERR_CONNECTION_LOST (26) ETHERNET: Connection lost
ERR_CONNECTION_PARAMETERS (32) USART in MODULE: Usart inactive
ERR_PROTOCOL_NOT_YET_IMPLEMENTED (33) USART in MODULE: Usart active but not operational
ERR_CHANNEL_NOT_YET_IMPLEMENTED (34) USART in MODULE: Usart active but not operational
ERR_Rx_TOO_LONG_FRAME (35) USART in MODULE: The frame is dismissed
ERR_End_of_Rx_Frame_Characters (36) USART in MODULE: The frame is dismissed
ERR_Incorrect_Data_in_the_Rx_Frame (37) USART in MODULE: Erroneous Data_in_the_Received_Frame
ERR_Number_of_Incorrect_data_in_the_Rx_Frame (38) USART in MODULE: The frame is dismissed
ERR_Tx_TOO_LONG_FRAME (39) USART in MODULE: The frame is not sent
USART in MODULE: The Tx queue is not empty after the tx time
ERR_Tx_Time_Delay (40)
delay : Left to send the frame
ERR_Wrong_Address_Slave (41) USART in MODULE: The frame is dismissed
ERR_Rx_Characters_TimeOut (42) USART in MODULE: The frame is dismissed
USART in MODULE: Activation Error CTS after RTS: The frame
ERR_Activation_CTS (43)
is not sent
ERR_Rx_Frames_TOO_Close_Together (44) USART in MODULE: The frame is dismissed
ERR_SERIE_PROTOCOL_TYPE (48) Protocol type incorrect
ERR_UNAVAILABLE_RESOURCE (49) Unavailable Resource
ERR_CHASSIS_SLOT_NUM (50) Chassis or slot number error.
ERR_STOP_BITS (51) Erroneous value for number of stop bits
ERR_BITS_PER_CHAR (52) Erroneous value for number of bits per character
ERR_PARITY (53) Parity error
ERR_CHANNEL_TYPE (54) Channel type error
ERR_SPEED (55) Configured speed is invalid
ERR_MESSAGE_END (56) Erroneous value for message end character
ERR_MESSAGE_END_DETECTION (57) End of message detection error
ERR_FRAME_RX_TIME (58) Erroneous value for frame reception time
ERR_RX_BUFFER_SIZE (59) Erroneous size of reception buffer
ERR_TX_BUFFER_SIZE (60) Erroneous size of transmission buffer
ERR_PAR1 (70) MODBUS: The parameter PAR1 of the Modbus protocol is not

Ingeteam Proprietary All Rights Reserved Pag. 431


Value Description
correct
MODBUS: The USART assigned to the slave is being used by
USART_BUSY (71)
another function
NO_MODULE (72) MODBUS: There is no communication module
USART_NO_INITIALIZE (73) MODBUS: The USART has not been initialized
ERR_DEINIT_USART (74) MODBUS: The USART is deinit
NO_SPACE_FOR_RX_MESSAGE (75) MODBUS: No space for Rx message
NO_MESSAGE (76) MODBUS: No message
USART_NO_ACTIVE (77) MODBUS: The USART is not active
ERR_ID_USART (78) MODBUS: The ID USART is not correct
ERR_TX_SIZE (79) MODBUS: The Tx size is not correct
ERR_TX (80) MODBUS: The Tx is not correct
ERR_TX_NOT_ALLOWED (81) MODBUS: The Tx is not allowed
ERR_RX_NOT_ALLOWED (82) MODBUS: The Rx is not allowed
ERR_MODBUS_MODULE_TYPE (83) MODBUS: The module type is not correct
ERROR_MODBUS_RESOURCE_NUM (84) MODBUS: The resource number is not correct
MODBUS: The number of retransmission of the master are
ERR_NUMBER_OF_RETRANSMISSION_FINISHED (85)
finished
ERROR_T_CICLO_NOT_INITIALIZED (86) MODBUS: The T_Ciclo is not initialized
ERROR_MODBUS_SLAVE_ADDR_WRONG (87) MODBUS: The slave address is wrong
ERROR_MODBUS_FUNCTION_SUBFUNCTION_WRONG
MODBUS: The function subfunction is wrong
(88)
MODBUS: The parameter PAR2 of the Modbus protocol is not
ERR_PAR2 (89)
correct
OPTION_NOT_IMPLEMENTED (90) MODBUS: Option not implemented
ERR_TX_MODE (91) MODBUS: Tx mode not correct
ERR_AGENT_TYPE_WRONG (92) MODBUS: Agent type wrong
MODBUS: INPUT, HOLDING or/and COILS buffers are too long.
ERR_ADDRESS (93)
Exceeds the task?s memory range
ERR_LCR (94) MODBUS: LCR of the message is not correct
ERR_CRC (95) MODBUS: CRC of the message is not correct
ERR_NBYTESRX (96) MODBUS: The number of bytes received is not correct
ERR_NBYTESTX (97) MODBUS: The number of bytes transmitted is not correct
ERR_TOO_LONG_MASTER_MSG (98) MODBUS: The master message is too long
ERR_0_BYTES_MASTER_MSG (99) MODBUS: The size of the master message is 0
ERR_INCORRECT_FRAME (100) MODBUS: The frame is not correct
ERR_ETHERNET (101) ETHERNET: Ethernet error
MODBUS: The parameter PAR4 of the Modbus protocol is not
ERR_PAR4 (102)
correct
MODBUS: The parameter PAR5 of the Modbus protocol is not
ERR_PAR5 (103)
correct
ERR_CONNECTION (124) ETHERNET: connection not made
NO_NEW_DATA (125) ETHERNET: No new data
CONNECTION_LOST (126) ETHERNET: Connection lost
ALREADY_CONNECTED (127) ETHERNET: Connection already established
ALREADY_CLOSED (128) ETHERNET: Connection already closed
ERR_PARAM_PARTNER (129) ETHERNET: Error in a communication parameter
ERR_CHANNEL_ID (130) ETHERNET: Incorrect channel Id
ETHERNET: The identifier given does not belong to any defined
ERR_ITEM_NUM (151)
item
ERR_SENDING_ITEM (152) ETHERNET: Error sending data
ERR_REQUESTING_ITEM (153) ETHERNET: Error requesting data
OUT_OF_RANGE (154) ETHERNET: Transaction out of range
ERR_TRAN_CYCLIC (155) ETHERNET: Transaction configured as cyclical cannot be used

Ingeteam Proprietary All Rights Reserved Pag. 432


Value Description
acyclically
ETHERNET: The communications module has still not started
COMS_MODULE_NOT_STARTED_UP (160)
up
COMS_MODULE_BUSY (161) ETHERNET: MODBUS: The communications module is busy
ERR_ILLEGAL_FUNCTION_SLAVE_MB (201) MODBUS: Illegal function slave
ERR_ILLEGAL_DATA_ADDRESS_SLAVE_MB (202) MODBUS: Illegal data address slave
ERR_ILLEGAL_DATA_VALUE_SLAVE_MB (203) MODBUS: Illegal data value slave
ERR_SLAVE_DEVICE_FAILURE_SLAVE_MB (204) MODBUS: Illegal slave device failure
ERR_ACKNOWLEDGE_SLAVE_MB (205) MODBUS: Error in acknowledge slave
ERR_SLAVE_DEVICE_BUSY_SLAVE_MB (206) MODBUS: Slave device busy
ERR_MEMORY_PARITY_ERROR_SLAVE_MB (208) MODBUS: Memory parity error
ERR_GATEWAY_PATH_UNAVAILABLE_SLAVE_MB (210) MODBUS: Gateway path unavailable
ERR_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
MODBUS: Gateway target device failed to respond slave
_SLAVE_MB (211)
ERR_RX_FRAME_FORMAT (300) C30: Rx frame format incorrect.
ERR_RX_MESSAGE_FOR_OTHER_STATION (301) C30: Received message for other station.
ERR_RX_CHECKSUM (302) C30: Rx checksum incorrect.
ERR_TX_BYTES_NUMBER (303) C30: Tx bytes number incorrect.
COMS_ALLOWED (400) Comunications allowed.
COMS_NOT_ALLOWED (401) Comunications not allowed.
USART in MODULE:There was an interruption of no data
ERR_WRONG_TIMEOUT_INTERRUPT (500)
timeout
ERR_OVERRUN_RX (512) USART in MODULE:Overrun in Rx
ERR_PARITY_RX (1024) USART in MODULE:Parity Error in Rx
ERR_FRAMING_RX (2048) USART in MODULE:Framing Error in Rx
ERR_FRAME_QUEUE_RX_FULL (8192) USART in MODULE:It has filled the queue of frames
ERR_RX_BREAK (16384) USART in MODULE:Break Error in Rx
ERR_QUEUE_RX_FULL (32768) USART in MODULE:It has filled the queue of characters in Rx
OK_COMS_ETH_DISCONNECT (-1)
Tbl. 1.378 Enumerator enComsRet.

Ingeteam Proprietary All Rights Reserved Pag. 433


Total or partial reproduction of this publication by an means or
procedure is prohibited without previous express written
authorisation by Ingeteam Power Technology.

One of the primary goals of Ingeteam Power Technology is the Parque Tecnolgico de Bizkaia-
continuous improvement of its equipment; consequently, the Edificio 110
48170 Zamudio (Bizkaia)
information contained in this catalogue may be modified without
Tel +34-944 039 600
previous notice. Fax +34-944 039 679

For further information, please refer to the manual or contact us. http://www.ingeteam.com

Ingeteam Proprietary All Rights Reserved Pag. 434


www.ingeteam.com

Das könnte Ihnen auch gefallen