Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Overview of TcMC2 XFC

TwinCAT PLC Library: TcMC2 XFC

Overview

The library TcMC2 XFC facilitates precisely timed acquisition of axis positions and output of digital signals at precise positions in conjunction with EtherCAT XFC terminals (time stamp terminals and oversampling terminals).

A prerequisite is high-precision dead time compensation of the axes, which is available from TwinCAT 2.11 for EtherCAT and Sercos drives.

A precise relationship between time and position can then be established at any time.

Important applications include acquisition of latch positions (Touch Probe and Measuring probe function) and realisation of digital cam controllers for which the library provides function blocks.


Dead time compensation

A prerequisite for high-precision conversion of positions into times and vice versa is precise dead time compensation of the axes. From TwinCAT 2.11 such a dead time compensation function is available for EtherCAT and Sercos axes. It operates largely automatically. Manual configuration may still be required in order to compensate dead times within a drive, for example.

Support of distributed clocks

In EtherCAT drives distributed clock support must be activated initially via the EtherCAT Advanced Settings dialog.

By activating the switch Include DC Shift Times time information in the info data of the drive is made available and subsequently linked to the NC axis.

DcInputShift is the time required for transferring status information, including the actual position of a drive in the control system, i.e. the time between data acquisition and evaluation. DcOutputShift is the time required for output of the process data to the drive, i.e. the delay between calculation and effect of these data.

The time information is provided dynamically by the system and is used by the NC for dead time compensation of an axis.

For Sercos axes the times DcInputShift and DcOutputShift are provided by the Sercos card and do not have to be configured. If a drive is linked to an NC axis these times are also linked.

Compensation of the encoder dead time

Dead time compensation for the data acquisition side is initially activated on the Time Compensation tab of the axis encoder. The dead time from DcInputShift provided by the system is used for calculating the compensation.

In special cases, for example in the event of additional dead times due to the hardware used, it may be necessary to configure further times. The value Encoder Delay in Cycles indicates additional delays (whole I/O cycles). This time is therefore not a fixed value, but changes with the cycle time. Additional Encoder Delay is a fixed time value in µs caused by the hardware used.

Compensation of the drive dead time

The dead time in output direction can also be compensated. To this end the compensation is activated via the Time Compensation tab for the drive of the NC axis. The time provided by the system, DcOutputShift, is used for calculating the compensation.

In special cases further times can be configured. The value Task Delay in Cycles is based on the setting in the task configuration. Depending on the set task timing the dead time may be extended by one cycle. Drive Delay in Cycles indicates additional delays by whole I/O cycles caused by the drive. Additional Drive Delay is a fixed time value in µs that is also caused by the hardware used.

Effect of dead time compensation

Dead time compensation is used for conversion of all NC data that are cyclically exchanged with the PLC (NcToPlc) to the current time. The actual position, set position and following error of the axis in particular refer to the current time and reflect the physical axis position at this time. The PLC can use these values for further high-precision time and position calculations. (See basic functions XFC_GetCurDcTaskTime , XFC_TimeOfPosition and XFC_PositionAtTime.)


XFC_GetCurDcTaskTime

The function XFC_GetCurDcTaskTime determines the start time of the current PLC cycle.

The function optimises the calls of the system function F_GetCurDcTaskTime by answering several queries within a PLC task cycle with the same time, without calling the system function repeatedly.

Return value

FUNCTION XFCF_GetCurDcTaskTime : T_DCTIME
Return value of the function Complete 64-bit distributed clock system time. Start time of the current PLC cycle (cycle of the task that calls this function.)


XFC_ExtendDcTime

The function XFC_ExtendDcTime extends a 32-bit time stamp to 64 bit.

A prerequisite for the extension to a complete time stamp is that the 32-bit time stamp is valid for the current time range. It is not possible to guarantee error-free extension of a time stamp that applies more than approx. +/- 2 seconds before or after the current time.

Inputs

VAR_INPUT
    TimeStamp32 : T_DCTIME32;
END_VAR
TimeStamp32 Distributed Clock System Time.
TimeStamp32 contains the lower 32 bits of the complete DcTime and covers a time range of +/- 2 seconds around the current time.

Return value

FUNCTION XFCF_ExtendDcTime : T_DCTIME
Return value of the function Complete 64-bit distributed clock system time.


XFC_PositionAtTime

XFC_PositionAtTime calculates an axis position, which will be or was valid at a given time.

The function extrapolates the position in relation to the current position and dynamics. Precise extrapolation is only possible over a short interval, since the axis dynamics may change.

The function block requires precisely one call in order to provide the result. It can therefore be used similar to a function, although as well as the position it may also return an error. This error must be analysed in order to ensure that the calculated position is valid.

Inputs

VAR_INPUT
    DcTime 	: T_DCTIME32;
    Options 	: ST_NcTimeConversionOptions;
END_VAR
DcTime | Distributed Clock System Time. DcTime contains the lower 32 bits of the complete DcTime and covers a time range of +/- 2 seconds around the current time. In order to optimise the calculation of the position value, the time should be close to the current time, i.e. only a few PLC or NC cycles in the future or the past.
Options | Data structure with options for position extrapolation.
Options. | SubIndex | For axes with more than one encoder the index (0..9) of the encoder to which the position refers can be specified in SubIndex.
Options. | InterpolationOptions | 0 : The position extrapolation is carried out with the current velocity, without taking into account the current acceleration. 1: The axis acceleration is included in the position extrapolation.
Options. | CompensationTime | additional compensation time.

Outputs

VAR_OUTPUT
    Position	: LREAL;
    Error 	: BOOL;
    ErrorID 	: UDINT;
END_VAR
Position | Extrapolated position that will be or was reached at the specified time DcTime.
Error | Becomes TRUE if an error occurs.
ErrorID | Supplies the error number if an Error output is set and therefore indicates that the queried position is too far in the past or in future.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
END_VAR
Axis Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.


