Real-Time, Synchronous External Task

Overview

The real-time, synchronous external task is an external task that is synchronous with the Sercos RTP (Real-Time Process). The real-time, synchronous external task is triggered in the RTP and executed after the RTP finishes.

A typical usecase for the real-time task is position capture in the millisecond range without the use of touch probes.

Description

The controller-internal real-time tasks which handles Sercos communication and calculations for the axes triggers the AFTER_RTP event in each cycle. This event can be used to trigger a motion controller code task of the type External triggered as an external event.

With this parameterization, the real-time, synchronous external task is triggered as soon as possible after the real-time task is finished.

The priorities of the motion controller code tasks are respected. Therefore, even if this event-triggered task is already triggered by RTP, it is delayed if another task with a higher priority is triggered as well.

The task can be interrupted by the RTP.

Configuration

Procedure:

Step

Action

1

In the Device Tree, display the Task Configuration window.

2

From the listbox Type, select the item External.

3

From the listbox External Event, select the item AFTER_RTP.

4

Set a task priority and enable a Watchdog as required by your application.

NOTE: Refer to the M262 Programming Guide for additional information on the task configuration screen and on task priorities.

Cycle Time Considerations

The cycle time of the RTP only applies to the Sercos communication phase 4.

Cycle time of real-time, synchronous external task in Sercos communication phases:

Sercos communication phase

Cycle time

NRT

4 ms

0

2 ms

1

1 ms

2

1 ms

3

Sercos cycle time

4

Sercos cycle time

If the execution time of the RTP, the real-time, synchronous external task, and other tasks with higher priority exceeds the Sercos cycle time, the real-time, synchronous external task is interrupted by the RTP. In such a case, the real-time, synchronous external task is no longer synchronous with the RTP.

To keep the real-time, synchronous external task synchronous with the RTP, ensure that the execution time of the real-time, synchronous external task plus the execution time of the RTP does not exceed the configured Sercos cycle time. Example code:

hTask : RTS_IEC_HANDLE;
pstTaskInfo : POINTER TO CmpIecTask.Task_Info2;
udiResult : RTS_IEC_RESULT;
dwCycleTimeInUs : DWORD;
bLossOfSynchronicity : BOOL;
lrRtpCycleTimeInUs : LREAL;
lrPercentageOfRtpCycle : LREAL;

hTask := CmpIecTask.IecTaskGetCurrent(ADR(udiResult));
IF udiResult = 0 THEN
    pstTaskInfo := CmpIecTask.IecTaskGetInfo3(hTask, ADR(udiResult));
    IF udiResult = 0 THEN
        dwCycleTimeInUs := pstTaskInfo^.dwCycleTime;
    END_IF
END_IF

lrPercentageOfRtpCycle := S3M.FC_GetMotionCycleTaskLoadOfLastCycle();
lrRtpCycleTimeInUs := lrPercentageOfRtpCycle * (UDINT_TO_LREAL(SercosMaster.SercosCycletimeConfig.Cycletime) / 1E5);

IF (udiResult = 0) AND ( (lrRtpCycleTimeInUs + DWORD_TO_LREAL(dwCycleTimeInUs)) > UDINT_TO_LREAL(SercosMaster.SercosCycletimeConfig.Cycletime / 1000) ) THEN
    // loss of synchronicity
    bLossOfSynchronicity := TRUE;
    // TODO stop machine
END_IF