Beruflich Dokumente
Kultur Dokumente
Soft Reference.
User Manual.
IC6451IKH05 Rev.C1
Table of contents
Table of contents................................................................................................................ 2
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
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
1.1.1.1.2 Syntax
FUNCTION_BLOCK ExtendedEthernetC30
VAR_INPUT
EnableComs_BL:BOOL;
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
1.1.1.1.6.1 enComsRet
( see Appendix I )
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.
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 format OF the frame in the C30 extended protocol is shown below:
Byte4: 68h
Byte6: 00h
: :
Byte6+X: UserDataX
Byte6+X+1: Checksum
Byte6+X+2: 16h
1.1.1.1.8 Example
PROGRAM C30ExampleProgram
VAR CONSTANT
END_VAR
VAR
(* ExtendedEthernetC30 FB *)
CommC30: ExtendedEthernetC30;
en : BOOL := TRUE;
(* Rx Tx control flags *)
flag_tx : BOOL;
flag_rx : BOOL;
sending : BOOL;
receiving : BOOL;
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=> ,
RxOK_BL=> ,
RxStationNum_US=> ,
NumMessageRx_US =>,
RxError_BL=> ,
NumBytesRx_US=> ,
CommStatus_enComsRet=> );
IF connected.Q
THEN
receiving := TRUE;
END_IF
IF CommC30.ConnectOK_BL
THEN
IF CommC30.RxOK_BL
THEN
rx_frame_num := rx_frame_num + 1;
sending := TRUE;
END_IF
IF CommC30.RxError_BL
THEN
rx_err_num := rx_err_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxOK_BL
tx_frame_num := tx_frame_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxError_BL
THEN
tx_err_num := tx_err_num + 1;
sending := TRUE;
END_IF
END_IF
IF sending
THEN
flag_tx := TRUE;
END_IF
IF receiving
THEN
flag_rx := TRUE;
END_IF
1.1.1.2.1 Description
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;
RxError_BL:BOOL;
CommStatus_enComsRet:enComsRet;
END_VAR
VAR_IN_OUT
FlagEnTx_BL:BOOL;
FlagEnRx_BL:BOOL;
END_VAR
1.1.1.2.6.1 enComsRet
( see Appendix I )
1.1.1.2.6.2 stSerialPortParam
1.1.1.2.7 Remarks
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
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 format of the frame in the C30 extended protocol is shown below:
Byte1: 68h
Byte4: 68h
Byte6: 00h
: :
Byte6+X: UserDataX
Byte6+X+1: Checksum
Byte6+X+2: 16h
PROGRAM C30ExampleProgram
VAR CONSTANT
END_VAR
VAR
(* SerialC30 FB *)
CommC30: ExtendedSerialC30;
en : BOOL := TRUE;
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;
connected : R_TRIG;
(* Statistical *)
rx_frame_num : DINT;
rx_err_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=> );
IF connected.Q
THEN
receiving := TRUE;
END_IF
IF CommC30.ConnectOK_BL
THEN
IF CommC30.RxOK_BL
THEN
rx_frame_num := rx_frame_num + 1;
sending := TRUE;
END_IF
IF CommC30.RxError_BL
THEN
rx_err_num := rx_err_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxOK_BL
THEN
tx_frame_num := tx_frame_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxError_BL
THEN
tx_err_num := tx_err_num + 1;
END_IF
END_IF
IF sending
THEN
flag_tx := TRUE;
END_IF
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;
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.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
( see Appendix I )
1.1.1.3.6.4 stSSICounterConf
1.1.1.3.7 Example
PROGRAM Example_ComsRIO
VAR
END_VAR
(*To use these example the user must define following STRUCTS:
STRUCT
DigitalInput_W: WORD;
Reserved_W: WORD;
Status_W: WORD;
END_STRUCT
END_TYPE
STRUCT
DigitalOutput_W: WORD;
Reserved_W: WORD;
AnalogOutput_R: REAL;
ServoGainCompensation_W: WORD;
ControlWord_W: WORD;
END_STRUCT
END_TYPE
STRUCT
TrunnionRadius_R: REAL;
LengthConstant_R: REAL;
AngleConstant_R: REAL;
MinCylinderLength_R: REAL;
MaxCylinderLength_R: 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;
END_STRUCT
END_TYPE*)
ActivationDelay_T:= T#1s ,
Output_BL=> ,
Status_DI=> );
IF TimerSendParam.Output_BL OR EnSendParams
THEN
ReqAction:=SEND_PARAMS;
Params_ADDR:=ADR(ParamsWrite);
Params_SIZEOF:=SIZEOF(ParamsWrite);
EnSendParams:=FALSE;
END_IF
IF EnReadParams
THEN
ReqAction:=READ_PARAMS;
Params_ADDR:=ADR(ParamsRead);
Params_SIZEOF:=SIZEOF(ParamsRead);
EnReadParams:=FALSE;
END_IF
ComunicationRIO(
EnComs_BL:=EnComs ,
SlaveAddr_DI:=SlaveAddr ,
ConfSerial_stRIO_ComSerialConf_ADDR:=ADR(ConfSerial) ,
InputData_ADDR:=ADR(RIO_Input) ,
InputDataBufferSizeBy_DI:=SIZEOF (RIO_Input) ,
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;
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.6.1 enComsRet
( see Appendix I )
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.
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.
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.
Byte1: 68h
Byte4: 68h
Byte6: 00h
: :
Byte6+X: UserDataX
Byte6+X+1: Checksum
Byte6+X+2: 16h
1.1.1.4.8 Example
PROGRAM C30ExampleProgram
VAR CONSTANT
END_VAR
VAR
(* SerialC30 FB *)
CommC30: SerialC30;
en : BOOL := TRUE;
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;
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(
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=> );
IF connected.Q
THEN
receiving := TRUE;
END_IF
IF CommC30.ConnectOK_BL
IF CommC30.RxOK_BL
THEN
rx_frame_num := rx_frame_num + 1;
sending := TRUE;
END_IF
IF CommC30.RxError_BL
THEN
rx_err_num := rx_err_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxOK_BL
THEN
tx_frame_num := tx_frame_num + 1;
receiving := TRUE;
END_IF
IF CommC30.TxError_BL
THEN
tx_err_num := tx_err_num + 1;
sending := TRUE;
END_IF
END_IF
IF sending
THEN
flag_tx := TRUE;
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;
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.6.1 enComsRet
( see Appendix I )
1.1.1.5.6.2 stSerialPortParam
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.
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.
Byte1: E5h
Byte2: A7h
Byte3: CDh
.. ..
Byte7+N: UserDataN
Byte7+N+1: ChecksumMSB
Byte7+N+2: ChecksumLSB
1.2 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.
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
1.2.1.1.5.1 enComsRet
( see Appendix I )
1.2.1.1.5.2 stTCPIP
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
VAR CONSTANT
Port1TcpConnectionNum_I:INT:=1;(*Connection number*)
Port1UdpConnectionNum_I:INT:=0;(*Connection number *)
(* Block Variables*)
VAR
END_VAR
VAR
counter : INT := 0;
END_VAR
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
VAR_INPUT
END_VAR
(*Variables de salida*)
VAR_OUTPUT
END_VAR
(*{library private}*)
VAR
END_VAR
(*low level FB which sends and waits for a reception with the same data*)
SendRec(
Enable_BL:=EnableTest ,
RxBuff_ADDR:=ADR (BufferRec) ,
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=> );
IF SendRec.RxOK_BL
THEN
IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)
THEN
ErrorAuxLongDatos:=TRUE;
END_IF;
BufferSend[0]:=BufferSend[0]+1;
DO
END_FOR;
END_IF;
THEN
ErrorAuxFunciones:=TRUE;
END_IF;
FUNCTION_BLOCK TcpEtherSendRecTrans
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
{library private}
VAR
Temp1: TON;
Temp2: TON;
Conectar: CONNECT;
Envio:BSEND;
Recep:BRCV;
Conexion:stTCPIP;
ActivarConexion: BOOL;
SendEn: BOOL;
RecEn: BOOL;
Enviando: BOOL;
Recibiendo: BOOL;
RecepAuxStatus_enComsRet: enComsRet;
recValue :DINT;
recValueModified :DINT;
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;
ActivarConexion:=Enable_BL;
SendEn :=FALSE;
RecEn :=FALSE;
Recibiendo:=FALSE;
Enviando :=FALSE;
ELSE
IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo
THEN
Enviando:=TRUE;
SendEn:=TRUE;
END_IF;
THEN
SendEn:=FALSE;
Enviando:=FALSE;
Recibiendo:=TRUE;
END_IF;
IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo
THEN
RecEn:=TRUE;
END_IF;
THEN
Recibiendo:=FALSE;
RecEn:=FALSE;
END_IF;
THEN
ActivarConexion:=FALSE;
SendEn :=FALSE;
RecEn :=FALSE;
Recibiendo:=FALSE;
Enviando :=FALSE;
END_IF;
END_IF;
(* CONNECT *)
Conectar (
EnC_BL:=ActivarConexion,
Valid_BL=>ConectOK_BL ,
Error_BL=>ConectError_BL ,
Status_enComsRet=>Status_ConectenComsRet,
Id_DI=> );
(* Timed to wait *)
Temp1(
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 ,
Rid_DI:=0 ,
Len_DI:=NumBytesTx_DI ,
Sd1_ADDR:=TxBuff_ADDR ,
Done_BL=>TxOK_BL ,
Error_BL=>TxError_BL ,
Status_enComsRet=>Status_TxComsRet );
IF Temp2.Q
THEN
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;
ComunicationStatus_enComsRet:=OK_COMS;
(*Prioriry definition: in the case of having some communication error status follows the following
priority:
IF Conectar.Status_enComsRet<>OK_COMS
THEN
ComunicationStatus_enComsRet:=Conectar.Status_enComsRet;
ELSE
IF Recep.Status_enComsRet<>OK_COMS OR
RecepAuxStatus_enComsRet<>OK_COMS
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;
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.5.1 enComsRet
( see Appendix I )
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
VAR CONSTANT
Port1UdpConnectionNum_I:INT:=0;(*Connection number*)
END_VAR
(* Block Variables*)
VAR
END_VAR
VAR
counter : INT := 0;
END_VAR
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
(*Input variables*)
VAR_INPUT
END_VAR
(*Variables de salida*)
VAR_OUTPUT
END_VAR
VAR
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=> ,
ComunicationStatus_enComsRet=> );
IF SendRec.RxOK_BL
THEN
IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)
THEN
ErrorAuxLongDatos:=TRUE;
END_IF;
BufferSend[0]:=BufferSend[0]+1;
DO
BufferSend[Ind]:=BufferSend[0]+Ind;
END_FOR;
END_IF;
THEN
ErrorAuxFunciones:=TRUE;
END_IF;
FUNCTION_BLOCK TcpEtherSendRecTrans
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
{library private}
VAR
Temp1: TON;
Temp2: TON;
Conectar: CONNECT;
Recep:BRCV;
Conexion:stTCPIP;
ActivarConexion: BOOL;
SendEn: BOOL;
RecEn: BOOL;
Enviando: BOOL;
Recibiendo: BOOL;
RecepAuxStatus_enComsRet: enComsRet;
recValue :DINT;
recValueModified :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;
ActivarConexion:=Enable_BL;
SendEn :=FALSE;
RecEn :=FALSE;
Recibiendo:=FALSE;
Enviando :=FALSE;
ELSE
IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo
THEN
Enviando:=TRUE;
SendEn:=TRUE;
END_IF;
THEN
SendEn:=FALSE;
Enviando:=FALSE;
Recibiendo:=TRUE;
END_IF;
IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo
THEN
RecEn:=TRUE;
END_IF;
THEN
Recibiendo:=FALSE;
END_IF;
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(
PT:=TxWaitTime_T ,
Q=> ,
ET=> );
Temp2(
IN:= Recibiendo ,
PT:=RxWaitTime_T ,
Q=> ,
(*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 );
IF Temp2.Q
THEN
RxError_BL:=TRUE;
RecepAuxStatus_enComsRet:=125; (*NO_NEW_DATA*)
(*Disables the receiving mark and enable the reception to activate a new transmission*)
Recibiendo:=FALSE;
END_IF;
ComunicationStatus_enComsRet:=OK_COMS;
(*Prioriry definition: in the case of having some communication error status follows the following
priority:
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;
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
1.2.1.3.5.1 enComsRet
( see Appendix I )
1.2.1.3.5.2 stGenModbusSerialConf
1.2.1.3.5.4 stModbusSlave
1.2.1.3.5.5 stModbusTCP
1.2.1.3.5.7 stTranspSerialConf
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:
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.
1.2.1.3.7 Example
PROGRAM PRG_Test_ComunicacionesEthernet
VAR CONSTANT
Port1TcpConnectionNum_I:INT:=1;(*Connection number*)
Port1UdpConnectionNum_I:INT:=0;(*Connection number*)
Port1UdpLocalConnectionPort_I:INT:=2345;(*Connection port number of the local UDP
communication port 1 *)
END_VAR
VAR
END_VAR
VAR
counter : INT := 0;
END_VAR
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
(*Input variables*)
END_VAR
(*Variables de salida*)
VAR_OUTPUT
END_VAR
(*{library private}*)
VAR
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) ,
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=> );
IF SendRec.RxOK_BL
THEN
IF SendRec.NumBytesRx_DI<>SIZEOF( BufferSend)
THEN
ErrorAuxLongDatos:=TRUE;
END_IF;
BufferSend[0]:=BufferSend[0]+1;
DO
BufferSend[Ind]:=BufferSend[0]+Ind;
END_IF;
THEN
ErrorAuxFunciones:=TRUE;
END_IF;
FUNCTION_BLOCK TcpEtherSendRecTrans
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
{library private}
VAR
Temp1: TON;
Temp2: TON;
Conectar: CONNECT;
Envio:BSEND;
Recep:BRCV;
Conexion:stTCPIP;
ActivarConexion: BOOL;
SendEn: BOOL;
RecEn: BOOL;
Enviando: BOOL;
Recibiendo: BOOL;
RecepAuxStatus_enComsRet: enComsRet;
recValue :DINT;
recValueModified :DINT;
Status_ConectenComsRet :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;
ActivarConexion:=Enable_BL;
SendEn :=FALSE;
RecEn :=FALSE;
Recibiendo:=FALSE;
Enviando :=FALSE;
ELSE
IF NOT SendEn AND Temp1.Q AND NOT Enviando AND NOT Recibiendo
THEN
Enviando:=TRUE;
SendEn:=TRUE;
END_IF;
SendEn:=FALSE;
Enviando:=FALSE;
Recibiendo:=TRUE;
END_IF;
IF NOT RecEn AND NOT SendEn AND NOT Enviando AND Recibiendo
THEN
RecEn:=TRUE;
END_IF;
THEN
Recibiendo:=FALSE;
RecEn:=FALSE;
END_IF;
THEN
ActivarConexion:=FALSE;
SendEn :=FALSE;
RecEn :=FALSE;
Recibiendo:=FALSE;
Enviando :=FALSE;
END_IF;
END_IF;
(* CONNECT *)
Conectar (
EnC_BL=ActivarConexion,
Partner_ADDR:=ADR(Conexion),
Error_BL=>ConectError_BL ,
Status_enComsRet=>Status_ConectenComsRet,
Id_DI=> );
(* Timed to wait *)
Temp1(
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 ,
Len_DI:=NumBytesTx_DI ,
Sd1_ADDR:=TxBuff_ADDR ,
Done_BL=>TxOK_BL ,
Error_BL=>TxError_BL ,
Status_enComsRet=>Status_TxComsRet );
IF Temp2.Q
THEN
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;
ComunicationStatus_enComsRet:=OK_COMS;
(*Prioriry definition: in the case of having some communication error status follows the following
priority:
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
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;
VAR_OUTPUT
Done_BL:BOOL;
Status_enComsRet:enComsRet;
END_VAR
1.2.1.4.5.1 enComsRet
( see Appendix I )
1.2.1.4.5.2 stModbusTCP
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.
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:
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.
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
temp.PT := t#1s;
temp();
THEN
communicating := TRUE;
sending := TRUE;
receiving := TRUE;
%QW2 := %QW2 + 1;
%QW3 := %QW3 + 2;
(* 2 items: *)
(* 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;
send();
sending := FALSE;
receiving := FALSE;
(* Do not attempt another send / recv until the previous one is finished *)
THEN
THEN
THEN
itemSend.StatusComs_enComsRet;
END_IF;
THEN
itemRecv.StatusComs_enComsRet;
END_IF;
communicating := FALSE;
END_IF;
END_IF;
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
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;
Error_BL:BOOL;
END_VAR
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.
1.3.1.1.5.3 stChassisIODiagnosticV1
1.3.1.1.5.4 stCPUDiagnosticV1
1.3.1.1.5.5 stCPUDiagnosticV2
1.3.1.1.5.7 StCPUDiagnosticV4
1.3.1.1.5.8 stIOStatusV1
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.
PROGRAM EXAMPLE
VAR
nTest :DINT := 0;
END_VAR
VAR
myCPUdiag:PLC_DIAGNOSTIC;
locCPUDiagnosticV1:stCPUDiagnosticV1;(*CPUv1, *)
locChassisIODiagnosticV1:stChassisIODiagnosticV1; (* I/Ov1cX *)
END_VAR
CASE nTest OF
myCPUdiag(
Enable_BL:= TRUE,
Reset_BL:= FALSE,
DiagnosticBuffer_ADDR:= ADR(locCPUDiagnosticV1),
DiagnosticBufferSizeBy_DI:= SIZEOF(locCPUDiagnosticV1),
Status_DI=> ,
Valid_BL=> ,
Error_BL=> );
myCPUdiag(
Enable_BL:= TRUE,
Reset_BL:= FALSE,
IdElement_STR:= 'I/Ov1c0',
DiagnosticBuffer_ADDR:= ADR(locChassisIODiagnosticV1),
DiagnosticBufferSizeBy_DI:= SIZEOF(locChassisIODiagnosticV1),
Status_DI=> ,
Valid_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.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.
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
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
1.3.1.3.3 Remarks
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
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.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
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;
en: BOOL:=TRUE;
done: BOOL;
END_VAR
(*SetNetConf : WRITE_CONFIGURATION;*)
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;
IdElement_STR:='NETc2v0',
ConfigurationBuffer_ADDR:=ADR(ntconfig),
ConfigurationBufferSizeBy_DI:=SIZEOF(ntconfig),
Status_enConfRet=> status,
Done_BL=> 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.
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.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
1.3.1.5.5.3 stConfEtherV0
1.3.1.5.5.4 stFwProtectionsV0
1.3.1.5.5.5 stReconfigRequestV0
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;
done: BOOL;
END_VAR
(*SetNetConf : WRITE_CONFIGURATIONv1;*)
ntconfig[0].Mask_STR :='255.255.255.0';
ntconfig[0].Gateway_STR:='0.0.0.0';
ntconfig[0].NICId_I:= 0;
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,
ConfigurationBuffer_ADDR:= ADR(ntconfig),
ConfigurationBufferSizeBy_DI:= SIZEOF(ntconfig),
Status_enConfRet=> status,
Done_BL=> done);
THEN
en := FALSE;
END_IF;
1.3.1.6 WRITE_LOG
1.3.1.6.1 Description
1.3.1.6.2 Syntax
VAR_INPUT
Enable_BL:BOOL;
Source_SI:SINT;
EventCode_I:INT;
ParameterList_STR:STRING(127);
CriticalyLevel_enCLevel:enCLevel;
PrivilegeLevel_SI:SINT;
END_VAR
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
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;
END_VAR
1.4 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;
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.
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*)
END_VAR
(*Create Directory*)
Done_BL =>,
Status_enDirRet => );
THEN
bEnableCreateDir := FALSE;
END_IF;
1.4.1.2.1 Description
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.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*)
Done_BL =>,
Status_enDirRet => );
THEN
bEnableRemoveDir:= FALSE;
END_IF;
1.4.1.3.1 Description
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.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
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;
END_VAR
Done_BL =>,
Status_enDirRet => );
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.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.
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;
StatusDirScan: enDirRet;
ContFindElem: UDINT;
END_VAR
IF EnDirScan
THEN
IF DirScan.Done_BL
THEN
EnDirScan:=FALSE;
StatusDirScan:=DirScan.Status_enDirRet;
END_IF;
DirScan(
Enable_BL:=EnDirScan ,
ScanName_STR:=DirToScan ,
Done_BL=> ,
FoundNewElement_BL=> ,
FoundElement_stScanData=> ,
Status_enDirRet=> );
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.
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.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.
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
Mode_STR:='Create' ,
FileName_STR :='\NewFileName',(*'\A\B\C\NewFileName' , *)
Id_DI=>,
Valid_BL=>,
Status_enFileRet => );
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.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
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).
PROGRAM FILE_DELETE_Example
VAR
FileDelete:FILE_DELETE;
enableDelete:BOOL :=TRUE;
END_VAR
FileName_STR:='\NewFileName',
Done_BL =>,
Status_enFileRet =>)
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
Done_BL:BOOL;
Status_enFileRet:enFileRet;
END_VAR
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
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.
PROGRAM FILE_READ_Example
VAR
FileCreate :FILE_CREATE;
iMode :INT := 1;
Id_DI :DINT;
(*Write*)
Write :FILE_WRITE;
END_VAR
CASE nTest OF
1: (* FileCreate:FILE_CREATE*)
Mode_STR:= Mode[iMode],
Id_DI=>,
Valid_BL=>,
Done_BL =>,
Status_enFileRet => );
THEN
FileCreate.Id_DI;
enableCreate := FALSE;
nTest := 2;
END_IF;
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
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
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.
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
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.
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.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.
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
THEN
encreate := TRUE;
IF fcreate.Done_BL
THEN
IF fcreate.Valid_BL
THEN
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;
IF fseek.Done_BL
THEN
IF fseek.Status_enFileRet = OK_FILE
THEN
enfread := TRUE;
END_IF;
enfseek := FALSE;
END_IF;
IF fread.Done_BL
enfread := FALSE;
encreate := FALSE;
run_example := FALSE;
END_IF;
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,
Done_BL=> ,
Status_enFileRet=> );
fread(
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
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
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
FileCreate :FILE_CREATE;
iMode :INT := 0;
Id_DI :DINT;
(*Write*)
Write :FILE_WRITE;
END_VAR
CASE nTest OF
1: (* FileCreate:FILE_CREATE*)
Mode_STR:= Mode[iMode],
Id_DI=>,
Valid_BL=>,
Done_BL =>,
Status_enFileRet => );
THEN
FileCreate.Id_DI;
enableCreate := FALSE;
nTest := 2;
END_IF;
Id_DI:= FileCreate.Id_DI ,
DataSourceBuffer_ADDR:=ADR( Buffer_Write ) ,
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
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
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
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:
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.
PROGRAM EXAMPLE
VAR CONSTANT
NUM_OF_WEEKEND_DAYS: DINT := 3;
BUFFER_SIZE:DINT := 376;
END_VAR
VAR
bListCreated: BOOL;
StrDay : STRING(32);
END_VAR
IF NOT bListCreated
THEN
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;
END_IF
END_IF
1.4.1.12.1 Description
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
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
1.4.1.12.6 Remarks
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.
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;
BUFFER_SIZE:DINT := 376;
END_VAR
VAR
bListCreated: BOOL;
bFridayInserted: BOOL;
bSaturdayInserted: BOOL;
bSundayInserted: BOOL;
idList: UDINT;
statusList: enListRet;
END_VAR
VAR
(*input parameters*)
StrDay : 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
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;
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,)*)
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 *)
(*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 => ,
CopyNBytes_DI =>CopiedBytes);
IF (OK_LIST = GetListElement.Status_enListRet)
THEN
bSaturdayFound := TRUE;
END_IF
END_IF
1.4.1.13 LIST_INSERT
1.4.1.13.1 Description
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
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
1.4.1.13.6 Remarks
The ElementToInsert.Data_ADDR field should contain a valid address from which to obtain the
associated data to insert.
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;
BUFFER_SIZE:DINT := 376;
END_VAR
VAR
bListCreated: BOOL;
bFridayInserted: BOOL;
bSaturdayInserted: BOOL;
bSundayInserted: BOOL;
idList: UDINT;
statusList: enListRet;
END_VAR
VAR
(*LIST_CREATE*)
StrDay : 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
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;
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,)*)
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 *)
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 => ,
CopyNBytes_DI =>CopiedBytes);
IF (OK_LIST = GetListElement.Status_enListRet)
THEN
bSaturdayFound := TRUE;
END_IF
END_IF
1.4.1.14 LIST_REMOVE
1.4.1.14.1 Description
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
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
1.4.1.14.6 Remarks
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.
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;
BUFFER_SIZE:DINT := 376;
END_VAR
VAR
bListCreated: BOOL;
bFridayInserted: BOOL;
bSaturdayInserted: BOOL;
bSundayInserted: BOOL;
idList: UDINT;
statusList: enListRet;
END_VAR
VAR
(*LIST_CREATE*)
StrDay : 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 );
Mode_STR := 'RemoveByName',
Status_enListRet => ,
CopyNBytes_DI =>CopiedBytes );
IF (OK_LIST = ListRemove.Status_enListRet)
THEN
END_IF
1.5 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
VAR_INPUT
B:BYTE;
END_VAR
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*)
(* 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
TIMELOW:TIME;
TIMEHIGH:TIME;
END_VAR
VAR_OUTPUT
OUT:BOOL;
END_VAR
1.5.1.2.5 Remarks
1.5.1.2.6 Example
PROGRAM EXAMPLE
VAR
(*BLINK*)
TIMEHIGH := T#1000ms,
TIMELOW := T#1500ms );
(*Output Parameters*)
OutputBlinkSignal: BOOL;
END_VAR
1.5.1.3 DERIVATIVE
1.5.1.3.1 Description
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
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;
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*)
(*function*)
END_VAR
(*Samples Counter*)
ELSE SamplesCounter:=1;
END_IF
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;
LOW:INT;
END_VAR
VAR_OUTPUT
OUT:BOOL;
END_VAR
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*)
(*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*)
HIGH:=UpperLimit,
LOW:=LowerLimit,
(*input assignment*)
IN:=InputVariable,
(*Output*)
1.5.1.5 INTEGRAL
1.5.1.5.1 Description
1.5.1.5.2 Syntax
FUNCTION_BLOCK INTEGRAL
VAR_INPUT
IN:REAL;
TM:DWORD;
RESET:BOOL;
END_VAR
OUT:REAL;
OVERFLOW:BOOL:=FALSE;
END_VAR
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 .
PROGRAM Example
VAR
(*INTEGRAL*)
(*Inputs*)
SamplesCounter:INT:=0;
-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*)
(*function*)
END_VAR
(*Samples Counter*)
ELSE SamplesCounter:=1;
END_IF
1.5.1.6.1 Description
1.5.1.6.2 Syntax
VAR_INPUT
I:INT;
END_VAR
1.5.1.6.4 Remarks
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*)
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.
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;
1.5.1.7.5 Remarks
The function will calculate the manipulated variable (Y) according to the following equation:
Where:
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*)
Input:REAL;
Output:REAL;
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
END_IF;
(*Regulator: PID*)
Regulator(ACTUAL:=Regulator.Y,
SET_POINT:=Input,
Y=>Output );
Regulator.RESET := Regulator.OVERFLOW;
1.6 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.
FUNCTION_BLOCK CTD
VAR_INPUT
CD:BOOL;
LOAD:BOOL;
PV:WORD;
END_VAR
VAR_OUTPUT
Q:BOOL;
CV:WORD;
END_VAR
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
3: CounterDown( CD :=FALSE);
5: CounterDown( CD :=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
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
3:CounterUp( CU :=TRUE);(*CV=1*)
4:CounterUp( CU :=FALSE);
6:CounterUp( CU :=FALSE);
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
QD:BOOL;
CV:WORD;
END_VAR
1.6.1.3.5 Remarks
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
1.6.1.3.6 Example
PROGRAM Example
VAR
CounterUpDown: CTUD ;
nTest:INT := 0;
END_VAR
CASE nTest OF
112:CounterUpDown( CD :=TRUE);(*CV=1*)
113:CounterUpDown( CD :=FALSE);
(*CounterUpDown.QD = TRUE *)
115:CounterUpDown( CD :=FALSE);
117:CounterUpDown( CD :=FALSE);
121:CounterUpDown( CU :=FALSE);
(*CounterUpDown.QU = TRUE *
123:CounterUpDown( CU :=FALSE);
124:CounterUpDown( CU :=TRUE);(*Q=TRUE*)
125:CounterUpDown( CU :=FALSE);
END_CASE;
1.6.1.4.1 Description
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.5 Remarks
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.
PROGRAM Example
VAR
(*F_TRIG*)
FallingEdgePulse :F_TRIG;
OutputPulsesCounter:INT := 0;
nTest:INT:=0;
END_VAR
CASE nTest OF
1: (* FallingEdgePulse:F_TRIG *)
IF(FallingEdgePulse.Q)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
IF(FallingEdgePulse.Q)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
END_CASE;
1.6.1.5 RS
1.6.1.5.1 Description
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.
FUNCTION_BLOCK RS
VAR_INPUT
SET:BOOL;
RESET1:BOOL;
END_VAR
VAR_OUTPUT
Q1:BOOL;
END_VAR
1.6.1.5.5 Remarks
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
PROGRAM Example
VAR
(*RS*)
FlipFlopRS : RS := ( Q1 :=0 ) ;
nTest : DINT := 0;
END_VAR
CASE nTest OF
1: (* FlipFlop:RS *)
(*Use a FlipFlop*)
END_CASE;
1.6.1.6 RTC
1.6.1.6.1 Description
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
CDT:DT;
END_VAR
1.6.1.6.5 Remarks
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;
END_VAR
CASE nTest OF
1: (* RunTimeCounter : RTC *)
(* Use a RunTimeCounter*)
RunTimeCounter( EN :=FALSE) ;
(*RunTimeCounter.Q = FALSE *)
(*RunTimeCounter.Q = TRUE *)
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
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
1.6.1.7.5 Remarks
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;
RisingEdgePulse(CLK:=TRUE);
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
END_CASE;
1.6.1.8 SR
1.6.1.8.1 Description
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.5 Remarks
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
1.6.1.8.6 Example
(*PROGRAM Example*)
VAR
(*SR*)
nTest:DINT:= 0;
END_VAR
CASE nTest OF
1:(* FlipFlop:SR*)
(*Use a FlipFlop*)
END_CASE;
1.6.1.9.1 Description
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.5 Remarks
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 *)
TimerOff(IN :=FALSE,
PT:= T#5s) ;
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
1.6.1.10.5 Remarks
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;
END_VAR
CASE nTest OF
1: (*Reset timer*)
TimerOn( IN :=FALSE );
2: (* TimerOn : TON *)
TimerOn(IN :=TRUE,
PT:= T#5s) ;
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
1.6.1.11.5 Remarks
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 ) ;
TimerPulse( IN :=TRUE,
PT:= T#3s) ;
END_CASE;
1.7 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.
1.7.1.1 BLINK_SIGNAL
1.7.1.1.1 Description
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
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).
1.7.1.1.6 Example
PROGRAM Example
VAR
(*BLINK*)
TimeLow_T := T#1000ms,
TimeHigh_T := T#1500ms ) ;
OutputBlinkSignal :BOOL;
END_VAR
1.7.1.2 COUNTER_DOWN
1.7.1.2.1 Description
1.7.1.2.2 Syntax
FUNCTION_BLOCK COUNTER_DOWN
VAR_INPUT
CounterDown_BL:BOOL;
Load_BL:BOOL;
StartValue_W:WORD;
VAR_OUTPUT
Out_BL:BOOL;
CounterValue_W:WORD;
END_VAR
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
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);
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
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*)
END_CASE;
1.7.1.4 COUNTER_UP_DOWN
1.7.1.4.1 Description
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;
1.7.1.4.5 Remarks
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.
PROGRAM Example
VAR
(*COUNTER_UP_DOWN *)
CounterUpDown : COUNTER_UP_DOWN;
nTest:INT := 0;
END_VAR
CASE nTest OF
(*Use a CounterUpDown*)
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;
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
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.
1.7.1.5.5.4 stIC3391Delay
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
(*Configuration to define the counter and inputs to use to measure the delay*)
Signal1Inverted_BL:=FALSE,(*Not inverted*)
END_VAR
DelayCounter(
CounterType_enCounterType:=IC3391,(*Module type*)
ChassisNum_DI:=0,(*Chasis number*)
SlotNum_DI:=7,(*Slot number*)
CounterConfigureSizeBy_DI:=SIZEOF(DelayCounterConf),(*Size of configuration
structure*)
1.7.1.6 DERIVATIVE_R
1.7.1.6.1 Description
1.7.1.6.2 Syntax
FUNCTION_BLOCK DERIVATIVE_R
VAR_INPUT
In_R:REAL;
TimeMsec_DW:DWORD;
END_VAR
VAR_OUTPUT
Out_R:REAL;
END_VAR
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 .
PROGRAM Example
VAR
(*RAMP_R*)
(*DERIVATIVE_R*)
(*Inputs*)
SamplesCounter:INT:=0;
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*)
(*function*)
END_VAR
(*Samples Counter*)
ELSE SamplesCounter:=1;
END_IF
1.7.1.7.1 Description
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.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.
PROGRAM Example
VAR
(*FALLING_TRIG*)
FallingEdgePulse :FALLING_TRIG;
OutputPulsesCounter:INT := 0;
nTest:INT :=0;
END_VAR
CASE nTest OF
1:(* FallingEdgePulse:F_TRIG *)
IF(FallingEdgePulse.Out_BL)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
IF(FallingEdgePulse.Out_BL)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
END_CASE;
1.7.1.8 FREQUENCY_MEASURE
1.7.1.8.1 Description
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.
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.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.
1.7.1.8.6 Example
PROGRAM Example
VAR
nTest:INT;
(*FREQUENCY_MEASURE*)
MeasureFreq:FREQUENCY_MEASURE:=(Periods_I :=8 );
ErrorOnMeasure:INT;
Tau:TIME :T#30ms;
END_VAR
CASE nTest OF
MeasureFreq(Reset_BL:=TRUE);
TimeHigh_T := Tau );
MeasureFreq( In_BL:=Signal.Out_BL,
Reset_BL:=FALSE);
(*MeasureFreq.Out_R = 1/60 HZ *)
END_IF
END_CASE;
1.7.1.9.1 Description
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
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.
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
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 *)
(*output signal*)
GeneratedSignal:=SignalGenerator.Out_I;;
1.7.1.10.1 Description
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
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;
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*)
High_I:=UpperLimit,
Low_I:=LowerLimit,
In_I:=InputVariable,
(*Output*)
1.7.1.11 INTEGRAL_R
1.7.1.11.1 Description
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
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;*)
-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*)
(*function*)
END_VAR
(*Samples Counter*)
ELSE SamplesCounter:=1;
END_IF
1.7.1.12 LIMIT_ALARM_REG
1.7.1.12.1 Description
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.
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
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;
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.
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
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.
(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*)
Volts:REAL;
END_VAR
Voltage2Degrees(In_R:= Volts,
(*output assignments*)
Out_R=>Temperature );
THEN
END_IF
1.7.1.14 PD_REG
1.7.1.14.1 Description
PD controller.
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
Y_R:REAL;
LimitsActive_BL:BOOL;
END_VAR
1.7.1.14.5 Remarks
The FUNCTION will calculate the manipulated variable (Y_R) according TO the following
equation:
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
(*PD_REG*)(* PD controller *)
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
PeriodUs_R:REAL;
Status_enCounterRet:enCounterRet;
END_VAR
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.
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
1.7.1.15.5.4 stIC3391Period
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
(*Configuration to define the counter and inputs to use to measure the period*)
Signal1Inverted_BL:=FALSE);(*Not inverted*)
END_VAR
CounterType_enCounterType:=IC3391,(*Module type*)
ChassisNum_DI:=0,(*Chasis number*)
SlotNum_DI:=7,(*Slot number*)
CounterConfigureSizeBy_DI:=SIZEOF(PeriodCounterConf),(*Size of configuration
structure*)
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.
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;
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.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 will calculate the manipulated variable (Y_R) according to the following equation:
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).
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
1.7.1.17 PID_REG
1.7.1.17.1 Description
PID controller.
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;
END_VAR
1.7.1.17.5 Remarks
The function will calculate the manipulated variable (Y_R) according to the following equation:
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*)
TimeLow_T := T#10000ms,
TimeHigh_T := T#10000ms ) ;
bBlinkSignal:BOOL;
rInputBlinkSignal :REAL;
END_VAR
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;
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.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.
1.7.1.18.5.5 stIC3325Position
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
Signal1Inverted_BL:=FALSE,(*Not inverted*)
Signal2Inverted_BL:=FALSE,(*Not inverted*)
CHAInverted_BL:=FALSE,(*Not inverted*)
module*)
END_VAR
PositionCounter(
CounterType_enCounterType:=IC3391,(*Module type*)
ChassisNum_DI:=0,(*Chasis number*)
SlotNum_DI:=7,(*Slot number*)
Write_BL:=EnWritePosition,(*Not used*)
ValueToWrite_R:=0,(*Not used*)
CounterConfigureSizeBy_DI:=SIZEOF(PositionCounterConf),(*Size of configuration
structure*)
HoldPositionRad_R=>,(*Not used*)
1.7.1.19 RAMP_I
1.7.1.19.1 Description
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;
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 .
PROGRAM Example
VAR
(*RAMP_I*)
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;
MaxAscend: INT := 2;
MaxDescend: INT:=3;
TimeBase: TIME;
Reset: BOOL;
Counter:INT;
Descend_I := 3);
END_VAR
END_FOR;
1.7.1.20.1 Description
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.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*)
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,
50,49,48,47,46,45,45,45,45,45,
9,8,7,6,5,4,3,2,1,0;
MaxAscendR: REAL := 2;
MaxDescendR: REAL:=3;
TimeBase: TIME;
Reset: BOOL;
Counter:INT;
Descend_R := 3,
TimeBase_T := T#0ms);
END_VAR
RampReal(In_R:=InputSignalR[ Counter ],
END_FOR;
1.7.1.21 READ_SSI_COUNTER
1.7.1.21.1 Description
1.7.1.21.2 Syntax
FUNCTION_BLOCK READ_SSI_COUNTER
VAR_INPUT
Enable_BL:BOOL;
CounterType_enCounterType:enCounterType;
ChassisNum_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.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.
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
PROGRAM Example_READ_SSI_COUNTER
VAR
SSICounterConf: stIC3392SSI := (
ConfSSI_stSSICounterConf_ST:=(
TminBetweenReadingsUS_I:=255));(*Minimum time
between readings*)
END_VAR
READ_SSI_COUNTER(
ChassisNum_DI:=0,(*Chasis number*)
SlotNum_DI:=8,(*Slot number*)
1.7.1.22.1 Description
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
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
IF(RisingEdgePulse.Out_BL)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
IF(RisingEdgePulse.Out_BL)
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
END_CASE;
1.7.1.23 RTC_TIMER
1.7.1.23.1 Description
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.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
(*RunTimeCounter.Out_BL = FALSE *)
(*RunTimeCounter.Out_BL = TRUE *)
(*RunTimeCounter.Current_DT = DT#1970-01-01-00:00:00 *)
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
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.
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
1.7.1.24.5.5 stIC3391Speed
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
(*Configuration to define the counter, type of encoder and inputs to use to measure the
encoders speed*)
SpeedCounterConf: stIC3391Speed := (
CHAInverted_BL:=FALSE,(*Not inverted*)
END_VAR
SpeedCounter(
ChassisNum_DI:=0,(*Chasis number*)
SlotNum_DI:=7,(*Slot number*)
CounterConfigureSizeBy_DI:=SIZEOF(SpeedCounterConf),(*Size of configuration
structure*)
1.7.1.25 STATISTICS_I
1.7.1.25.1 Description
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
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.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*)
Counter:INT;
END_VAR
FOR Counter:=-10 TO 10 BY 1 DO
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
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
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
Alpha:=INT_TO_REAL(Counter)/10;
END_FOR
(*TrigonometricStatistics.Min_R = -1
TrigonometricStatistics.Max_R = +1
*)
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
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*)
TimerPulse(In_BL:=TRUE,Length_T:=T#3s) ;
2: (*Reset timer*)
TimerPulse(In_BL :=FALSE ) ;
END_CASE;
1.7.1.28.1 Description
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.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 .
PROGRAM Example
VAR
(*TOF_ABSOLUTE *)
TimerOff: TOF_ABSOLUTE;
END_VAR
CASE nTest OF
TimerOff(In_BL :=FALSE);
END_CASE
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.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 .
PROGRAM Example
VAR
(*TOF_ABSOLUTE *)
TimerOn: TON_ABSOLUTE;
END_VAR
CASE nTest OF
TimerOn(In_BL:=FALSE,ActivationDelay_T:=T#5s);
2:(*Start timer on *)
END_CASE
1.7.1.30 VARIANCE_R
1.7.1.30.1 Description
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
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
FOR Dice:=1 TO 6 BY 1 DO
END_FOR
(* VarianceOnDice.Out_R = 2.91*)
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.
1.8.1.1 ASTAB_OFFON_ASYNC_DISC
1.8.1.1.1 Description
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.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=>,
1.8.1.2 ASTAB_OFFON_SYNC_DISC
1.8.1.2.1 Description
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.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=>);
1.8.1.3.1 Description
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.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=>);
1.8.1.4.1 Description
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.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=>);
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.
Where:
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
1.8.1.5.5.1 stCoordinate
1.8.1.5.6 Remarks
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 .
PROGRAM Example
VAR
(*function declaration*)
Interpolation: CHARCURVE_REAL;
(*input parameters*)
inputValue: REAL;
tablePointsNumber: INT := 5;
(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
PointsNum_I:= tablePointsNumber,
TablePoints_stCoordinate_ADDR:=ADR(table) );
outputValue:= Interpolation.Out_R;
statusInterpolation:= Interpolation.Status_BY;
1.8.1.6.1 Description
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
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.
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
1.8.1.6.5.7 stGateConf
1.8.1.6.5.9 stGenericCounterCfg
1.8.1.6.5.10 stGenericCounterConf
1.8.1.6.5.11 stGenericSTSFlags
1.8.1.6.5.13 stSpConf
1.8.1.6.6 Remarks
Identify the counter module type (generic or reduced) and use de appropiate structures
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;
Output1:REAL;
Enable: BOOL;
END_VAR
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;
(*******************************************************)
(*******************************************************)
FUNCTION_BLOCK PERIOD_COUNTER
(*Function to use the Generic counter (IC3325) for measuring the period of the signal on one
GATE*)
VAR_INPUT
(*CONFIGURATION Variables*)
(*Counter parametrs*)
(*Counter structures*)
CounterConfigure_ADRR:DWORD;
CounterConfigureSizeBy_DI:DINT;
END_VAR
VAR_OUTPUT
(*READ Variables*)
1-Error nChassis-nSlot
3-Error nCounter
END_VAR
(*{library private}*)
VAR
(*CONFIGURATION Variables*)
stIC3325PeriodConf:stIC3325Period;
Pointer_stIC3325PeriodConf:POINTER TO stIC3325Period;
stGenericCounterPeriod:stGenericCounterConf;
stGenericCounterConfiguration:stGenericCounterCfg;
stConfigurationGate0:stGateConf;
stPresetConfiguration:stCounterPreset;
stSPConfiguration:stCounterSp;
stGenericCounterRead:stGenericCounter;
HoldValue_DI:DINT;
(*AUXILIARY Variables*)
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 *)
IF (RiseEdgeDetection.Out_BL) THEN(* This checks if there has been a rising edge signal
Enable_BL *)
END_IF;
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^;
stGenericCounterConfiguration.Drm_BL:=TRUE;
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*)
stConfigurationGate0.InputNumberGate_BY:=INT_TO_BYTE(stIC3325PeriodConf.
InputSignal1_enIC3325InputSignal);(* physical input that is associated with GATE0
(0 .. 7) *)
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;
stGenericCounterPeriod.Gate0_stGateConf:=stConfigurationGate0;
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.PresetNumber_BY:=0;(*Aassociates the
PRESET 0 to gate1 *)
stGenericCounterPeriod.SP0_stCounterSp:=stSPConfiguration;(*Preset
parameters*)
CONFIGURATION.ChassisNum_DI:=ChassisNum_DI;
CONFIGURATION.SlotNum_DI:=SlotNum_DI;
CONFIGURATION.CounterNum_DI:=stIC3325PeriodConf.CounterNum_DI;
CONFIGURATION.CounterNum_stCounterConf_ADDR:=
ADR(stGenericCounterPeriod);
(*Output Values*)
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 *)
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;
(*Output Values*)
IF (stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL) THEN
Status_enCounterRet:=21;(*COUNTER OVERFLOW*)
END_IF;
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 .*)
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 *)
Done_BL:=TRUE;
(*OutputValues*)
HoldValue_DI:=stGenericCounterRead.HoldValue_DI;(*conversion of the
read hold data to 1e-06s*)
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*)
END_IF;
END_CASE;
1.8.1.7 COUNTER_DOWN
1.8.1.7.1 Description
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.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 .
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;
VAR_OUTPUT
Out_BL:BOOL;
CounterValue_W:WORD;
END_VAR
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 .
PROGRAM Example
VAR
CounterDown : COUNTER_DOWN;
nTest:INT := 0;
END_VAR
CASE nTest OF
1:(*CounterUp:COUNTER_UP*)(*Use a CounterUp*)
END_CASE;
1.8.1.9 COUNTER_UP_DOWN
1.8.1.9.1 Description
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
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
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.
1.8.1.9.6 Example
PROGRAM Example
VAR
(*COUNTER_UP_DOWN *)
CounterUpDown : COUNTER_UP_DOWN;
nTest:INT := 0;
END_VAR
CASE nTest OF
END_CASE;
1.8.1.10 FALLING_TRIG
1.8.1.10.1 Description
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;
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 *)
IF(FallingEdgePulse.Out_BL)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
IF(FallingEdgePulse.Out_BL)
THEN
OutputPulsesCounter := OutputPulsesCounter+1;
END_IF;
END_CASE;
1.8.1.11 FILTER
1.8.1.11.1 Description
The FILTER function performs first order low pass filtering of the input signal with a user-defined
time constant.
Yn=(t/(t+Tc))(Yn-1-Xn)+Xn
Where:
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;
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;
inputSignal: REAL;
(*output Parameters*)
outputSignal: REAL;
statusFilter: DINT;
(*signal generation*)
counter: INT;
THRESHOLD:INT:=1000;END_VAR
END_VAR
counter:=counter+1;
IF (counter>THRESHOLD) THEN
counter:=0;
END_IF;
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
END_VAR
VAR_OUTPUT
Output_BL:BOOL;
Status_DI:DINT;
END_VAR
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=>);
1.8.1.13.1 Description
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.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
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
1.8.1.13.5.6 stCounterSp
1.8.1.13.5.8 stGenericCounter
1.8.1.13.5.11 stGenericSTSFlags
1.8.1.13.5.12 stReducedCounter
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
stIC3325PeriodConfiguration.CounterNum_DI:=0;
stIC3325PeriodConfiguration.InputSignal1_enIC3325InputSignal:=G0;
stIC3325PeriodConfiguration.Signal1Inverted_BL:= FALSE;
(*Get Period*)
IC3325Period(
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;
(*******************************************************)
(*******************************************************)
FUNCTION_BLOCK PERIOD_COUNTER
(*Function to use the Generic counter (IC3325) for measuring the period of the signal on one
GATE*)
VAR_INPUT
CounterType_enCounterType:enCounterType;(*Counter Type*)
(*CONFIGURATION Variables*)
(*Counter parametrs*)
(*Counter structures*)
CounterConfigure_ADRR:DWORD;
CounterConfigureSizeBy_DI:DINT;
END_VAR
VAR_OUTPUT
(*READ Variables*)
(*0-Correct execution
1-Error nChassis-nSlot
3-Error nCounter
10-Error Internal
11-Counter Overflow*)
END_VAR
(*{library private}*)
VAR
(*CONFIGURATION Variables*)
stIC3325PeriodConf:stIC3325Period;
Pointer_stIC3325PeriodConf:POINTER TO stIC3325Period;
stGenericCounterPeriod:stGenericCounterConf;
stConfigurationGate0:stGateConf;
stPresetConfiguration:stCounterPreset;
stSPConfiguration:stCounterSp;
stGenericCounterRead: stGenericCounter;
HoldValue_DI: DINT;
(*AUXILIARY Variables*)
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 *)
IF (RiseEdgeDetection.Out_BL) THEN (* This checks if there has been a rising edge signal
Enable_BL *)
END_IF;
CASE (CounterType_enCounterType) OF(* Depending on the type of accountant to use the user
configuration is carried out by structures or other *)
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 *)
Pointer_stIC3325PeriodConf:=CounterConfigure_ADRR;
stIC3325PeriodConf:=Pointer_stIC3325PeriodConf^;
stGenericCounterConfiguration.Drm_BL:=TRUE;
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.Disarm_BL:=FALSE;
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.PresetNumber_BY:=0;(*
Aassociates the PRESET 0 to gate1 *)
stGenericCounterPeriod.SP0_stCounterSp:=stSPConfiguration;
(*Preset parameters*)
stPresetConfiguration;
CONFIGURATION.ChassisNum_DI:=ChassisNum_DI;
CONFIGURATION.SlotNum_DI:=SlotNum_DI;
CONFIGURATION.CounterNum_DI:=
stIC3325PeriodConf.CounterNum_DI;
ADR(stGenericCounterPeriod);
(*Output Values*)
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 *)
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;
(*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;
IF((READ.Status_enCounterRet<>0) OR
(stGenericCounterRead.StsFlags_stGenericSTSFlags.H2_BL))
THEN
ELSE
IF
(stGenericCounterRead.StsFlags_stGenericSTSFlags.H0_
BL AND
stGenericCounterRead.StsFlags_stGenericSTSFlags.RM
D_BL AND READ.Done_BL) THEN
Done_BL:=TRUE;
(*Output Values*)
HoldValue_DI:=
stGenericCounterRead.HoldValue_DI;
(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;
(* 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*)
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;
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
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
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
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);
THEN
OutputPulsesCounter:=OutputPulsesCounter+1;
END_IF;
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
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
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*)
(*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 = DT#1970-01-01-00:00:00 *)
END_CASE;
1.8.1.17 SP_GEN_REG_EMF_V
1.8.1.17.1 Description
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
FluxWeakeningMode_BL:BOOL;
YpEmf_R:REAL;
YiEmf_R:REAL;
SpExcIntensity_R:REAL;
Status_DI:DINT;
END_VAR
1.8.1.18.1 Description
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
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
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
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*)
TimerPulse(In_BL:=TRUE,
Length_T:=T#3s);
2: (*Reset timer*)
TimerPulse(In_BL:=FALSE);
END_CASE;
1.8.1.20.1 Description
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.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 .
PROGRAM Example
VAR
(*TOF_ABSOLUTE *)
TimerOff:TOF_ABSOLUTE;
nTest:INT:=0;
END_VAR
CASE nTest OF
1: (*Reset timer*)
TimerOff(In_BL :=TRUE,
DeactivationDelay_T:= T#5s);
2: (*Reset timer*)
TimerOff(In_BL :=FALSE);
END_CASE
1.8.1.21 TOF_RELATIVE
1.8.1.21.1 Description
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
DeactivationDelay_T:TIME;
END_VAR
VAR_OUTPUT
Output_BL:BOOL;
Status_DI:DINT;
END_VAR
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.
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*)
END_VAR
DeactivationDelay_T:=T#10s500ms);
delayedOutputSignal:=TofRelative.Output_BL;
status:=TofRelative.Status_DI;
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.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;
END_VAR
CASE nTest OF
TimerOn(In_BL:=FALSE,ActivationDelay_T:= T#5s);
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
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 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 .
PROGRAM TON_RELATIVE_Example
VAR
TonRelative:TON_RELATIVE;
input:BOOL;(*Input*)
status:DINT;(*Function Status
0-Correct Execution
1-ActivationDelay_T<0*)
END_VAR
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
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;
END_VAR
VAR_OUTPUT
Output_BL:BOOL;
Status_DI:DINT;
END_VAR
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.
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*)
status:DINT;(*Function Status
0-Correct Execution
1-ActivationDelay_T<0*)
END_VAR
TonofRelative(Input_BL:=input,
ActivationDelay_T:=T#10s500ms,
DeactivationDelay_T:=T#3s500ms);
delayedOutputSignal:=TonofRelative.Output_BL;
status:=TonofRelative.Status_DI;
1.8.1.25.1 Description
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.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
1.8.1.25.5.4 stCounterFlags
1.8.1.25.5.5 stIC3325Position
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
1.8.1.25.5.8 stCounterSp
1.8.1.25.5.11 stGenericCounterCfg
1.8.1.25.5.12 stGenericCounterConf
1.8.1.25.5.13 stGenericSTSFlags
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
stIC3325PositionConfiguration.CounterNum_DI:=0;
stIC3325PositionConfiguration.CHAInverted_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,
CounterConfigure_ADRR:=ADR (stIC3325PositionConfiguration),
PulsesPerTurn_I:= 100,
Done_BL=> ,
CurrentPositionRad_R=> ,
HoldPositionRad_R=> ,
Status_enCounterRet=> ,
Status_stCounterFlags=>
);
(*******************************************************)
(*******************************************************)
FUNCTION_BLOCK POSITION_COUNTER
(*Function to use the Generic counter (IC3325) for measuring the position of a signal on input
channel*)
VAR_INPUT
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*)
(*Counter structures*)
CounterConfigure_ADRR:DWORD;
CounterConfigureSizeBy_DI:DINT;
(*Coversion Parameters*)
END_VAR
VAR_OUTPUT
(*READ Variables*)
(*0-Correct execution
1-Error nChassis-nSlot
3-Error nCounter
10-Error Internal*)
END_VAR
{library private}
VAR
(*CONFIGURATION Variables*)
stIC3325PositionConf:stIC3325Position;
Pointer_stIC3325PositionConf:POINTER TO stIC3325Position;
stGenericCounterPosition:stGenericCounterConf;
stGenericCounterConfiguration:stGenericCounterCfg;
stConfigurationGate0:stGateConf;
stConfigurationGate1:stGateConf;
stPresetConfiguration:stCounterPreset;
stSPConfiguration:stCounterSp;
(*READ Variables*)
stGenericCounterRead:stGenericCounter;
(*READ Variables*)
(*AUXILIARY Variables*)
END_VAR
(* In the cycle in which there is a rising edge signal Enable_BL, there must be the counter
configuration*)
IF (RiseEdgeDetection.Out_BL) THEN (*It checks whether there has been a rising edge signal
Enable_BL*)
END_IF;
CASE (CounterType_enCounterType) OF
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^;
(*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;
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.Disarm_BL:=TRUE;
stConfigurationGate0.Capture_BL:=stIC3325PositionConf.
CaptureCounterSignal1_BL;
(*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
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;
stGenericCounterPosition.Gate1_stGateConf:=stConfigura
tionGate1;
stSPConfiguration.SpValue_DI:=
REAL_TO_DINT((stIC3325PositionConf.SetPointV
alue_R*PulsesPerTurn_I)/6.2831853); (*
SetPoint value *)
stSPConfiguration.Conf_stSpConf.Drm_BL:=FALSE;
stSPConfiguration.Conf_stSpConf.Preset_BL:=TRUE;
(* PRESET value associated with GATE1
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*)
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 (Write_BL) THEN
WRITE.ChassisNum_DI:=ChassisNum_DI;(*Chassis
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*)
(*Output Values*)
Done_BL:=WRITE.Done_BL;
Status_enCounterRet:=
END_IF;
IF (Read_BL) THEN
READ.ChassisNum_DI:=ChassisNum_DI;(*Chassis
number which the counter is connecteda*)
READ.Counter_stCounter_ADDR:=ADR(stGenericCounter
Read);(*Link to Reading configuration structure*)
(*Output Values*)
Done_BL:=TRUE;
Status_enCounterRet:= READ.Status_enCounterRet;
(*Exit status of the read function*)
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 (READ.Status_enCounterRet=0) THEN
CurrentPositionRad_R:=
((DINT_TO_REAL(stGenericCounterRead.
CounterValue_DI)/PulsesPerTurn_I)*6.283
HoldPositionRad_R:=((DINT_TO_REAL(st
GenericCounterRead.HoldValue_DI)/Pulse
sPerTurn_I)*6.2831853);(*Counter value*)
END_IF;
END_IF;
END_IF;
IF (CONFIGURATION.Done_BL) THEN
Configuration_BL:=FALSE;
END_IF;
ELSE (*If the structure passed to the function, does not match the expected
size*)
END_IF;
END_CASE;
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
VAR_INPUT
Input_BY:BYTE;
END_VAR
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*)
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
1.9.1.2.2 Syntax
VAR_INPUT
Input_DATE:DATE;
Input_TOD:TOD;
1.9.1.2.4.1 stPLCTime
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 *)
(*output*)
OutputPLCTime: stPLCTime;
OutputPLCTime:=DATE_AND_TOD_TO_stPLCTime(DateVariable,HourVariable);
1.9.1.3 DT_TO_stPLCTime
1.9.1.3.1 Description
1.9.1.3.2 Syntax
VAR_INPUT
Input_DT:DT;
END_VAR
1.9.1.3.4.1 stPLCTime
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);
1.9.1.4 EXTRACT_BL
1.9.1.4.1 Description
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
VAR_INPUT
Value_DW:DWORD;
BitNumber_BY:BYTE;
END_VAR
1.9.1.4.4 Remarks
Returns:
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).
1.9.1.4.5 Example
PROGRAM Example
VAR
Bit_i:BOOL;
END_VAR
Bit_i := EXTRACT_BL(Value,Index );
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
VAR_INPUT
Input_I:INT;
END_VAR
1.9.1.5.4 Remarks
Returns:
255 The function input parameter can not be represented in BCD in a BYTE.
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*)
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
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
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 = 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.
VAR_INPUT
Value_DW:DWORD;
BitNumber_BY:BYTE;
BitValue_BL:BOOL;
END_VAR
1.9.1.7.4 Remarks
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;
END_VAR
Value := PUTBIT_DW(Value,Index,Bit_i);
1.9.1.8 RESET_SET
1.9.1.8.1 Description
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
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.
1.9.1.8.6 Example
PROGRAM RESET_SET_Example
VAR
nTest : INT := 0;
(*RESET_SET*)
END_VAR
CASE nTest OF
1: (* FlipFlop:RESET_SET *)
(*Use a FlipFlop*)
END_CASE;
1.9.1.9.1 Description
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
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.
1.9.1.9.6 Example
PROGRAM SET_RESET_Example
VAR
nTest : INT := 0;
(*SET_RESET*)
END_VAR
CASE nTest OF
1: (* FlipFlop:SET_RESET *)
(*Use a FlipFlop*)
END_CASE;
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
VAR_INPUT
Input_stPLCTime:stPLCTime;
END_VAR
1.9.1.10.4.1 stPLCTime
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);
OutputDate:=stPLCTime_TO_DATE(InputPLCTime);
(*DATE#2001-09-11*)
1.9.1.11.1 Description
1.9.1.11.2 Syntax
FUNCTION stPLCTime_TO_DT : DT
VAR_INPUT
Input_stPLCTime:stPLCTime;
END_VAR
1.9.1.11.4.1 stPLCTime
1.9.1.11.5 Remarks
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.
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);
(*Get DT*)
OutputDT:=stPLCTime_TO_DT(InputPLCTime);
(*DT#2001-09-11-12:34:56.789*)
1.9.1.12.1 Description
1.9.1.12.2 Syntax
VAR_INPUT
Input_stPLCTime:stPLCTime;
END_VAR
1.9.1.12.4.1 stPLCTime
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.
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);
(*Get TOD*)
OutputTOD:=stPLCTime_TO_TOD(InputPLCTime);
(*TOD#12:34:56.789*)
1.9.1.13 UNPACK_BY
1.9.1.13.1 Description
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;
Bit3_BL:BOOL;
Bit4_BL:BOOL;
Bit5_BL:BOOL;
Bit6_BL:BOOL;
Bit7_BL:BOOL;
END_VAR
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;
END_VAR
(* 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
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.
1.10.1.1 CONCAT_STR
1.10.1.1.1 Description
1.10.1.1.2 Syntax
VAR_INPUT
In1_STR:STRING(255);
In2_STR:STRING(255);
END_VAR
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 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.
1.10.1.1.5 Example
PROGRAM Example
VAR
InputString: STRING(255);
(*output parameter*)
OutputString: STRING(255);
END_VAR
InputString :='World';
1.10.1.2 DELETE_STR
1.10.1.2.1 Description
1.10.1.2.2 Syntax
VAR_INPUT
In_STR:STRING(255);
Len_USI:USINT;
Pos_USI:USINT;
END_VAR
Returns the character string resulting from the deletion of the characters selected in the input
parameters.
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
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
VAR_INPUT
In1_STR:STRING(255);
In2_STR:STRING(255);
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
(*FindString: orld.*)
(*FoundPosition is 8*)
FindString := 'orld';
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.5.1 stFormat
1.10.1.4.6 Remarks
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
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*)
(*Output Parameters*)
FormattedString_STR: STRING(250);
Done: BOOL;
Error: BOOL;
Status_formatStr: DINT;
END_VAR
(*StringFormat: FORMAT_STR;*)
BufferFormat[0].FormatArg_STR:='%s';
BufferFormat[0].StrValue_STR:='Integer formats:\n';
(*---------------------- NUMERICALS---------------------*)
BufferFormat[1].FormatArg_STR:='%s';
BufferFormat[1].StrValue_STR:='Numericals:';
BufferFormat[2].DintValue_DI:=-10;
BufferFormat[3].FormatArg_STR:='%u ';
BufferFormat[3].DwordValue_DW:=20;
BufferFormat[4].FormatArg_STR:='%2f';
BufferFormat[4].RealValue_R:=0.20;
BufferFormat[5].FormatArg_STR:='%s';
BufferFormat[6].FormatArg_STR:='%S';
BufferFormat[6].StrValue_STR:='Hello Wor';
BufferFormat[7].FormatArg_STR:='%c';
BufferFormat[7].CharValue_BY:=16#6C;
BufferFormat[8].FormatArg_STR:='%c';
BufferFormat[8].CharValue_BY:=16#64;
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 );(*
*)
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
VAR_INPUT
In1_STR:STRING(255);
In2_STR:STRING(255);
Pos_USI:USINT;
END_VAR
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.
The maximum length of the input strings (In1_STR and In2_STR) is 255 characters.
1.10.1.5.5 Example
PROGRAM Example
VAR
BaseString: STRING(255);
IncludeString: STRING(255);
OutputString: STRING(255);
END_VAR
BaseString := 'HowYou?';
1.10.1.6 LEFT_STR
1.10.1.6.1 Description
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
VAR_INPUT
In_STR:STRING(255);
Len_USI:USINT;
END_VAR
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*)
1.10.1.7 LEN_STR
1.10.1.7.1 Description
1.10.1.7.2 Syntax
VAR_INPUT
In_STR:STRING(255);
END_VAR
1.10.1.7.4 Remarks
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
VAR_INPUT
In_STR:STRING(255);
Len_USI:USINT;
Pos_USI:USINT;
1.10.1.8.4 Remarks
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
1.10.1.9 REPLACE_STR
1.10.1.9.1 Description
It replaces the selected number of characters in the chosen position with another string of
characters.
1.10.1.9.2 Syntax
In1_STR:STRING(255);
In2_STR:STRING(255);
Len_USI:USINT;
Pos_USI:USINT;
END_VAR
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.
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;
OutputString:STRING(255);
END_VAR
BaseString :='HelloXYAll';
StringToInclude:='HowAreYou';
(*OutputString HelloHowAreYouAll*)
1.10.1.10 RESET_SET
1.10.1.10.1 Description
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.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.
1.10.1.10.6 Example
PROGRAM RESET_SET_Example
VAR
nTest : INT := 0;
(*RESET_SET*)
END_VAR
CASE nTest OF
1: (* FlipFlop:RESET_SET *)
(*Use a FlipFlop*)
END_CASE;
1.10.1.11.1 Description
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
VAR_INPUT
In_STR:STRING(255);
Len_USI:USINT;
END_VAR
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
(*OutputString lo*)
1.10.1.12 SET_RESET
1.10.1.12.1 Description
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
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.
1.10.1.12.6 Example
PROGRAM SET_RESET_Example
VAR
nTest : INT := 0;
(*SET_RESET*)
END_VAR
CASE nTest OF
1: (* FlipFlop:SET_RESET *)
(*Use a FlipFlop*)
END_CASE;
1.10.1.13 XOR_BUFFER
1.10.1.13.1 Description
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.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.
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
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