XFC_TimeOfPosition

XFC_TimeOfPosition calculates the time at which the axis will be or was at a specified position.

The function extrapolates the time in relation to the current position and dynamics. Precise extrapolation is only possible over a short interval, since the axis dynamics may change.

The function block requires precisely one call in order to provide the result. It can therefore be used similar to a function, although as well as the time it may also return an error. This error must be analysed in order to ensure that the calculated time DcTime is valid.

Inputs

VAR_INPUT
    Position	: LREAL;
    Options 	: ST_NcTimeConversionOptions;
END_VAR
Position | Absolute axis position
Options | Data structure with options for position extrapolation.
Options. | SubIndex | For axes with more than one encoder the index (0..9) of the encoder to which the position refers can be specified in SubIndex.
Options. | InterpolationOptions | 0 : The position extrapolation is carried out with the current velocity, without taking into account the current acceleration. 1: The axis acceleration is included in the position extrapolation.
Options. | CompensationTime | additional compensation time.

Outputs

VAR_OUTPUT
    DcTime 	: T_DCTIME32;
    Error 	: BOOL;
    ErrorID 	: UDINT;
END_VAR
DcTime | Distributed clock system time at which the position will be reached or was reached. DcTime contains the lower 32 bits of the complete DcTime and covers a time range of +/- 2 seconds around the current time.
Error | Becomes TRUE if an error occurs.
ErrorID | Supplies the error number if an Error output is set and therefore indicates that the queried position is too far in the past or in future.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
END_VAR
Axis Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.


XFC_TimeToPosition

XFC_TimeToPosition calculates the time within which an axis will reach a position or the time since which the axis has passed that position.

The function extrapolates the time in relation to the current position and dynamics. Precise extrapolation is only possible over a short interval, since the axis dynamics may change.

The function block requires precisely one call in order to provide the result. It can therefore be used similar to a function, although as well as the time it may also return an error. This error must be analysed in order to ensure that the calculated time duration is valid.

Inputs

VAR_INPUT
    Position	: LREAL;
    Options 	: ST_NcTimeConversionOptions;
END_VAR
Position | Absolute axis position
Options | Data structure with options for position extrapolation.
Options. | SubIndex | For axes with more than one encoder the index (0..9) of the encoder to which the position refers can be specified in SubIndex.
Options. | InterpolationOptions | 0 : The position extrapolation is carried out with the current velocity, without taking into account the current acceleration. 1: The axis acceleration is included in the position extrapolation.
Options. | CompensationTime | additional compensation time.

Outputs

VAR_OUTPUT
    Duration 		: DINT;
    TimeOfPosition 	: T_DCTIME32;
    Error 		: BOOL;
    ErrorID 		: UDINT;
END_VAR
Duration | Time duration in nanoseconds after which the position will be reached (> 0) or since the position was passed (< 0). Duration is a differential value between two variables of type T_DCTIME32 and therefore has the resolution of the distributed clock system time.
TimeOfPosition | Distributed clock system time at which the position will be reached or was reached. DcTime contains the lower 32 bits of the complete DcTime and covers a time range of +/- 2 seconds around the current time.
Error | Becomes TRUE if an error occurs.
ErrorID | Supplies the error number if an Error output is set and therefore indicates that the queried position is too far in the past or in future.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
END_VAR
Axis Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.


XFC_TimeToModuloPosition

XFC_TimeToModuloPosition calculates the time within which an axis will reach a position or the time since which the axis has passed that position. In this case the position is the nearest modulo position in the direction of travel.

The function extrapolates the time in relation to the current position and dynamics. Precise extrapolation is only possible over a short interval, since the axis dynamics may change.

The function block requires precisely one call in order to provide the result. It can therefore be used similar to a function, although as well as the time it may also return an error. This error must be analysed in order to ensure that the calculated time duration is valid.

Inputs

VAR_INPUT
    Position	: LREAL;
    ModuloFactor : LREAL;
    Options 	: ST_NcTimeConversionOptions;
END_VAR
Position | Absolute axis position
ModuloFactor | Modulo divisor to be used for the calculation. ModuloFactor can be identical with the modulo factor of the axis, e. g. 360 but it is possible to use a different factor.
Options | Data structure with options for position extrapolation.
Options. | SubIndex | For axes with more than one encoder the index (0..9) of the encoder to which the position refers can be specified in SubIndex.
Options. | InterpolationOptions | 0 : The position extrapolation is carried out with the current velocity, without taking into account the current acceleration. 1: The axis acceleration is included in the position extrapolation.
Options. | CompensationTime | additional compensation time.

Outputs

VAR_OUTPUT
    Duration 		: DINT;
    AbsolutePosition 	: LREAL;
    TimeOfPosition 	: T_DCTIME32;
    Error 		: BOOL;
    ErrorID 		: UDINT;
END_VAR
Duration | Time duration in nanoseconds after which the position will be reached. Duration is a differential value between two variables of type T_DCTIME32 and therefore has the resolution of the distributed clock system time.
AbsolutePosition | Absolute position (not modulo) corresponding to the modulo position and the determined time.
TimeOfPosition | Distributed clock system time at which the position will be reached or was reached. DcTime contains the lower 32 bits of the complete DcTime and covers a time range of +/- 2 seconds around the current time.
Error | Becomes TRUE if an error occurs.
ErrorID | Supplies the error number if an Error output is set and therefore indicates that the queried position is too far in the past or in future.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
END_VAR
Axis Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.


MC_DigitalCamSwitch

MC_DigitalCamSwitch is a digital cam controller with one or several cams on a digital output track.

Position, time and brake cams can be realised through suitable parameterisation. Further output tracks can be realised with independent instances of the function block.

