FB_CTRL_GET_TASK_CYCLETIME

FB_CTRL_GET_TASK_CYCLETIME 1:

This function block allows the task cycle time of a program to be determined with a resolution of 1 ms.

FB_CTRL_GET_TASK_CYCLETIME 2:

Correct use of the function block

The TaskCycleTime can only be correctly determined if the program does not contain any active breakpoints.
The task cycle time is only determined once. No further measurements are taken if either of the bCycleTimeValid or bError outputs is TRUE.

Do not use this function block if you use cycle times that are less than 1 ms or not multiples of 1 ms

FB_CTRL_GET_TASK_CYCLETIME 3: VAR_INPUT

VAR_INPUT
    eMode : E_CTRL_MODE;
END_VAR

Name

Type

Description

eMode

E_CTRL_MODE

Input that specifies the operation mode of the function block.

FB_CTRL_GET_TASK_CYCLETIME 4: VAR_OUTPUT

VAR_OUTPUT
    tTaskCycleTime   : TIME;
    bCycleTimeValid  : BOOL;
    eState           : E_CTRL_STATE;
    eErrorId         : E_CTRL_ERRORCODES;
    bError           : BOOL;
END_VAR

Name

Type

Description

tTaskCycleTime

TIME

This output indicates the current task cycle time, with a resolution of 1 ms.

bCycleTimeValid

BOOL

The time contained in the tTaskCycleTime output is valid when this output is TRUE.

eState

E_CTRL_STATE

State of the function block

eErrorId

E_CTRL_ERRORCODES

Supplies the error number when the output bError is set.

bError

BOOL

Becomes TRUE, as soon as an error occurs.

Sample:

PROGRAM PRG_GET_TASK_CYCLETIME_TEST
VAR
    tTaskCycleTime     : TIME;
    bCycleTimeValid    : BOOL;
    eState             : E_CTRL_STATE;
    eErrorId           : E_CTRL_ERRORCODES;
    bError             : BOOL;
    fbCTRL_GET_TASK_CYCLETIME : FB_CTRL_GET_TASK_CYCLETIME;
    bInit              : BOOL := TRUE;
    fSetpointValue     : FLOAT := 45.0;
    fActualValue       : FLOAT;
    fbCTRL_PI          : FB_CTRL_PI;
    stCTRL_PI_Params   : ST_CTRL_PI_PARAMS;
    fbCTRL_PT1         : FB_CTRL_PT1;
    stCTRL_PT1_Params  : ST_CTRL_PT1_PARAMS;
END_VAR
fbCTRL_GET_TASK_CYCLETIME( eMode    := eCTRL_MODE_ACTIVE,
                           tTaskCycleTime  => tTaskCycleTime,
                           bCycleTimeValid => bCycleTimeValid,
                           eState          => eCTRL_MODE_ACTIVE,
                           eErrorId        => eErrorId,
                           bError          => bError );
IF fbCTRL_GET_TASK_CYCLETIME.bCycleTimeValid
THEN
    IF bInit
    THEN
        stCTRL_PT1_Params.tTaskCycleTime := fbCTRL_GET_TASK_CYCLETIME.tTaskCycleTime;
        stCTRL_PT1_Params.tCtrlCycleTime := T#100ms;
        stCTRL_PT1_Params.fKp := 1.0;
        stCTRL_PT1_Params.tT1 := T#10s;
        stCTRL_PI_Params.tTaskCycleTime := fbCTRL_GET_TASK_CYCLETIME.tTaskCycleTime;
        stCTRL_PI_Params.tCtrlCycleTime := T#100ms;
        stCTRL_PI_Params.fKp := 0.5;
        stCTRL_PI_Params.tTn := T#5s;
        stCTRL_PI_Params.fOutMaxLimit := 100.0;
        stCTRL_PI_Params.fOutMinLimit := 0.0;
        bInit := FALSE;
END_IF
fbCTRL_PI( fActualValue := fbCTRL_PT1.fOut,
         fSetpointValue := fSetpointValue,
         eMode := eCTRL_MODE_ACTIVE,
         stParams := stCTRL_PI_Params );
fbCTRL_PT1( fIn := fbCTRL_PI.fOut,
            eMode := eCTRL_MODE_ACTIVE,
            stParams := stCTRL_PT1_Params,
            fOut => fActualValue );
END_IF