General functioning of the FB_CTRL_... Function blocks

The general functioning of the function blocks in the Controller Toolbox are described in the following paragraphs.

General Notes

General Notes

In general, the TcControllerToolbox can be used on PC, BX or BC systems. If the toolbox is used on a BC system, the maximum number of POUs has to be adjusted in the PLC control under menu item Project, Options...

General functioning of the FB_CTRL_... Function blocks 1:

Discretization

The continuous transfer functions of the transfer elements assembled in this library are transformed to discrete values using the trapezoidal rule (Tustin formula).

The Tustin formula:

General functioning of the FB_CTRL_... Function blocks 2:

Function block inputs

eMode:

The operating mode of the majority of blocks can be selected with this input. This makes it possible to select one of the following operating modes:

eCTRL_MODE_PASSIVE

The output or outputs of the block are set to zero, but the internal states are retained.

eCTRL_MODE_ACTIVE

The block is executed in accordance with its description, and appropriate output values are calculated (normal operation).

eCTRL_MODE_RESET

All internal states are reset in this operating mode, and the error bit is cleared.

eCTRL_MODE_MANUAL

The value of the input value fManSyncValue is provided at the output (manual operation).

stParams:

The necessary parameters are passed to the function block with this structure. The variables tTaskCycleTime and tCtrlCycleTime are contained in all the parameter structures. These parameters function in the following way:

The parameter tTaskCycleTime specifies the cycle time with which the function block is called. If the block is called in every cycle this corresponds to the cycle time of the calling task. If it is only called in every second cycle, the time must correspondingly be doubled. The parameter tCtrlCycleTime indicates the control loop's sampling time. This time must be greater than or equal to the parameter tTaskCycleTime. If the sampling time is set equal to tTaskCycleTime then the block is executed with every call. If a factor of 5 greater is selected, the block is only processed in every 5th call. This makes it possible to implement slow control loops even in a fast task.

The parameters tTaskCycleTime and tCtrlCycleTime are of type TIME and therefore do not permit inputs of less than 1ms. To use the controller in a fast PLC task with a cycle time of less than 1ms, a global base time can be specified as reference for the specified cycle times. Notes on using the base time.

Examples:

It is assumed that the block is called in every task cycle.

Task Configuration

Parameter: tTaskCycleTime

Parameter: tCtrlCycleTime

Method of operation:

T#10ms

T#10ms

T#10ms

The control loop is processed using a 10 ms sampling time.

T#10ms

T#10ms

T#50ms

The control loop is processed using a 50 ms sampling time.

T#100ms

T#100ms

T#100ms

The control loop is processed using a 100 ms sampling time.

T#100ms

T#100ms

T#50ms

ERROR, execution not possible!

T#100ms

T#50ms

T#50ms

ERROR, although the block has been executed, incorrect output values have been calculated!

The outputs of the function blocks

eState:

This output indicates the current internal state of the block.

eCTRL_STATE_IDLE

The block has successfully been reset, and is now waiting for selection of the operating mode.

eCTRL_STATE_PASSIVE

The block is in the passive state in which no calculations are carried out.

eCTRL_STATE_ACTIVE

The block is in the active state, which is the normal operating state.

eCTRL_STATE_RESET

A reset request is being processed, but the reset has not yet been completed.

eCTRL_STATE_MANAUL

The block is in the manual state, and the output can be manually specified at the appropriate input.

eCTRL_STATE_...

If there are any other internal states, they are described together with the corresponding blocks.

eCTRL_STATE_ERROR

An error has occurred; the block is not executed when in this state. See eErrorId for further information.

bError:

An error in the block is indicated by an TRUE at this boolean output.

eErrorId:

The error number is provided at this output if the bError output is TRUE.

Using the global base time (only available on a PC system)

In order to be able to use the function blocks of a PLC task with a cycle time of less than 1ms, it is possible to interpret the specified cycle times as ticks of a base time. In this special parameterization, the time unit of 1ms is interpreted as 1 tick. This approach is equivalent to setting a PLC cycle time of less than 1ms in the TwinCAT System Manager.

The switchover and declaration of the base time is done with the global structure stCtrl_GLOBAL_CycleTimeInterpretation for all function blocks of the toolbox.

VAR_GLOBAL
    stCtrl_GLOBAL_CycleTimeInterpretation : ST_CTRL_CYCLE_TIME_INTERPRETATION;
END_VAR
TYPE ST_CTRL_CYCLE_TIME_INTERPRETATION :
STRUCT
    bInterpretCycleTimeAsTicks : BOOL;  (* e.g. 2ms -> 2ticks
*)
    fBaseTime                  : FLOAT; (* Base time in seconds,
e.g. 200µs -> 200E-6s *)
END_STRUCT
END_TYPE

In order to interpret the specified cycle times as ticks, the variable bInterpretCycleTimeAsTicks in the global structure stCtrl_GLOBAL_CycleTimeInterpretation is set to TRUE. Within this structure, the base time unit has to be set in variable fBaseTime.

By setting the flag bInterpretCycleTimeAsTicks, the interpretation of the parameters with the names

is changed. The interpretation and effect of all other parameters of type TIME remains unaffected.

Sample:

The base time unit of the TwinCAT system is 200µs. The PLC task, and therefore the function blocks of the Toolbox, are called cyclically every 400µs.

Setting the global structure:

stCtrl_GLOBAL_CycleTimeInterpretation.bInterpretCycleTimeAsTicks := TRUE;
stCtrl_GLOBAL_CycleTimeInterpretation.fBaseTime          := 200E-6;

Parameterization of a function block from the Toolbox:

stParams.tTaskCycleTime    := T#2ms;  (*2*200µs=400µs *)
stParams.tCtrlCycleTime    := T#4ms;  (*4*200µs=800µs *)
stParams. ...

The TaskCycleTime specified on the function blocks is 2•200E-6s = 400µs and thus corresponds to the set PLC cycle time. The CtrlCycleTime is set to 800µs = 4•200E-6s, so that the control loop operates with a sampling time of 800µs, i.e. it is processed during every second PLC cycle.