In addition to the switching state of the digital output the output data structure contains precise time information for the next switching operations. This information is used for the actual output at an XFC output terminal with a downstream function block (XFC_EL2252 or XFC_EL2262).

Inputs

VAR_INPUT
    Enable : BOOL;
    Options : ST_CamSwitchOptions;
END_VAR
Enable | The cam controller is activated via the Enable input. The initial state remains unchanged, as long as Enable=FALSE.
Options | Optional parameters
Options. | EncoderIndex | If more than one encoder is connected to the axis, the encoder index [0..9] can be specified here. First encoder is always index 0.
Options. | UseAcceleration | UseAcceleration can be enabled to take the axis acceleration into account for position calculations. There will be an advantage if the acceleration set value can be used. If the axis is an encoder axis, the position data may be noisy and the acceleration value will be noisy as well. In this case UseAcceleration is supposed to be false.

Outputs

VAR_OUTPUT
    InOperation	: BOOL;
    Busy 		: BOOL;
    Error 		: BOOL;
    ErrorID 		: UDINT;
END_VAR
InOperation | InOperation is TRUE, as long as the cam controller is active and the cam track is calculated according to the cam parameterisation.
Busy | Busy is TRUE as long as the block function is not completed.
Error | Becomes TRUE if an error occurs.
ErrorID | If the error output is set, this parameter supplies the error number.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
    Switches 		: CAMSWITCH_REF;
    Output 		: OUTPUT_REF;
    TrackOptions 	: TRACK_REF;
END_VAR
Axis | Axis data structure
Switches | The data structure Switches contains a reference to the parameterisation of all cams on the cam track.
Output | The data structure Output contains the calculated state of the digital output and the associated time stamp for the output at a digital XFC output terminal
TrackOptions | The data structure TrackOptions contains the parameterisation for the cam track.

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.

Example with two digital cams


XFC_PositionCam

XFC_PositionCam realises a position cam that switches a digital output on or off, depending on the position.

In contrast to the digital cam controller MC_DigitalCamSwitch, the function block switches precisely one cam on a digital output track. This facilitates parameterisation of the block, although it cannot by used if several cams are required on an output track.

In addition to the switching state of the digital output the output data structure contains precise time information for the next switching operations. This information is used for the actual output at an XFC output terminal with a downstream function block (XFC_EL2252 or XFC_EL2262).

Inputs

VAR_INPUT
    FirstOnPosition 	: LREAL;
    LastOnPosition 	: LREAL;
    Modulo 		: BOOL;
    ModuloFactor 	: LREAL := 360;
    OnCompensation 	: LREAL;
    OffCompensation	: LREAL;
    Options 		: ST_CamSwitchOptions;
END_VAR
FirstOnPosition | First position from which the cam is switched on.
LastOnPosition | Last position up to which the cam is switched on. The cam function is inverted, if LastOnPosition < FirstOnPosition
Modulo | If Modulo=TRUE, all positions are interpreted as modulo. The cam function is repeated cyclically. The parameter ModuloFactor is used for calculating the modulo cycle.
ModuloFactor | ModuloFactor indicates the length of a modulo cycle in the positioning unit of the axis and is only used if Modulo=TRUE.
OnCompensation | Compensation time for the rising edge of the cam in [s]. For negative values of OnCompensation the switching time is brought forward, otherwise it is delayed. This value has priority over TRACK_REF.
OffCompensation | Compensation time for the falling edge of the cam in [s]. For negative values of OffCompensation the switching time is brought forward, otherwise it is delayed. This value has priority over TRACK_REF.
Options | Optional parameters
Options. | EncoderIndex | If more than one encoder is connected to the axis, the encoder index [0..9] can be specified here. First encoder is always index 0.
Options. | UseAcceleration | UseAcceleration can be enabled to take the axis acceleration into account for position calculations. There will be an advantage if the acceleration set value can be used. If the axis is an encoder axis, the position data may be noisy and the acceleration value will be noisy as well. In this case UseAcceleration is supposed to be false.

Inputs/outputs

VAR_IN_OUT
    Output 		: OUTPUT_REF;
    Axis 		: AXIS_REF;
END_VAR
Output | The data structure Output contains the calculated state of the digital output and the associated time stamp for the output at a digital XFC output terminal
Axis | Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.

Description of time compensation


XFC_TimeCam

XFC_TimeCam realises a time cam that activates a digital output depending on the position and switches it off after a certain time.

In contrast to the digital cam controller MC_DigitalCamSwitch, the function block switches precisely one cam on a digital output track. This facilitates parameterisation of the block, although it cannot by used if several cams are required on an output track.

In addition to the switching state of the digital output the output data structure contains precise time information for the next switching operations. This information is used for the actual output at an XFC output terminal with a downstream function block (XFC_EL2252 or XFC_EL2262).

Inputs

VAR_INPUT
    FirstOnPosition 	: LREAL;
    Duration	 	: LREAL;
    Modulo 		: BOOL;
    ModuloFactor 	: LREAL := 360;
    OnCompensation 	: LREAL;
    OffCompensation	: LREAL;
    Options 		: ST_CamSwitchOptions;
END_VAR
FirstOnPosition | First position from which the cam is switched on.
Duration | Switch-on duration of the cam in [s].
Modulo | If Modulo=TRUE, all positions are interpreted as modulo. The cam function is repeated cyclically. The parameter ModuloFactor is used for calculating the modulo cycle.
ModuloFactor | ModuloFactor indicates the length of a modulo cycle in the positioning unit of the axis and is only used if Modulo=TRUE.
OnCompensation | Compensation time for the rising edge of the cam in [s]. For negative values of OnCompensation the switching time is brought forward, otherwise it is delayed. This value has priority over TRACK_REF.
OffCompensation | Compensation time for the falling edge of the cam in [s]. For negative values of OffCompensation the switching time is brought forward, otherwise it is delayed. This value has priority over RACK_REF.
Options | Optional parameters
Options. | EncoderIndex | If more than one encoder is connected to the axis, the encoder index [0..9] can be specified here. First encoder is always index 0.
Options. | UseAcceleration | UseAcceleration can be enabled to take the axis acceleration into account for position calculations. There will be an advantage if the acceleration set value can be used. If the axis is an encoder axis, the position data may be noisy and the acceleration value will be noisy as well. In this case UseAcceleration is supposed to be false.

Inputs/outputs

VAR_IN_OUT
    Output 		: OUTPUT_REF;
    Axis 		: AXIS_REF;
END_VAR
Output | The data structure Output contains the calculated state of the digital output and the associated time stamp for the output at a digital XFC output terminal
Axis | Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.

Description of time compensation


XFC_BreakCam

XFC_BreakCam realises a brake cam, which deactivates a digital output depending on the position as soon as BreakRelease is withdrawn.

In addition to the switching state of the digital output the output data structure contains precise time information for the next switching operations. This information is used for the actual output at an XFC output terminal with a downstream function block (XFC_EL2252 or XFC_EL2262).

Inputs

VAR_INPUT
    BreakRelease 	: LREAL;
    LastOnPosition 	: LREAL;
    Modulo 		: BOOL;
    ModuloFactor 	: LREAL := 360;
    OffCompensation	: LREAL;
    Options 		: ST_CamSwitchOptions;
END_VAR
BreakRelease | Brake enable. The cam remains active as long as BreakRelease is TRUE. When BreakRelease becomes FALSE, the cam is switched off at position LastOnPosition.
LastOnPosition | Last position up to which the cam is switched on.
Modulo | If Modulo=TRUE, all positions are interpreted as modulo. The cam function is repeated cyclically. The parameter ModuloFactor is used for calculating the modulo cycle.
ModuloFactor | ModuloFactor indicates the length of a modulo cycle in the positioning unit of the axis and is only used if Modulo=TRUE.
OffCompensation | Compensation time for the falling edge of the cam in [s]. For negative values of OffCompensation the switching time is brought forward, otherwise it is delayed. This value has priority over TRACK_REF.
Options | Optional parameters
Options. | EncoderIndex | If more than one encoder is connected to the axis, the encoder index [0..9] can be specified here. First encoder is always index 0.
Options. | UseAcceleration | UseAcceleration can be enabled to take the axis acceleration into account for position calculations. There will be an advantage if the acceleration set value can be used. If the axis is an encoder axis, the position data may be noisy and the acceleration value will be noisy as well. In this case UseAcceleration is supposed to be false.

Inputs/outputs

VAR_IN_OUT
    Output 		: OUTPUT_REF;
    Axis 		: AXIS_REF;
END_VAR
Output | The data structure Output contains the calculated state of the digital output and the associated time stamp for the output at a digital XFC output terminal.
Axis | Axis data structure

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.

Description of time compensation


XFC_TouchProbe

The XFC_TouchProbe function block records an axis position at the time of the edge of a digital input signal (measuring probe function).

The digital input signal is recorded with an XFC input terminal (e.g. EL1252) with time stamps for the falling and rising signal edge. The function block determines the axis position at which the edge change occurred and issues it as RecordedPosition.

In contrast to the conventional TouchProbe function MC_TouchProbe the digital input is not directly linked to the drive hardware. The position of each EtherCAT or Sercos axis in the system can be recorded via the time stamp of the input. This axis is exactly synchronised via Dead time compensation.

The function block can be used in free-running or single-shot mode. In free-running mode each edge of the input signal is recorded (maximum one edge per PLC cycle). In single-shot mode the next edge is only recorded once until the function block is triggered again.

The optional window function can be used to ignore signal edges outside the defined position filter.

Signal curve

Inputs

VAR_INPUT
    Execute 		: BOOL;
    WindowOnly 	: BOOL;
    FirstPosition 	: LREAL;
    LastPosition 	: LREAL;
END_VAR
Execute | If Execute is active, the axis position is recorded at the defined signal edge of the input signal. A falling edge at Execute terminates the process immediately. Depending on the configuration in TriggerInput.FreeRun the next signal edge is recorded and evaluated once. If FreeRun is TRUE, a new position value is recorded continuously with each defined edge of the input signal, while Execute remains TRUE.
WindowOnly | If this option is active, only one position inside the window between FirstPosition and LastPosition is recorded. Positions outside the window are discarded. Only if the recorded position lies inside the window does Done become TRUE. The recording window can be interpreted in terms of absolute or modulo values. In this connection the flag ModuloPositions in the structure TriggerInput is to be set accordingly. In the case of absolute value positions there is exactly one window. In the case of modulo value positions the window repeats itself within the modulo cycle defined in the axis parameters (e.g. 0 to 360 degrees).
FirstPosition | Initial position of the recording window, if WindowOnly is TRUE. This position can be interpreted as an absolute or modulo value. In this connection the flag ModuloPositions is to be set appropriately in the structure TriggerInput (see below).
LastPosition | Final position of the recording window, if WindowOnly is TRUE. This position can be interpreted as an absolute or modulo value. In this connection the flag ModuloPositions is to be set appropriately in the structure TriggerInput (see below).
Options | Optional parameters
Options. | UseAcceleration | UseAcceleration can be enabled to take the axis acceleration into account for position calculations. There will be an advantage if the acceleration set value can be used. If the axis is an encoder axis, the position data may be noisy and the acceleration value will be noisy as well. In this case UseAcceleration is supposed to be false.

Outputs

VAR_OUTPUT
    Done 		: BOOL;
    Busy 		: BOOL;
    Error 		: BOOL;
    ErrorID 		: UDINT;
    RecordedPosition	: LREAL;
END_VAR
Done | The value RecordedPosition is valid. If TriggerInput.FreeRun is TRUE, Done only remains TRUE only for one PLC cycle and is then reset automatically, since TouchProbe is automatically reactivated.
Busy | Becomes TRUE as soon as the function block is active, and becomes FALSE when it has returned to its initial state. If TriggerInput.FreeRun is TRUE, Busy remains TRUE continuously, even if Done or Error become TRUE, since TouchProbe is automatically reactivated.
Error | Becomes TRUE, as soon as an error occurs.
ErrorID | If the error output is set, this parameter supplies the error number.
RecordedPosition | Axis position recorded at the point in time of the trigger signal. If TriggerInput.FreeRun is TRUE, the function block operates in free-running mode, so that each valid change in the input signal leads to a new RecordedPosition. The position can be analysed, if Done becomes TRUE.

Inputs/outputs

VAR_IN_OUT
    Axis 		: AXIS_REF;
    TriggerInput 	: XFC_TRIGGER_REF;
END_VAR
Axis | Axis data structure
TriggerInput | TriggerInput is a data structure for describing the trigger source and for feeding the state and time stamp of a digital input signal. This structure must be filled by the user.

The axis data structure of type AXIS_REF addresses an axis uniquely within the system. Among other parameters it contains the current axis status, including position, velocity or error status.


XFC_EL2252

XFC_EL2252 handles the output of a digital cam with the XFC time stamp terminal EL2252.

Notes:

The function block XFC_EL2252_V2 is recommended for new projects.

Data output at the terminal takes place only shortly before the TimeStamp is reached. Three PLC cycles are required for activation and acknowledgement of the outputs. Only then can a further edge change take place. The minimum time between two edge changes of the output signal is therefore three, better four PLC cycles, in order to prevent errors or loss of precision. If the output signal is generated by a cam controller, a minimum cam width can be calculated from the maximum velocity and the PLC cycle time.

Output1 and Output2 cannot be used completely independent because only one timestamp is available to activate both outputs. If both channels are used, the rising or falling signal edges of both channels must have a minimum distance in time. In this case the nearest timestamp of both channels can be passed to the block.

Inputs

VAR_INPUT
    Output1 		: BOOL;
    Output2 		: BOOL;
    TimeStampValid 	: BOOL;
    TimeStamp 	: T_DCTIME32;
    ForceWhenLate	: BOOL;
END_VAR
Output1 | Next initial state for channel 1 of the terminal that will be activated at TimeStamp. If the output signal is generated by a cam controller, it should be noted that the output is inverted. The cam controller provides the current signal state. However, the next state from the parameterised TimeStamp must be transferred to Output1.
Output2 | Next initial state for channel 2 of the terminal that will be activated at TimeStamp. If the output signal is generated by a cam controller, it should be noted that the output is inverted. The cam controller provides the current signal state. However, the next state from the parameterised TimeStamp must be transferred to Output2.
TimeStampValid | TimeStampValid is TRUE if the parameterised TimeStamp is valid.
TimeStamp | Time stamp (distributed clock system time) The EL2252 terminal supports only one time stamp for both outputs. At this time both outputs Output1 and Output2 are updated together. Output to the terminal takes place three cycles before the time stamp is reached. If this time is exceeded, the output ErrorOutputMissed or PrecisionReduced is set, depending on the state of ForceWhenLate.
ForceWhenLate | If ForceWhenLate is TRUE, the output is activated even if the time stamp is already exceeded. It is recommended to set ForceWhenLate to avoid missing signal edges in case of timing jitter.

Outputs

VAR_OUTPUT
    Error 		: BOOL;
    ErrorID 		: UDINT;
    ErrorOutputMissed	: BOOL;
END_VAR
Error | Becomes TRUE if an error occurs.
ErrorID | If an error output is set, this parameter supplies an error number.
ErrorOutputMissed | The exact switching point defined by TimeStamp could not be adhered to and the initial state remains unchanged. If ForceWhenLate is TRUE, the initial state is always output and ErrorOutputMissed does not become TRUE.
PrecisionReduced | The exact switching point defined by TimeStamp could not be adhered to; the initial state was output with a delay. PrecisionReduced should be regarded as a warning. It can only become TRUE if ForceWhenLate is TRUE.

Inputs/outputs

VAR_IN_OUT
    TrackOptions 	: TRACK_REF;
    EL2252 		: EL2252_IoInterface;
END_VAR
TrackOptions | The data structure TrackOptions contains the parameterisation for the cam track.
EL2252 | Process image of the terminal

Example for a position cam output

The following example illustrates how the output from a cam controller XFC_PositionCam should be transferred to the function block XFC_EL2252. An important element is the inversion of the signal state Level, since the signal state will change at time NextStateChange.

Example for two position cam outputs at a single terminal

Output1 and Output2 cannot be used completely independent because only one timestamp is available to activate both outputs. If both channels are used, the rising or falling signal edges of both channels must have a minimum distance in time (4 PLC cycles). In this case the nearest timestamp of both channels can be passed to the block. It is important to invert only the output that corresponds to the timestamp that is passed to the block. Just this output will change the state and the other output is passed with its current state.

PROGRAM EL2252_TwoChannels
VAR
    PosCam1 : XFC_PositionCam;
    Output1 : OUTPUT_REF;

    PosCam2 : XFC_PositionCam;
    Output2 : OUTPUT_REF;

    EL2252 : XFC_EL2252;
END_VAR

IF Output1.NextStateChange > 0 AND Output1.NextStateChange < Output2.NextStateChange THEN
    EL2252.TimeStampValid 	:= Output1.NextStateChangeValid;
    EL2252.TimeStamp 		:= Output1.NextStateChange;
    EL2252.Output1 		:= NOT Output1.Level; (* toggle *)
    EL2252.Output2 		:= Output2.Level; (* keep *)
ELSE
    EL2252.TimeStampValid 	:= Output2.NextStateChangeValid;
    EL2252.TimeStamp 		:= Output2.NextStateChange;
    EL2252.Output1 		:= Output1.Level; (* keep *)
    EL2252.Output2 		:= NOT Output2.Level; (* toggle *)
END_IF


XFC_EL2252_V2

XFC_EL2252_V2 handles the output of a digital cam with the XFC time stamp terminal EL2252.

Notes:

The function block XFC_EL2252_V2 replaces the function block XFC_EL2252 which is still available in the library for compatibility reasons.

Data output at the terminal takes place only shortly before the time stamp of one of the outputs is reached. Three PLC cycles are required for activation and acknowledgement of the outputs. Only then can a further edge change take place. The minimum time between two edge changes of the output signal is therefore three, better four PLC cycles, in order to prevent errors or loss of precision. If the output signal is generated by a cam controller, a minimum cam width can be calculated from the maximum velocity and the PLC cycle time.

Output1 and Output2 cannot be used completely independent because only one timestamp is available to activate both outputs. If both channels are used, the rising or falling signal edges of both channels must have a minimum distance in time. In this case the nearest timestamp of both channels can be passed to the block.

Inputs

VAR_INPUT
    ForceWhenLate	: BOOL;
END_VAR
ForceWhenLate If ForceWhenLate is TRUE, the output is activated even if the time stamp is already exceeded.
It is recommended to set ForceWhenLate to avoid missing signal edges in case of timing jitter.

Outputs

VAR_OUTPUT
    Error 		: BOOL;
    ErrorID 		: UDINT;
    ErrorOutputMissed	: BOOL;
    PrecisionReduced	: BOOL;
END_VAR
Error | Becomes TRUE if an error occurs.
ErrorID | If an error output is set, this parameter supplies an error number.
ErrorOutputMissed | The exact switching point defined by TimeStamp could not be adhered to and the initial state remains unchanged. If ForceWhenLate is TRUE, the initial state is always output and ErrorOutputMissed does not become TRUE.
PrecisionReduced | The exact switching point defined by TimeStamp could not be adhered to; the initial state was output with a delay. PrecisionReduced should be regarded as a warning. It can only become TRUE if ForceWhenLate is TRUE.

Inputs/outputs

VAR_IN_OUT
    Output1 		: OUTPUT_REF;
    Output2 		: OUTPUT_REF;
    TrackOptions1 	: TRACK_REF;
    TrackOptions2 	: TRACK_REF;
    EL2252 		: EL2252_IoInterface;
END_VAR
Output1 | State of channel 1 of the terminal. The data structure Output1 contains the calculated state of the digital output and the associated time stamp for the output 1 at a digital XFC output terminal
Output2 | State of channel 2 of the terminal. The data structure Output2 contains the calculated state of the digital output and the associated time stamp for the output 2 at a digital XFC output terminal
TrackOptions1 | The data structure TrackOptions1 contains the parameterisation for the cam track 1 (Output1).
TrackOptions2 | The data structure TrackOptions2 contains the parameterisation for the cam track 2 (Output2).
EL2252 | Process image of the terminal


XFC_EL2212

TwinCAT PLC Library: TcMC2 XFC

XFC_EL2212_V2

XFC_EL2212_V2 handles the output of a digital cam with the XFC time stamp terminal EL2212.

Notes:

The function block XFC_EL2212_V2 replaces the function block XFC_EL2212which is still available in the library for compatibility reasons.

Data output at the terminal takes place only shortly before the time stamp of one of the outputs is reached. Three PLC cycles are required for activation and acknowledgement of the outputs. Only then can a further edge change take place. The minimum time between two edge changes of the output signal is therefore three, better four PLC cycles, in order to prevent errors or loss of precision. If the output signal is generated by a cam controller, a minimum cam width can be calculated from the maximum velocity and the PLC cycle time.

Output1 and Output2 cannot be used completely independent because only one timestamp is available to activate both outputs. If both channels are used, the rising or falling signal edges of both channels must have a minimum distance in time. In this case the nearest timestamp of both channels can be passed to the block.

Inputs

VAR_INPUT
    ForceWhenLate	: BOOL;
END_VAR
ForceWhenLate If ForceWhenLate is TRUE, the output is activated even if the time stamp is already exceeded.
It is recommended to set ForceWhenLate to avoid missing signal edges in case of timing jitter.

Outputs

VAR_OUTPUT
    Error 		: BOOL;
    ErrorID 		: UDINT;
    ErrorOutputMissed	: BOOL;
    PrecisionReduced	: BOOL;
END_VAR
Error | Becomes TRUE if an error occurs.
ErrorID | If an error output is set, this parameter supplies an error number.
ErrorOutputMissed | The exact switching point defined by TimeStamp could not be adhered to and the initial state remains unchanged. If ForceWhenLate is TRUE, the initial state is always output and ErrorOutputMissed does not become TRUE.
PrecisionReduced | The exact switching point defined by TimeStamp could not be adhered to; the initial state was output with a delay. PrecisionReduced should be regarded as a warning. It can only become TRUE if ForceWhenLate is TRUE.

Inputs/outputs

VAR_IN_OUT
    Output1 		: OUTPUT_REF;
    Output2 		: OUTPUT_REF;
    TrackOptions1 	: TRACK_REF;
    TrackOptions2 	: TRACK_REF;
    EL2212 		: EL2212_IoInterface;
END_VAR
Output1 | State of channel 1 of the terminal. The data structure Output1 contains the calculated state of the digital output and the associated time stamp for the output 1 at a digital XFC output terminal
Output2 | State of channel 2 of the terminal. The data structure Output2 contains the calculated state of the digital output and the associated time stamp for the output 2 at a digital XFC output terminal
TrackOptions1 | The data structure TrackOptions1 contains the parameterisation for the cam track 1 (Output1).
TrackOptions2 | The data structure TrackOptions2 contains the parameterisation for the cam track 2 (Output2).
EL2212 | Process image of the terminal


XFC_EL2262

XFC_EL2262 handles the output of a digital cam with the XFC oversampling terminal EL2262.

Notes:

The maximum output frequency depends on the cycle time. The minimum distance between two rising signal edges is two PLC cycles. The distance between rising and falling edges of the signal may be shorter than one PLC cycle. The accuracy is given by the parameterized oversampling factor of the terminal.

The two channels of the terminals are independent and are controlled by two instances of the XFC_EL2262 block.

Inputs

VAR_INPUT
    OversamplingFactor 	: UINT;
    OutputOneCycleDelayed 	: BOOL; (* TRUE if EL2262 is updated with the NC SAF task at the beginning of the next cycle *)
END_VAR
OversamplingFactor | Oversampling factor for the EL2262 terminal
OutputOneCycleDelayed | OutputOneCycleDelayed is TRUE, if the output of the process image is delayed by a cycle due to the set timing. OutputOneCycleDelayed depends on the timing of the output task to which the EL2262 is linked.
ForceWhenLate | In case of cyclically changing time information it may happen that the output signal cannot be triggered. ForceWhenLate will trigger the output best possible. In this case the output PrecisionReduced will be set to TRUE for diagnostic purposes. (For example a jitter in an axis position may cause a jitter in time information.)
Channel | Channel number 0 or 1 of the EL2262 terminal

Outputs

VAR_OUTPUT
    Error 		: BOOL;
    ErrorID 		: UDINT;
    ErrorOutputMissed	: BOOL;
END_VAR
Error | Becomes TRUE if an error occurs.
ErrorID | If an error output is set, this parameter supplies an error number.
ErrorOutputMissed | ErrorOutputMissed turns to TRUE if the output cannot be triggered due to a jitter in the time information.
PrecisionReduced | PrecisionReduced turns to TRUE in case the output was triggered best possible with reduced accuracy due to a jitter in the time information.

Inputs/outputs

VAR_IN_OUT
    Output 		: OUTPUT_REF;
    TrackOptions 	: TRACK_REF;
    EL2262 		: EL2262_IoInterface;
END_VAR
Output | The data structure Output contains the calculated state of the digital output and the associated time stamp for the output at a digital XFC output terminal
TrackOptions | The data structure TrackOptions contains the parameterisation for the cam track.
EL2262 | Process image of the terminal


MC_CamSwitch

TwinCAT PLC Library: TcMC2 XFC

Data type MC_CamSwitch

The data type MC_CamSwitch contains all parameters of a digital cam for a digital cam controller MC_DigitalCamSwitch.

TYPE MC_CamSwitch :
STRUCT
    FirstOnPosition 	: LREAL;
    LastOnPosition 	: LREAL;
    AxisDirection 	: E_CamSwitchDirection;
    CamSwitchMode 	: E_CamSwitchMode;
    Duration 		: LREAL;
END_STRUCT
END_TYPE

The data structure for parameterisation of a digital cam controller is usually an ARRAY OF MC_CamSwitch. A further structure CAMSWITCH_REF refers to this structure.

FirstOnPosition | First position from which the cam is switched on.
LastOnPosition | Last position up to which the cam is switched on. The cam function is inverted, if LastOnPosition < FirstOnPosition. LastOnPosition is not used for time cams.
AxisDirection | AxisDirection defines in which axis travel direction the digital cam is active (positive, negative or both directions).
CamSwitchMode | Digital cam type (position cam, time cam or brake cam).
Duration | Duration defines the switch-on time of the cam in [s] and is only used for time cams.

TYPE E_CamSwitchDirection :
(
    CAMSWITCHDIRECTION_BOTH, 		(* digital cam will work in both directions *)
    CAMSWITCHDIRECTION_POSITIVE, 	(* digital cam is just working in positive direction *)
    CAMSWITCHDIRECTION_NEGATIVE 	(* digital cam is just working in negative direction *)
);
END_TYPE

TYPE E_CamSwitchMode :
(
    CAMSWITCHMODE_POSITION,		(* position cam *)
    CAMSWITCHMODE_TIME,		(* time cam *)
    CAMSWITCHMODE_BREAK		(* break cam *)
);
END_TYPE


CAMSWITCH_REF

TwinCAT PLC Library: TcMC2 XFC

Data type CAMSWITCH_REF

The data type CAMSWITCH_REF refers to a data structure with cam parameters for a digital cam controller MC_DigitalCamSwitch.

TYPE CAMSWITCH_REF :
STRUCT
    NumberOfSwitches 	: UDINT;
    pSwitches 	: POINTER TO MC_CamSwitch;
    SizeOfSwitches 	: UDINT;
END_STRUCT
END_TYPE

The actual data structure for parameterisation of a digital cam controller is usually an ARRAY OF MC_CamSwitch. CAMSWITCH_REF refers to this structure via a pointer and clearly defines the size of the structure and the number of actual cams.

A variable of type CAMSWITCH_REF is initialised as illustrated in the following example:

VAR
    CamSwitchArray	: ARRAY[1..3] OF MC_CamSwitch;
    CamSwitchRef 	: CAMSWITCH_REF;
END_VAR
(* real number of defined digital cams *)
CamSwitchRef.NumberOfSwitches := 1; (* 1..3 *)

(* pointer to the digital cam data array *)
CamSwitchRef.pSwitches := ADR(CamSwitchArray);

(* maximum size of the digital cam data array *)
CamSwitchRef.SizeOfSwitches := SIZEOF(CamSwitchArray);

Example with two tracks


OUTPUT_REF

TwinCAT PLC Library: TcMC2 XFC

Data type OUTPUT_REF

The data type OUTPUT_REF contains data describing the state of a digital output. In addition to the switching state it contains time stamps for state changes.

TYPE OUTPUT_REF :
STRUCT
    Level 			: BOOL; 		(* current level of the digital output *)

    NextStateChangeValid 	: BOOL; 		(* time value NextStateChange is valid *)
    NextStateChange 		: T_DCTIME32; 	(* time of next state change - current level will be inverted *)

    NextOnTimeValid 		: BOOL; 		(* time value NextOnTime is valid *)
    NextOnTime 		: T_DCTIME32; 	(* time when the digital output is turned ON next time *)

    NextOffTimeValid 		: BOOL; 		(* time value NextOffTime is valid *)
    NextOffTime 		: T_DCTIME32; 	(* time when the digital output is turned OFF next time *)
END_STRUCT
END_TYPE

Level | Current switching state of the digital output
NextStateChangeValid | NextStateChangeValid is TRUE, if the time stamp NextStateChange is valid.
NextStateChange | Time of the next change of state (distributed clock TimeStamp)
NextOnTimeValid | NextOnTimeValid is TRUE, if the time stamp NextOnTime is valid.
NextOnTime | Time of the next positive switching edge (distributed clock TimeStamp)
NextOffTimeValid | NextOffTimeValid is TRUE, if the time stamp NextOffTime is valid.
NextOffTime | Time of the next negative switching edge (distributed clock TimeStamp)


TRACK_REF

TwinCAT PLC Library: TcMC2 XFC

Data type TRACK_REF

The data type TRACK_REF contains the parameters of a digital cam track for a digital cam controller MC_DigitalCamSwitch.

TYPE TRACK_REF :
STRUCT
    ModuloPositions 	: BOOL 	:= TRUE; 	(* all cam positions are interpreted as modulo positions when TRUE *)
    ModuloFactor 	: LREAL 	:= 360; 	(* e. g. 360 degrees *)
    OnCompensation 	: LREAL; 		(* compensation time [s] *)
    OffCompensation 	: LREAL; 		(* compensation time [s] *)
    Hysteresis 	: LREAL; 		(* distance from last switch position (+ or -) *)
    BreakRelease 	: BOOL; 		(* allow break to be released when TRUE, break cams will be activated when FALSE *)
    Force 		: BOOL; 		(* override all digital cams and set track ON *)
    Disable 		: BOOL; 		(* override all digital cams and set track OFF - overrides Force as well *)
END_STRUCT
END_TYPE
ModuloPositions | If Modulo=TRUE, all positions are interpreted as modulo. The cam function is repeated cyclically. The parameter ModuloFactor is used for calculating the modulo cycle.
ModuloFactor | ModuloFactor indicates the length of a modulo cycle in the positioning unit of the axis and is only used if Modulo=TRUE.
OnCompensation | Compensation time for the rising edge of the cam in [s]. For negative values of OnCompensation the switching time is brought forward, otherwise it is delayed.
OffCompensation | Compensation time for the falling edge of the cam in [s]. For negative values of OffCompensation the switching time is brought forward, otherwise it is delayed.
Hysteresis | not implemented. Hysteresis of the switching operations for reversing the rotation direction. The hysteresis is specified in the position unit of the axis.
BreakRelease | Brake enable for brake cams on this cam track
Force | The digital output is activated independent of the cams on this track. Disable has priority over Force.
Disable | The digital output is deactivated independent of the cams on this track. Disable has priority over Force.

Description of time compensation


XFC_TRIGGER_REF

TwinCAT PLC Library: TcMC2 XFC

Data type XFC_TRIGGER_REF

The data type XFC_TRIGGER_REF contains the state and parameters of a digital input that is used for the function XFC_TouchProbe .

TYPE XFC_TRIGGER_REF :
STRUCT
    Signal 			: BOOL;
    TimestampRisingEdge 	: T_DCTIME32;
    TimestampFallingEdge	: T_DCTIME32;

    Edge 			: E_SignalEdge;
    FreeRun 			: BOOL;
    EncoderIndex 		: UINT;
    ModuloPositions 		: BOOL;
    ModuloFactor 		: LREAL := 360.0;
END_STRUCT
END_TYPE
Signal Current state of the digital input signal.
The current state must be supplied here.
TimestampRisingEdge Time stamp of the last rising edge of the digital input signal.
Only the time stamp of the edge defined via Edge has to be supplied.
If the input signal supplies a 64-bit time stamp T_DCTIME, only the lower 32 bits are supplied. It is therefore important to ensure that the value at the time of the evaluation is not older than 2 seconds.
TimestampFallingEdge Time stamp of the last falling edge of the digital input signal.
Only the time stamp of the edge defined via Edge has to be supplied.
If the input signal supplies a 64-bit time stamp T_DCTIME, only the lower 32 bits are supplied. It is therefore important to ensure that the value at the time of the evaluation is not older than 2 seconds.
Edge Edge defines the signal edge to be used for the evaluation of the axis position.
TYPE E_SignalEdge :
(
    RisingEdge,
    FallingEdge
);
END_TYPE
FreeRun If FreeRun is TRUE, the input is latched continuously.
In this case the input Execute must remain TRUE in function block XFC_TouchProbe. No edge at Execute is required in order to record the next new position value.
EncoderIndex | If more than one encoder is connected to the axis, the encoder index [0..9] can be specified here. First encoder is always index 0.
ModuloPositions | If Modulo=TRUE, all positions are interpreted as modulo. The parameter ModuloFactor is used for calculating the modulo cycle.
ModuloFactor | ModuloFactor indicates the length of a modulo cycle in the positioning unit of the axis and is only used if Modulo=TRUE.