TwinCAT PLC Control Toolbox library

BECHHOFF

2

Contents
1. OVERVIEW .......................................................................................................................... 4 2. GENERAL FUNCTIONING OF THE FB_CTRL_... FUNCTION BLOCKS .......................... 7 3. FUNCTION BLOCKS......................................................................................................... 11
3.1. AUXILARY .................................................................................................................................................................... 11 FUNCTION_BLOCK FB_CTRL_GET_SYSTEM_TIME (only on a PC system) ........................................................... 11 FUNCTION_BLOCK FB_CTRL_GET_TASK_CYCLETIME (only on a PC system).................................................... 13 FUNCTION_BLOCK FB_CTRL_LOOP_SCHEDULER................................................................................................. 15 3.2. Base.................................................................................................................................................................................. 19 FUNCTION_BLOCK FB_CTRL_D.................................................................................................................................. 19 FUNCTION_BLOCK FB_CTRL_HYSTERESIS............................................................................................................. 21 FUNCTION_BLOCK FB_CTRL_I ................................................................................................................................... 23 FUNCTION_BLOCK FB_CTRL_P .................................................................................................................................. 25 FUNCTION_BLOCK FB_CTRL_TRANSFERFUNCTION_1 ........................................................................................ 26 FUNCTION_BLOCK FB_CTRL_TRANSFERFUNCTION_2 ........................................................................................ 30 3.3. Controller ........................................................................................................................................................................ 35 FUNCTION_BLOCK FB_CTRL_2POINT....................................................................................................................... 35 FUNCTION_BLOCK FB_CTRL_2POINT_PWM_ADAPTIVE...................................................................................... 37 FUNCTION_BLOCK FB_CTRL_3POINT....................................................................................................................... 40 FUNCTION_BLOCK FB_CTRL_3POINT_EXT ............................................................................................................. 43 FUNCTION_BLOCK FB_CTRL_nPOINT....................................................................................................................... 46 FUNCTION_BLOCK FB_CTRL_PARAMETER_SWITCH ........................................................................................... 48 FUNCTION_BLOCK FB_CTRL_PI ................................................................................................................................. 51 FUNCTION_BLOCK FB_CTRL_PI_PID......................................................................................................................... 54 FUNCTION_BLOCK FB_CTRL_PID .............................................................................................................................. 58 FUNCTION_BLOCK FB_CTRL_PID_EXT_SPLITRANGE .......................................................................................... 63 FUNCTION_BLOCK FB_CTRL_PID_EXT .................................................................................................................... 69 FUNCTION_BLOCK FB_CTRL_PID_SPLITRANGE.................................................................................................... 75 3.4. Filter ................................................................................................................................................................................ 81 FUNCTION_BLOCKFB_CTRL_ACTUAL_VALUE_FILTER....................................................................................... 81 FUNCTION_BLOCK FB_CTRL_ARITHMETIC_MEAN .............................................................................................. 83 FUNCTION_BLOCK FB_CTRL_DIGITAL_FILTER ..................................................................................................... 84 FUNCTION_BLOCK FB_CTRL_MOVING_AVERAGE ............................................................................................... 88 FUNCTION_BLOCK FB_CTRL_NOISE_GENERATOR(only on a PC system)............................................................ 90 FUNCTION_BLOCK FB_CTRL_PT1.............................................................................................................................. 92 FUNCTION_BLOCK FB_CTRL_PT2.............................................................................................................................. 94 FUNCTION_BLOCK FB_CTRL_PT2oscillation ............................................................................................................. 97 FUNCTION_BLOCK FB_CTRL_PT3.............................................................................................................................. 99 FUNCTION_BLOCK FB_CTRL_PTn............................................................................................................................ 101 FUNCTION_BLOCK FB_CTRL_PTt............................................................................................................................. 103 FUNCTION_BLOCK FB_CTRL_SERVO_MOTOR_SIMULATION (only on a PC system) ..................................... 105 FUNCTION_BLOCK FB_CTRL_TuTg.......................................................................................................................... 108

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

3

3.5. Interpolation ................................................................................................................................................................. 110 FUNCTION_BLOCK FB_CTRL_LIN_INTERPOLATION .......................................................................................... 110 FUNCTION_BLOCK FB_CTRL_NORMALIZE ........................................................................................................... 113 3.6. Monitoring/Alarming ................................................................................................................................................... 116 FUNCTION_BLOCK FB_CTRL_CHECK_IF_IN_BAND ............................................................................................ 116 FUNCTION_BLOCK FB_CTRL_LOG_DATA (only on a PC system) ......................................................................... 118 FUNCTION_BLOCK FB_CTRL_LOG_MAT_FILE (only on a PC system) ................................................................. 120 3.7. Output to controlling equipment................................................................................................................................. 126 FUNCTION_BLOCK FB_CTRL_DEADBAND ............................................................................................................ 126 FUNCTION_BLOCK FB_CTRL_LIMITER .................................................................................................................. 128 FUNCTION_BLOCK FB_CTRL_MULTIPLE_PWM_OUT ......................................................................................... 130 FUNCTION_BLOCK FB_CTRL_PWM_OUT............................................................................................................... 135 FUNCTION_BLOCK FB_CTRL_PWM_OUT_EXT ..................................................................................................... 137 FUNCTION_BLOCK FB_CTRL_SCALE ...................................................................................................................... 140 FUNCTION_BLOCK FB_CTRL_SERVO_MOTOR_OUT ........................................................................................... 142 FUNCTION_BLOCK FB_CTRL_SPLITRANGE .......................................................................................................... 145 FUNCTION_BLOCK FB_CTRL_STEPPING_MOTOR_OUT...................................................................................... 148 3.8. Setpoint generation....................................................................................................................................................... 151 FUNCTION_BLOCK FB_CTRL_3PHASE_SETPOINT_GENERATOR(only on a PC system) .................................. 151 FUNCTION_BLOCK FB_CTRL_RAMP_GENERATOR ............................................................................................. 159 FUNCTION_BLOCK FB_CTRL_RAMP_GENERATOR_EXT.................................................................................... 161 FUNCTION_BLOCK FB_CTRL_SETPOINT_GENERATOR...................................................................................... 164 FUNCTION_BLOCK FB_CTRL_SIGNAL_GENERATOR .......................................................................................... 167

APPENDIX ........................................................................................................................... 170
Definition of the structures and enums.............................................................................................................................. 170 FLOAT: ............................................................................................................................................................................ 170 E_CTRL_MODE:............................................................................................................................................................. 170 E_CTRL_STATE : ........................................................................................................................................................... 170 E_CTRL_ERRORCODES: .............................................................................................................................................. 171 E_CTRL_SIGNAL_TYPE:.............................................................................................................................................. 176

EXAMPLE PROJECT .......................................................................................................... 176

TwinCAT PLC Library: Controller Toolbox

Complex controllers that can be used for a large number of applications are included. Overview This library contains function blocks that represent various control engineering transfer elements in a functional diagram.BECHHOFF 4 1. Function blocks Name FB_CTRL_2POINT FB_CTRL_2POINT_PWM_ADAPTIVE FB_CTRL_3PHASE_SETPOINT_GENERATOR FB_CTRL_3POINT FB_CTRL_3POINT_EXT FB_CTRL_ACTUAL_VALUE_FILTER FB_CTRL_ARITHMETIC_MEAN FB_CTRL_CHECK_IF_IN_BAND FB_CTRL_D FB_CTRL_DEADBAND Description 2-position controller Adaptive 2-position controller with PWM output 3 phase setpoint generator 3-position controller Extended 3-position controller Actual value filter Arithmetic mean filter Range monitoring D element Dead band TwinCAT PLC Library: Controller Toolbox . as well as basic blocks with which unique controller structures can be implemented for special applications.

csv ASCII format Data logger in Matlab 5 format Schedules computing power if several loops exist. Moving average filter PWM element with multiple outputs Characteristic curve linearisation Noise generator n-position controller P element Parameter switching algorithm for a split range controller PI controller Cascaded PI-PID controller PID controller Extended PID controller Extended PID regulator with parameter switching PID regulator with parameter switching PT1 element PT2 element Oscillating PT2 element TwinCAT PLC Library: Controller Toolbox .BECHHOFF 5 FB_CTRL_DIGITAL_FILTER FB_CTRL_GET_SYSTEM_TIME FB_CTRL_GET_TASK_CYCLETIME FB_CTRL_HYSTERESIS FB_CTRL_I FB_CTRL_LIMITER FB_CTRL_LIN_INTERPOLATION FB_CTRL_LOG_DATA FB_CTRL_LOG_MAT_FILE FB_CTRL_LOOP_SCHEDULER FB_CTRL_MOVING_AVERAGE FB_CTRL_MULTIPLE_PWM_OUT FB_CTRL_NORMALIZE FB_CTRL_NOISE_GENERATOR FB_CTRL_nPOINT FB_CTRL_P FB_CTRL_PARAMETER_SWITCH FB_CTRL_PI FB_CTRL_PI_PID FB_CTRL_PID FB_CTRL_PID_EXT FB_CTRL_PID_EXT_SPLITRANGE FB_CTRL_PID_SPLITRANGE FB_CTRL_PT1 FB_CTRL_PT2 FB_CTRL_PT2oscillation Digital filter Output windows system time Get task cycle time Hysteresis element I element Control value limiter Linear interpolation element Data logger in *.

htm FB_CTRL_SPLITRANGE FB_CTRL_STEPPING_MOTOR_OUT FB_CTRL_TRANSFERFUNCTION_I FB_CTRL_TRANSFERFUNCTION_II FB_CTRL_TuTg Split range in positive and negative part Controlling stepper motor Transfer function according to the first standard form Transfer function according to the second standard form TuTg element TwinCAT PLC Library: Controller Toolbox .BECHHOFF 6 FB_CTRL_PT3 FB_CTRL_PTn FB_CTRL_PTt FB_CTRL_PWM_OUT FB_CTRL_PWM_OUT_EXT FB_CTRL_RAMP_GENERATOR FB_CTRL_RAMP_GENERATOR_EXT FB_CTRL_SCALE FB_CTRL_SERVO_MOTOR_OUT FB_CTRL_SERVO_MOTOR_SIMULATION FB_CTRL_SETPOINT_GENERATOR PT3 element PTn element PTt-Glied PWM element Extended PWM element Ramp generator Extended ramp generator Range adjustment Controlling of a servo motor Simulation of a servo motor Set value generator FB_CTRL_SIGNAL_GEC:\TwinCAT\InfoSystem\1 Signal generator 033\ABCTempHTMLTcPlcLibContoller_CTR L_Signal_Generator.

Function blocks The general functioning of the blocks in the Controller Tool box are described in the following paragraphs. Discretisation The continuous transfer functions of the transfer elements assembled in this library are transformed to discrete values using the trapezoidal rule (Tustin formula). 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. The Tustin formula: TwinCAT PLC Library: Controller Toolbox ... BX or BC systems. General functioning of the FB_CTRL_. the TcControllerToolbox can be used on PC. General Notes In general. Options.BECHHOFF 7 2...

the block is only processed in every 5th call. and appropriate output values are calculated (normal operation). The block is executed in accordance with its description. ERROR.BECHHOFF 8 Function block inputs eMode: The operating mode of the majority of blocks can be selected with this input. eCTRL_MODE_RESET eCTRL_MODE_MANUAL stParams: The necessary parameters are passed to the function block with this structure. This time must be greater than or equal to the parameter tTaskCycleTime. This makes it possible to select one of the following operating modes: eCTRL_MODE_PASSIVE eCTRL_MODE_ACTIVE The output or outputs of the block are set to zero. This makes it possible to implement slow control loops even in a fast task. a global base time can be specified as reference for the specified cycle times. incorrect output values have been calculated! TwinCAT PLC Library: Controller Toolbox . If the block is called in every cycle this corresponds to the cycle time of the calling task. The control loop is processed using a 100 ms sampling time. The control loop is processed using a 50 ms sampling time. If the sampling time is set equal to tTaskCycleTime then the block is executed with every call. Task Configuration T#10ms T#10ms T#100ms T#100ms T#100ms Parameter: tTaskCycleTime T#10ms T#10ms T#100ms T#100ms T#50ms Parameter: tCtrlCycleTime T#10ms T#50ms T#100ms T#50ms T#50ms Method of operation: The control loop is processed using a 10 ms sampling time. the time must correspondingly be doubled. In order to use the controller in a fast PLC task with a cycle time of less than 1ms. If a factor of 5 greater is selected. The parameter tCtrlCycleTime indicates the control loop's sampling time. The parameters tTaskCycleTime and tCtrlCycleTime are of type TIME and therefore do not permit inputs of less than 1ms. The variables tTaskCycleTime and tCtrlCycleTime are contained in all the parameter structures. execution not possible! ERROR. The value of the input value fManSyncValue is provided at the output (manual operation). and the error bit is cleared. Examples: It is assumed that the block is called in every task cycle. Notes on using the base time. If it is only called in every second cycle. although the block has been executed. but the internal states are retained. These parameters function in the following way: The parameter tTaskCycleTime specifies the cycle time with which the function block is called. All internal states are reset in this operating mode.

(* Base time in seconds. If there are any other internal states. bError: An error in the block is indicated by an TRUE at this boolean output. eCTRL_STATE_MANAUL The block is in the manual state. which is the normal operating state.. eCTRL_STATE_PASSIVE The block is in the passive state in which no calculations are carried out. eCTRL_STATE_. (* e. eErrorId: The error number is provided at this output if the bError output is TRUE. eCTRL_STATE_ERROR An error has occurred. and is now waiting for selection of the operating mode.g. it is possible to interpret the specified cycle times as ticks of a base time. they are described together with the corresponding blocks.. but the reset has not yet been completed. VAR_GLOBAL stCtrl_GLOBAL_CycleTimeInterpretation : ST_CTRL_CYCLE_TIME_INTERPRETATION. This approach is equivalent to setting a PLC cycle time of less than 1ms in the TwinCAT System Manager. eCTRL_STATE_ACTIVE The block is in the active state. END_VAR TYPE ST_CTRL_CYCLE_TIME_INTERPRETATION : STRUCT bInterpretCycleTimeAsTicks : BOOL. the base time unit has to be set in variable fBaseTime. the time unit of 1ms is interpreted as 1 tick. In this special parameterisation. eCTRL_STATE_IDLE The block has successfully been reset.g. eCTRL_STATE_RESET A reset request is being processed. Within this structure. e. 2ms -> 2ticks *) fBaseTime : FLOAT. See eErrorId for further information. and the output can be manually specified at the appropriate input. 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. The switchover and declaration of the base time is done with the global structure stCtrl_GLOBAL_CycleTimeInterpretation for all function blocks of the toolbox. the block is not executed when in this state. the variable bInterpretCycleTimeAsTicks in the global structure stCtrl_GLOBAL_CycleTimeInterpretation is set to TRUE. 200µs -> 200E-6s *) END_STRUCT END_TYPE In order to interpret the specified cycle times as ticks. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 9 The outputs of the function blocks eState: This output indicates the current internal state of the block.

so that the control loop operates with a cycle time of 800µs.e. the interpretation of the parameters with the names • • tTaskCycleTime tCtrlCycleTime is changed. The TaskCycleTime specified at the blocks is 2•200E-6s = 400µs and therefore corresponds to the set PLC cycle time.. . (* 2*200µs=400µs *) stParams.. it is processed during every second PLC cycle. TwinCAT PLC Library: Controller Toolbox . are called cyclically every 400µs. and therefore the Toolbox blocks. The interpretation and effect of all other parameters of type TIME remains unaffected.tCtrlCycleTime := T#4ms. Setting the global structure: stCtrl_GLOBAL_CycleTimeInterpretation.bInterpretCycleTimeAsTicks := TRUE.BECHHOFF 10 By setting the flag bInterpretCycleTimeAsTicks.fBaseTime := 200E-6. Parameterisation of a function block from the Toolbox: stParams. The CtrlCycleTime is set to 800µs = 4•200E-6s. The PLC task. Example: The base time unit of the TwinCAT system is 200µs. i. stCtrl_GLOBAL_CycleTimeInterpretation.tTaskCycleTime := T#2ms. (* 4*200µs=800µs *) stParams.

Description: This function block makes the current system time available in its output structure. : E_CTRL_ERRORCODES. If this is not done. FUNCTION BLOCKS 3. : WORD. the resolution will be reduced to 2 • tCtrlCycleTime. : WORD. : BOOL. : TIMESTRUCT. : WORD.BECHHOFF 11 3. VAR_OUTPUT VAR_OUTPUT stSystemTime eErrorId bError END_VAR TYPE TIMESTRUCT STRUCT wYear wMonth wDayOfWeek wDay wHour wMinute wSecond : WORD. AUXILARY FUNCTION_BLOCK FB_CTRL_GET_SYSTEM_TIME (only on a PC system) This function block reads the current Windows system time. The resolution is specified through the tCtrlCycleTime parameter. wMilliseconds : WORD.1. and it is necessary to observe the condition tCtrlCycleTime > 2 • tTaskCycleTime. : WORD. making it available in SystemTimeStruct. : WORD. : WORD. the maximum resolution is 10 ms. END_STRUCT END_TYPE TwinCAT PLC Library: Controller Toolbox .

tTaskCycleTime : Cycle time with which the function block is called. wMilliseconds : Millisecond: 0 ~ 999.). wDay : The day of the month: 1 ~ 31.BECHHOFF 12 stSystemTime : Structure in which the system time is output. February = 2 etc.lib TwinCAT PLC Library: Controller Toolbox . wMinute : Minute: 0 ~ 59. (* task cycle time [TIME] *) tCtrlCycleTime : TIME.). wDayOfWeek : The day of the week: 0 ~ 6 (Sunday = 0. This consists of the following elements: TYPE ST_CTRL_GET_SYSTEM_TIME: STRUCT tTaskCycleTime : TIME. wHour : Hour: 0 ~ 23. (* controller cycle time [TIME] *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. wSecond : Second: 0 ~ 59. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. VAR_IN_OUT VAR_IN_OUT stParams: ST_CTRL_GET_SYSTEM_TIME. : Becomes TRUE as soon as an error situation occurs. Monday = 1 etc. If the block is called in every task cycle this corresponds to the task cycle time of the calling task. END_VAR stParams : Parameter structure of the function block. Development environment TwinCAT v2. wMonth : The month: 1 ~ 12 (January = 1. wYear : The year: 1970 ~ 2106.8 Target system type PC (i386) PLC libraries to be linked TcControllerToolbox. eErrorId bError : Supplies the error number when the bError output is set. This must be greater than or equal to the TaskCycleTime.

BECHHOFF 13 FUNCTION_BLOCK FB_CTRL_GET_TASK_CYCLETIME (only on a PC system) This function block allows the task cycle time of a program to be determined with a resolution of 1 ms. : Supplies the error number when the bError output is set. No further measurements are taken if either of the bCycleTimeValid or bError outputs is TRUE. as soon as an error occurs.The task cycle time is only determined once.This block should not be used if cycle times of less than 1 ms. Warning:: . : State of the function block. : Becomes TRUE. or that are not a multiple of 1 ms. (* resolution: 1ms *) TwinCAT PLC Library: Controller Toolbox . . are in use. : E_CTRL_STATE. VAR_INPUT VAR_INPUT eMode: E_CTRL_MODE. : BOOL. with a resolution of 1 ms. VAR_OUTPUT VAR_OUTPUT tTaskCycleTime bCycleTimeValid eState eErrorId bError END_VAR tTaskCycleTime : This output indicates the current task cycle time. . bCycleTimeValid eState eErrorId bError : The time contained in the tTaskCycleTime output is valid when this output is TRUE.The TaskCycleTime can only be correctly determined if the program does not contain any active breakpoints. END_VAR eMode : Input that specifies the block's operating mode. : TIME. : BOOL. : E_CTRL_ERRORCODES.

BECHHOFF 14 Example: PROGRAM PRG_GET_TASK_CYCLETIME_TEST VAR tTaskCycleTime : TIME. (* control loop *) bInit : BOOL := TRUE.fKp := 1. stCTRL_PI_Params.fOutMaxLimit := 100. bCycleTimeValid => bCycleTimeValid. stCTRL_PI_Params. eState => eCTRL_MODE_ACTIVE. stParams := stCTRL_PT1_Params. stCTRL_PT1_Params.tCtrlCycleTime := T#100ms.fKp := 0. stCTRL_PI_Params. fbCTRL_PI : FB_CTRL_PI. END_VAR (* call fb to get the task cycle time *) fbCTRL_GET_TASK_CYCLETIME( eMode := eCTRL_MODE_ACTIVE.bCycleTimeValid THEN IF bInit THEN stCTRL_PT1_Params. eState : E_CTRL_STATE. fActualValue : FLOAT. bInit := FALSE. stCTRL_PT1_Params : ST_CTRL_PT1_PARAMS.tT1 := T#10s. fbCTRL_PT1 : FB_CTRL_PT1. eErrorId => eErrorId. stCTRL_PI_Params : ST_CTRL_PI_PARAMS. fSetpointValue := fSetpointValue.fOutMinLimit := 0. stCTRL_PI_Params. eMode := eCTRL_MODE_ACTIVE. TwinCAT PLC Library: Controller Toolbox .tTaskCycleTime := fbCTRL_GET_TASK_CYCLETIME.tTaskCycleTime := fbCTRL_GET_TASK_CYCLETIME.0.fOut.tTn := T#5s. fSetpointValue : FLOAT := 45. bError => bError ). fbCTRL_GET_TASK_CYCLETIME : FB_CTRL_GET_TASK_CYCLETIME. bCycleTimeValid : BOOL.0. stCTRL_PT1_Params. stCTRL_PI_Params. tTaskCycleTime => tTaskCycleTime.fOut. (* call PT1 *) fbCTRL_PT1( fIn := fbCTRL_PI.tCtrlCycleTime := T#100ms. eMode := eCTRL_MODE_ACTIVE.0.0. (* call control loop if the cycle time is valid *) IF fbCTRL_GET_TASK_CYCLETIME.5. stCTRL_PI_Params.tTaskCycleTime. stParams := stCTRL_PI_Params ). eErrorId : E_CTRL_ERRORCODES.tTaskCycleTime. END_IF (* call controller *) fbCTRL_PI( fActualValue := fbCTRL_PT1. bError : BOOL. stCTRL_PT1_Params.

BECHHOFF

15

fOut ); END_IF

=> fActualValue

Development environment TwinCAT v2.8

Target system type PC (i386)

PLC libraries to be linked TcControllerToolbox.lib

FUNCTION_BLOCK FB_CTRL_LOOP_SCHEDULER

This function block allows the system loading to be distributed over a number of control loops that are a) parameterised using the same tCtrlCycleTime and b) for which the condition tCtrlCycleTime > tTaskCycleTime is true. The output vector calculated by this block is used to start the individual control loops at different times, so that the system loading is distributed.

Behaviour of the output vector:

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

16

6 control loops are managed in this diagram. In this case, tCtrlCycleTime = 7

· tTaskCycleTime.

The programmer must create the following array in the PLC if this function block is to be used: arrOutputVector : ARRAY[1..nNumberOfControlLoops] OF BOOL; The function block sets the bits in this vector to TRUE or FALSE. The control loops that are managed with the loop scheduler are only switched into the eCTRL_MODE_ACTIVE state when the corresponding bit in the output vector is TRUE. See example code below.

VAR_INPUT
VAR_INPUT nManValue : DWORD;

eMode: E_CTRL_MODE; END_VAR
nManValue : This input allows the first 32 bits in the output vector to be set in eCTRL_MODE_MANUAL. A 1 sets the first bit, a 2 the second bit, a 3 the first and second bits, ... eMode : Input that specifies the block's operating mode.

VAR_OUTPUT
VAR_OUTPUT eState eErrorId bError END_VAR
eState eErrorId bError : State of the function block. : Supplies the error number when the bError output is set. : Becomes TRUE, as soon as an error occurs.

: E_CTRL_STATE; : E_CTRL_ERRORCODES; : BOOL;

VAR_IN_OUT
VAR_IN_OUT stParams END_VAR
stParams : Parameter structure for the loop scheduler. This consists of the following elements: TYPE ST_CTRL_LOOP_SCHEDULER_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms; (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms; (* task cycle time [TIME] *) nNumberOfControlLoops pOutputVector_ADR nOutputVector_SIZEOF END_STRUCT : UINT; : POINTER TO BOOL := 0; : UINT := 0;

: ST_CTRL_LOOP_SCHEDULER_PARAMS;

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

17

END_TYPE tCtrlCycleTime : The cycle time with which the control loops managed by the loop scheduler are processed. This must be greater than or equal to the TaskCycleTime.

tTaskCycleTime : The cycle time with which the loop scheduler and the function blocks associated with the control loops are called. If the block is called in every cycle this corresponds to the task cycle time of the calling task. nNumberOfControlLoops pOutputVector_ADR nOutputVector_SIZEOF : The number of control loops being managed. :.Address of the output vector. :Size of the output vector in bytes.

Example:
PROGRAM PRG_LoopScheduler VAR arrOutputVector : ARRAY[1..5] OF BOOL; eMode stParams eErrorId bError : E_CTRL_MODE; : ST_CTRL_LOOP_SCHEDULER_PARAMS; : E_CTRL_ERRORCODES; : BOOL;

fbCTRL_LoopScheduler : FB_CTRL_LOOP_SCHEDULER; bInit : BOOL := TRUE; (* modes of the control loops *) eMode_CtrlLoop_1 : E_CTRL_MODE; eMode_CtrlLoop_2 : E_CTRL_MODE; eMode_CtrlLoop_3 : E_CTRL_MODE; eMode_CtrlLoop_4 : E_CTRL_MODE; eMode_CtrlLoop_5 : E_CTRL_MODE; END_VAR IF bInit THEN stParams.tCtrlCycleTime stParams.tTaskCycleTime

:= T#10ms; := T#2ms;

stParams.nNumberOfControlLoops := 5; bInit END_IF := FALSE;

(* set addresses *) stParams.nOutputVector_SIZEOF := SIZEOF(arrOutputVector); stParams.pOutputVector_ADR := ADR(arrOutputVector); (* call scheduler *) fbCTRL_LoopScheduler( eMode := eMode, stParams := stParams, eErrorId => eErrorId, bError => bError); IF arrOutputVector[ 1 ] THEN (* activate control loop 1 *) eMode_CtrlLoop_1 := eCTRL_MODE_ACTIVE; END_IF

TwinCAT PLC Library: Controller Toolbox

END_IF Development environment TwinCAT v2.BECHHOFF 18 IF arrOutputVector[ 2 ] THEN (* activate control loop 2 *) eMode_CtrlLoop_2 := eCTRL_MODE_ACTIVE. END_IF IF arrOutputVector[ 4 ] THEN (* activate control loop 4 *) eMode_CtrlLoop_4 := eCTRL_MODE_ACTIVE.lib TcControllerToolbox.9.lbx TwinCAT PLC Library: Controller Toolbox .lb6 TcControllerToolbox.8 TwinCAT v2.9. build 947 onwards TwinCAT v2. build 956 onwards Target system type PC (i386) BC BX PLC libraries to be linked TcControllerToolbox. END_IF IF arrOutputVector[ 3 ] THEN (* activate control loop 3 *) eMode_CtrlLoop_3 := eCTRL_MODE_ACTIVE. END_IF IF arrOutputVector[ 5 ] THEN (* activate control loop 5 *) eMode_CtrlLoop_5 := eCTRL_MODE_ACTIVE.

or whose value is the present at the output in Manual : A rising edge at this input sets the D-element to the value fManSyncValue. Transfer function (continuous): VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode END_VAR fIn fManSyncValue Mode. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR : FLOAT. : FLOAT. : Input that specifies the block's operating mode. : FLOAT. : E_CTRL_MODE. : Input to which the D-element can be synchronised. : E_CTRL_ERRORCODES. : BOOL. bSync eMode : Input of the D-element. : E_CTRL_STATE. Base FUNCTION_BLOCK FB_CTRL_D The function block provides a DT1 transfer element (a real D-element) in a functional diagram. : BOOL.BECHHOFF 19 3.2. TwinCAT PLC Library: Controller Toolbox .

9 from Build 956 TwinCAT PLC Library: Controller Toolbox . Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* task cycle time [TIME] *) tTv : TIME := T#0ms. (* derivative action time Tv *) tTd : TIME := T#0ms. : Supplies the error number when the bError output is set.9 from Build 947 TwinCAT v2. as soon as an error occurs. Development Environment TwinCAT v2. (* minimum output limit *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed.lb6 TcControllerToolbox. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. This consists of the following elements: TYPE ST_CTRL_D_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms.BECHHOFF 20 fOut eState eErrorId bError : Output of the D-element.lbx : ST_CTRL_D_PARAMS. If the block is called in every cycle this corresponds to the task cycle time of the calling task.8 TwinCAT v2. This must be greater than or equal to the TaskCycleTime. (* derivative damping time Td *) fOutMaxLimit : FLOAT := 1E38. : Lower limit to which the output of the D-element is restricted. : Becomes TRUE. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the D-element. tTaskCycleTime : Cycle time with which the function block is called. : State of the function block. (* maximum output limit *) fOutMinLimit : FLOAT := -1E38. tTv tTd fOutMaxLimit fOutMinLimit : Differentiation time constant : Damping time constant : Upper limit to which the output of the D-element is restricted.lib TcControllerToolbox.

: A rising edge at this input sets the hysteresis element to the value fManSyncValue. : E_CTRL_ERRORCODES. : Input through which the hysteresis element can be set to one of the two branches. : BOOL. : E_CTRL_MODE. : Input that specifies the block's operating mode. : FLOAT. Transfer function: VAR_INPUT VAR_INPUT fIn bManSyncValue bSync eMode END_VAR fIn bManSyncValue bSync eMode : Input of the hysteresis element. : E_CTRL_STATE. VAR_OUTPUT VAR_OUTPUT bOut eState eErrorId bError END_VAR : BOOL.BECHHOFF 21 FUNCTION_BLOCK FB_CTRL_HYSTERESIS The function block provides a hysteresis transfer element in a functional diagram. : BOOL. TwinCAT PLC Library: Controller Toolbox . : BOOL.

Development Environment TwinCAT v2.8 TwinCAT v2. : Supplies the error number when the bError output is set. : State of the function block. This consists of the following elements: TYPE ST_CTRL_HYSTERESIS_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. (* task cycle time [TIME] *) fHysteresisRange : FLOAT. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.9 ab Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.lb6 TcControllerToolbox.BECHHOFF 22 bOut eState eErrorId bError : Output of the hysteresis element.lib TcControllerToolbox. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the hysteresis element. : ST_CTRL_HYSTERESIS_PARAMS. : Becomes TRUE as soon as an error situation occurs. fHysteresisRange : Hysteresis range. see diagram above.lbx TwinCAT PLC Library: Controller Toolbox . If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* range of the hysteresis loop *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. tTaskCycleTime : Cycle time with which the function block is called.9 ab Build 947 TwinCAT v2.

: Input that specifies the block's operating mode. TwinCAT PLC Library: Controller Toolbox . : E_CTRL_MODE. : FLOAT. : BOOL. : Input to which the I-element can be synchronised. : FLOAT. bSync eMode bHold : Input of the I element. Transfer function: VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode bHold END_VAR fIn fManSyncValue Mode. : E_CTRL_ERRORCODES. independently of the input fIn. : E_CTRL_STATE.BECHHOFF 23 FUNCTION_BLOCK FB_CTRL_I The function block provides an I-transfer element in the functional diagram. or whose value is the present at the output in Manual : A rising edge at this input sets the integrator to the value fManSyncValue. : BOOL. : A TRUE at this input holds the integrator fixed at the current value. : BOOL. : BOOL. VAR_OUTPUT VAR_OUTPUT fOut bARWactive eState eErrorId bError : FLOAT.

If the block is called in every cycle this corresponds to the task cycle time of the calling task. : ST_CTRL_I_PARAMS. (* integral action time Ti *) fOutMaxLimit : FLOAT := 1E38. (* minimum output limit *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. This must be greater than or equal to the TaskCycleTime. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the I element. : Lower limit at which integration is halted (ARW measure). Reaching this limit is indicated by a TRUE at the bARWActive output.lib TcControllerToolbox. : Supplies the error number when the bError output is set.lb6 TcControllerToolbox. tTaskCycleTime : Cycle time with which the function block is called. : Becomes TRUE. (* maximum output limit *) fOutMinLimit : FLOAT := -1E38. : State of the function block. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.lbx Development Environment TwinCAT v2. (* controller cycle time *) tTaskCycleTime : TIME := T#0ms. Reaching this limit is indicated by a TRUE at the bARWActive output. as soon as an error occurs. : Upper limit at which integration is halted (ARW measure). tTi fOutMaxLimit fOutMinLimit : Integration time of the I element.8 TwinCAT v2. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. (* task cycle time *) tTi : TIME := T#0ms.BECHHOFF 24 END_VAR fOut bARWactive eState eErrorId bError : Output of the I element. This consists of the following elements: TYPE ST_CTRL_I_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : A TRUE at this output indicates that the integrator is being restricted.9 from Build 947 TwinCAT v2.9 from Build 956 TwinCAT PLC Library: Controller Toolbox .

bError : Becomes TRUE. This consists of the following elements: :ST_CTRL_P_PARAMS.BECHHOFF 25 FUNCTION_BLOCK FB_CTRL_P The function block provides an P-transfer element in the functional diagram. :E_CTRL_ERRORCODES. :FLOAT. : State of the function block. :FLOAT. :E_CTRL_MODE. TwinCAT PLC Library: Controller Toolbox . VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR fOut eState : Output of the P element. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the P element. :E_CTRL_STATE. :BOOL. as soon as an error occurs. eErrorId : Supplies the error number when the bError output is set. Transfer function: VAR_INPUT VAR_INPUT fIn eMode END_VAR fIn eMode : Input of the P element. : Input that specifies the block's operating mode.

BECHHOFF

26

TYPE ST_CTRL_P_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms; (* controller cycle time *) tTaskCycleTime : TIME := T#0ms; (* task cycle time *) fKp : FLOAT := 0.0; END_STRUCT END_TYPE tCtrlCycleTime (* proportional gain Kp *)

: Cycle time with which the control loop is processed. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.

tTaskCycleTime : Cycle time with which the function block is called. If the block is called in every cycle this corresponds to the task cycle time of the calling task. fKp : Proportional amplification of the P element. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.lb6 TcControllerToolbox.lbx

Development Environment TwinCAT v2.8 TwinCAT v2.9 from Build 947 TwinCAT v2.9 from Build 956

FUNCTION_BLOCK FB_CTRL_TRANSFERFUNCTION_1

This block calculates a discrete transfer function with the first standard form illustrated below. The transfer function here can be of any order, n. The coefficients for the following transfer functions are stored in the parameter arrays:

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

27

Description of the transfer behaviour:
The transfer function above is calculated with the first standard form, after some transformations, in every sampling step.

The programmer must create the following arrays in the PLC if this function block is to be used: ar_fNumeratorArray : ARRAY[0..nOrderOfTheTransferfunction] OF FLOAT; ar_DenominatorArray : ARRAY[0..nOrderOfTheTransferfunction] OF FLOAT; ar_stTransferfunction1Data : ARRAY[0..nOrderOfTheTransferfunction] OF ST_CTRL_TRANSFERFUNCTION_1_DATA; The coefficients b0 to bn are stored in the array ar_fNumeratorArray. This must be organised as follows: ar_fNumeratorArray[ 0 ] ar_fNumeratorArray[ 1 ] ... ar_fNumeratorArray[ n-1 ] ar_fNumeratorArray[ n ] := b0; := b1; := bn-1; := bn;

The coefficients b0 to bn are stored in the array ar_DenominatorArray. This must be organised as follows: ar_DenominatorArray [ 0 ] := a0; ar_DenominatorArray [ 1 ] := a1; ... ar_DenominatorArray [ n-1 ] := an-1; ar_DenomiantorArray [ n ] := an; The internal data required by the block is stored in the ar_stTransferfunction1Data array. This data must never be modified from within the PLC program. This procedure is also illustrated in the example program listed below.

VAR_INPUT
VAR_INPUT fIn fManValue eMode END_VAR
fIn fManValue : Input to the transfer function. : Input whose value is present at the output in manual mode.

: FLOAT; : FLOAT; : E_CTRL_MODE;

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

28

eMode

: Input that specifies the block's operating mode.

VAR_OUTPUT
VAR_OUTPUT fOut eState bError eErrorId END_VAR
fOut eState eErrorId bError : Output from the transfer function. : State of the function block. : Supplies the error number when the bError output is set. : Becomes TRUE, as soon as an error occurs.

: FLOAT; : E_CTRL_STATE; : BOOL; : E_CTRL_ERRORCODES;

VAR_IN_OUT
VAR_IN_OUT stParams END_VAR
stParams : Parameter structure of the function block. This consists of the following elements: TYPE ST_CTRL_TRANSFERFUNCTION_1_PARAMS: STRUCT tTaskCycleTime : TIME; (* task cycle time in seconds *) tTaskCtrlTime : TIME:= T#0ms; (* controller cycle time *) nOrderOfTheTransferfunction : USINT; pNumeratorArray_ADR nNumeratorArray_SIZEOF : POINTER TO FLOAT := 0; : UINT;

: ST_CTRL_TRANSFERFUNCTION_1_PARAMS;

pDenominatorArray_ADR : POINTER TO FLOAT := 0; nDenomiantorArray_SIZEOF : UINT; pTransferfunction1Data_ADR : POINTER TO ST_CTRL_TRANSFERFUNCTION_1_DATA; nTransferfunction1Data_SIZEOF : UINT; END_TYPE tTaskCycleTime : Cycle time with which the function block is called. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tPWMPeriod nOrderOfTheTransferfunction pNumeratorArray_ADR nNumeratorArray_SIZEOF pDenominatorArray_ADR nDenominatorArray_SIZEOF : Period of the PWM signal. : Order of the transfer function [0... ] : Address of the array containing the numerator coefficients. : Size of the array containing the numerator coefficients, in bytes. : Address of the array containing the denominator coefficients. : Size of the array containing the denominator coefficients, in bytes.

TwinCAT PLC Library: Controller Toolbox

: FLOAT := 0.nOrderOfTheTransferfunction] OF FLOAT.99850062471888. fbTansferfunction : FB_CTRL_TRANSFERFUNCTION_1. : FLOAT. : ST_CTRL_TRANSFERFUNCTION_1_PARAMS.BECHHOFF 29 pTransferfunction1Data_ADR : Address of the data array.tCtrlCycleTime := T#2ms. stParams.a_1. : BOOL... a_0. nTransferfunction1Data_SIZEOF : Size of the data array in bytes. ar_fNumeratorArray[1] := 2. ar_fNumeratorArray[2] := 1.nOrderOfTheTransferfunction] OF FLOAT. stParams. END_VAR IF bInit THEN (* set values in the local arrays *) ar_fNumeratorArray[0] := 1.a_2 : FLOAT. ar_DenominatorArray[0] := 0. eMode stParams eErrorId bError : E_CTRL_MODE. TYPE ST_CTRL_TRANSFERFUNCTION_1_DATA: STRUCT Internal structure. b_2 : FLOAT. ar_DenominatorArray[2] := 1. b_0. ar_DenominatorArray[1] := -1.0. ar_DenominatorArray : ARRAY[0. bInit := FALSE. b_1. (* set values in the parameter struct *) stParams.nOrderOfTheTransferfunction := nOrderOfTheTransferfunction. END_IF TwinCAT PLC Library: Controller Toolbox . (* set the mode *) eMode := eCTRL_MODE_ACTIVE. : E_CTRL_ERRORCODES. bInit fIn fOut : BOOL := TRUE.998501124344101.24906304658218E-007.. END_STRUCT END_TYPE Example: PROGRAM PRG_TRANSFERFUNCTION_1_TEST VAR CONSTANT nOrderOfTheTransferfunction : USINT := 2.tTaskCycleTime := T#2ms. ar_stTransferfunction1Data : ARRAY[0. This must not be written to.nOrderOfTheTransferfunction] OF ST_CTRL_TRANSFERFUNCTION_1_DATA.49812609316437E-007.24906304658218E-007. END_VAR VAR ar_fNumeratorArray : ARRAY[0.

eErrorId => eErrorId. TwinCAT PLC Library: Controller Toolbox . (* call fnction block *) fbTansferfunction ( fIn := fIn. n.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lb6 TcControllerToolbox. := SIZEOF( ar_DenominatorArray ). after some transformations. stParams := stParams. := ADR( ar_DenominatorArray ). stParams.BECHHOFF 30 (* set the addresses *) stParams. eMode := eMode. fOut => fOut.pDenominatorArray_ADR stParams. stParams.nNumeratorArray_SIZEOF stParams.9 from Build 947 TwinCAT v2. The coefficients for the following transfer functions are stored in the parameter arrays: Description of the transfer behaviour: The transfer function above is calculated with the second standard form.lib TcControllerToolbox.nDenominatorArray_SIZEOF := ADR( ar_fNumeratorArray).nTransferfunction1Data_SIZEOF := SIZEOF( ar_stTransferfunction2Data ). bError => bError ). in every sampling step. := SIZEOF( ar_fNumeratorArray).pNumeratorArray_ADR stParams.pTransferfunction1Data_ADR := ADR( ar_stTransferfunction2Data ). Development Environment TwinCAT v2.lbx FUNCTION_BLOCK FB_CTRL_TRANSFERFUNCTION_2 This block calculates a discrete transfer function with the second standard form illustrated below. The transfer function here can be of any order.8 TwinCAT v2.

The internal data required by the block is stored in the ar_stTransferfunction2Data array. This must be organised as follows: ar_DenominatorArray [ 0 ] := a0. ar_DenominatorArray [ n-1 ] := an-1. : FLOAT. ar_stTransferfunction2Data : ARRAY[0.nOrderOfTheTransferfunction] OF ST_CTRL_TRANSFERFUNCTION_2_DATA...BECHHOFF 31 The programmer must create the following arrays in the PLC if this function block is to be used: ar_fNumeratorArray : ARRAY[0. The coefficients b0 to bn are stored in the array ar_DenominatorArray. The coefficients b0 to bn are stored in the array ar_fNumeratorArray. .. := bn-1. : FLOAT. := b1.... ar_fNumeratorArray[ n-1 ] ar_fNumeratorArray[ n ] := b0. This must be organised as follows: ar_fNumeratorArray[ 0 ] ar_fNumeratorArray[ 1 ] . This data must never be modified from within the PLC program. ar_DenominatorArray : ARRAY[0.. : Input whose value is present at the output in manual mode. This procedure is also illustrated in the example program listed below. VAR_INPUT VAR_INPUT fIn fManValue eMode END_VAR fIn fManValue eMode : Input to the transfer function. ar_DenominatorArray [ 1 ] := a1.nOrderOfTheTransferfunction] OF FLOAT. := bn.nOrderOfTheTransferfunction] OF FLOAT. : Input that specifies the block's operating mode. TwinCAT PLC Library: Controller Toolbox . : E_CTRL_MODE. ar_DenomiantorArray [ n ] := an.

VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. : ST_CTRL_TRANSFERFUNCTION_2_PARAMS. : Becomes TRUE. in bytes. : Supplies the error number when the bError output is set. TwinCAT PLC Library: Controller Toolbox . : BOOL.. (* controller cycle *) nOrderOfTheTransferfunction : USINT. : POINTER TO FLOAT := 0. : Address of the array containing the denominator coefficients.BECHHOFF 32 VAR_OUTPUT VAR_OUTPUT fOut eState bError eErrorId END_VAR fOut eState eErrorId bError : Output from the transfer function. : Size of the array containing the numerator coefficients. : Size of the array containing the denominator coefficients. ] : Address of the array containing the numerator coefficients. in bytes. : State of the function block. : FLOAT. nTransferfunction2Data_SIZEOF : UINT. as soon as an error occurs. : E_CTRL_ERRORCODES. pNumeratorArray_ADR nNumeratorArray_SIZEOF pDenominatorArray_ADR nDenomiantorArray_SIZEOF : POINTER TO FLOAT := 0.. tPWMPeriod nOrderOfTheTransferfunction pNumeratorArray_ADR nNumeratorArray_SIZEOF pDenominatorArray_ADR nDenominatorArray_SIZEOF : Period of the PWM signal. : UINT. : Order of the transfer function [0. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : UINT. END_TYPE tTaskCycleTime : Cycle time with which the function block is called. : E_CTRL_STATE. This consists of the following elements: TYPE ST_CTRL_TRANSFERFUNCTION_2_PARAMS: STRUCT tTaskCycleTime : TIME. pTransferfunction2Data_ADR : POINTER TO ST_CTRL_TRANSFERFUNCTION_2_DATA. (* task cycle time in seconds *) tCrtlCycleTime : TIME:= T#0ms.

BECHHOFF

33

pTransferfunction2Data_ADR

: Address of the data array.

nTransferfunction2Data_SIZEOF : Size of the data array in bytes.

TYPE ST_CTRL_TRANSFERFUNCTION_2_DATA: STRUCT Internal structure. This must not be written to. END_STRUCT END_TYPE

Example:
PROGRAM PRG_TRANSFERFUNCTION_2_TEST VAR CONSTANT nOrderOfTheTransferfunction : USINT := 2; END_VAR VAR ar_fNumeratorArray : ARRAY[0..nOrderOfTheTransferfunction] OF FLOAT; ar_DenominatorArray : ARRAY[0..nOrderOfTheTransferfunction] OF FLOAT; ar_stTransferfunction2Data : ARRAY[0..nOrderOfTheTransferfunction] OF ST_CTRL_TRANSFERFUNCTION_2_DATA; eMode stParams eErrorId bError : E_CTRL_MODE; : ST_CTRL_TRANSFERFUNCTION_2_PARAMS; : E_CTRL_ERRORCODES; : BOOL;

fbTansferfunction : FB_CTRL_TRANSFERFUNCTION_2; bInit fIn fOut : BOOL := TRUE; : FLOAT := 0; : FLOAT;

b_0, b_1, b_2 : FLOAT; a_0,a_1,a_2 : FLOAT; END_VAR IF bInit THEN (* set values in the local arrays *) ar_fNumeratorArray[0] := 1.24906304658218E-007; ar_fNumeratorArray[1] := 2.49812609316437E-007; ar_fNumeratorArray[2] := 1.24906304658218E-007; ar_DenominatorArray[0] := 0.998501124344101; ar_DenominatorArray[1] := -1.99850062471888; ar_DenominatorArray[2] := 1.0; (* set values in the parameter struct *) stParams.tTaskCycleTime := T#2ms; stParams.tCtrlCycleTime := T#2ms; stParams.nOrderOfTheTransferfunction := nOrderOfTheTransferfunction; (* set the mode *) eMode := eCTRL_MODE_ACTIVE; bInit := FALSE; END_IF

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

34

(* set the addresses *) stParams.pNumeratorArray_ADR := ADR( ar_fNumeratorArray); stParams.nNumeratorArray_SIZEOF := SIZEOF( ar_fNumeratorArray); stParams.pDenominatorArray_ADR := ADR( ar_DenominatorArray ); stParams.nDenominatorArray_SIZEOF := SIZEOF( ar_DenominatorArray ); stParams.pTransferfunction2Data_ADR := ADR( ar_stTransferfunction2Data ); stParams.nTransferfunction2Data_SIZEOF := SIZEOF( ar_stTransferfunction2Data ); (* call the function block *) fbTansferfunction ( fIn := fIn, eMode := eMode, stParams := stParams, fOut => fOut, eErrorId => eErrorId, bError => bError ); Development Environment TwinCAT v2.8 TwinCAT v2.9 from Build 947 TwinCAT v2.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.lb6 TcControllerToolbox.lbx

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

35

3.3. Controller
FUNCTION_BLOCK FB_CTRL_2POINT

The function block provides a 2-point transfer element in the functional diagram.

Behaviour of the output:

VAR_INPUT
VAR_INPUT fActualValue : FLOAT;

fSetpointValue : FLOAT; bManSyncValue bSync eMode END_VAR
fActualValue fSetpointValue bManSyncValue bSync eMode : Actual value of the controlled variable. : Set value of the controlled variable. : Input through which the 2-point element can be set to one of the two branches. : A rising edge at this input sets the 2-point element to the value bManSyncValue. : Input that specifies the block's operating mode.

: BOOL; : BOOL; : E_CTRL_MODE;

TwinCAT PLC Library: Controller Toolbox

: Becomes TRUE. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.9 from Build 947 TwinCAT v2. as soon as an error occurs.BECHHOFF 36 VAR_OUTPUT VAR_OUTPUT bOut eState eErrorId bError END_VAR bOut eState eErrorId bError : Output of the 2-point element. tCtrlCycleTime : Cycle time with which the control loop is processed. If the block is called in every cycle this corresponds to the task cycle time of the calling task.lib TcControllerToolbox. (* task cycle time [TIME] *) fHysteresisRange : FLOAT. Development Environment TwinCAT v2. fHysteresisRange: Hysteresis range. END_STRUCT END_TYPE (* range of the hysteresis loop *) : ST_CTRL_2POINT_PARAMS. : BOOL.8 TwinCAT v2.lb6 TcControllerToolbox. This consists of the following elements: TYPE ST_CTRL_2POINT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the 2-point element. see diagram above. tTaskCycleTime : Cycle time with which the function block is called.lbx TwinCAT PLC Library: Controller Toolbox . : State of the function block. : Supplies the error number when the bError output is set. : BOOL. : E_CTRL_STATE. : E_CTRL_ERRORCODES. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.

Behaviour of the output: TwinCAT PLC Library: Controller Toolbox . It is particularly suitable for single-area controllers in which high inlet temperatures are present and which make use of a thermal actuator.BECHHOFF 37 FUNCTION_BLOCK FB_CTRL_2POINT_PWM_ADAPTIVE The function block provides an adaptive two-position controller.

the controller uses a PWM block that is used to drive the thermal actuator.. and is switched off when the system deviation is less than zero. (* debug only *) bError: Becomes TRUE. fManSyncValue : Input to which the controller's mark-to-space ratio can be set. eMode : Input that specifies the block's operating mode. If fE > fOkRange. fOkRange]. TwinCAT PLC Library: Controller Toolbox . time tWaitTime must elapse before the mark-to-space ratio can be changed again. fSetpointValue : FLOAT. : BOOL. eState eErrorId : State of the function block. : E_CTRL_ERRORCODES. fMaxLimit].BECHHOFF 38 Description of the function: Internally. The mark-to-space ratio is only modified over the range [fMinLimit . is greater than zero. : BOOL. VAR_INPUT VAR_INPUT fActualValue : FLOAT. The period of the PWM signal is specified by the parameter tPWMPeriod. The PWM output is switched on as soon as the system deviation. fE. : Set value of the controlled variable. or with which the output can be set in Manual Mode. If fE falls below -fOkRange. the mark-to-space ratio is reduced by fStepSize.. fManSyncValue bSync eMode END_VAR fActualValue fSetpointValue : Actual value of the controlled variable.. : E_CTRL_STATE. After such an increase. : BOOL. bSync : A rising edge at this input will set the mark-to-space ratio of the internal PWM block to the value fManSyncValue. The output is set in Manual Mode if fManSyncValue > 0.0. : FLOAT. fPWMDutyCycle : Current mark-to-space ratio of the internal PWM block. the mark-to-space ratio is increased by fStepSize. : FLOAT. as soon as an error occurs. VAR_OUTPUT VAR_OUTPUT bOut fPWMDutyCycle eState eErrorId bError END_VAR bOut : Output of the controller. : Supplies the error number when the bError output is set. The mark-to-space ratio of the PWM block is adaptively adjusted to the behaviour of the controlled system. : E_CTRL_MODE. The mark-to-space ratio is not changed as long as the system deviation remains within the range [ -fOkRange . which is the set value minus the actual value..

. fOkRange :The range of fE over which the mark-to-space ratio will not be modified. 100%] *) tWaitTime : TIME END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. fForceRange fStepSize fMaxLimit fMinLimit tWaiTimet :If fE exceeds this range. : Minimum mark-to-space ratio in percent [0% . Development Environment TwinCAT v2.... This must be greater than or equal to the TaskCycleTime. 100%] : Maximum mark-to-space ratio in percent [0% . The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. :Value by which the mark-to-space ratio is varied each time it is adapted. the output is permanently set to TRUE. 100%].. (* task cycle time [TIME] *) tPWMPeriod : TIME fOkRange : FLOAT fForceRange : FLOAT fStepSize : FLOAT fMinLimit : FLOAT (* [0% .9 from Build 947 TwinCAT v2. (* controller cycle [TIME] *) tTaskCycleTime : TIME := T#0ms..lib TcControllerToolbox.8 TwinCAT v2.. : ST_CTRL_2POINT_PWM_ADAPTIVE_PARAMS. tPMWPeriod :Period of the PWM signal.. If the block is called in every cycle this corresponds to the task cycle time of the calling task..BECHHOFF 39 VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the 2-point element.lb6 TcControllerToolbox. [0% . : Waiting time between individual modifications of the mark-to-space ratio. 100%]. This consists of the following elements: TYPE ST_CTRL_2POINT_PWM_ADAPTIVE_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms.. tTaskCycleTime : Cycle time with which the function block is called.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. 100%] *) fMaxLimit : FLOAT (* [0% .lbx TwinCAT PLC Library: Controller Toolbox .

: Set value of the controlled variable. : E_CTRL_MODE. : BOOL. bNegOut = FALSE TwinCAT PLC Library: Controller Toolbox . nManSyncValue >= 1 → bPosOut = TRUE. bNegOut = FALSE nManSyncValue <= -1 → bPosOut = FALSE. : Input through which the 3-point element can be set to one of the three branches. → bPosOut = FALSE.BECHHOFF 40 FUNCTION_BLOCK FB_CTRL_3POINT The function block provides a 3-point transfer element in the functional diagram. Behaviour of the output: VAR_INPUT VAR_INPUT fActualValue : FLOAT. nManSyncValue bSync eMode END_VAR fActualValue fSetpointValue nManSyncValue : Actual value of the controlled variable. fSetpointValue : FLOAT. bNegOut = TRUE otherwise : INT.

fPosOutOn FALSE ). as soon as an error occurs.BECHHOFF 41 bSync eMode : A rising edge at this input sets the 3-point element to the value fManSyncValue. : FLOAT. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : This output from the 3-point element is TRUE if the lower branch of the characteristic curve is active. : BOOL. tCtrlCycleTime : Cycle time with which the control loop is processed. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : Input that specifies the block's operating mode. : Supplies the error number when the bError output is set. VAR_OUTPUT VAR_OUTPUT bPosOut bNegOut eState eErrorId bError END_VAR bPosOut bNegOut eState eErrorId bError : This output from the 3-point element is TRUE if the upper branch of the characteristic curve is active. : BOOL. : E_CTRL_ERRORCODES. (* task cycle time [TIME] *) fPosOutOn fPosOutOff fNegOutOn fNegOutOff END_STRUCT END_TYPE : FLOAT. (* switch to bPosOut on *) (* switch to bPosOut off *) (* switch to bNegOut on *) (* switch to bNegOut off *) : ST_CTRL_3POINT_PARAMS. : System deviation that will result in bPosOut = FALSE being switched to bPosOut = TRUE ( bNegOut = : System deviation that will result in bPosOut = TRUE being switched to bPosOut = FALSE ( bNegOut = TwinCAT PLC Library: Controller Toolbox . tTaskCycleTime : Cycle time with which the function block is called. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : State of the function block. : Becomes TRUE. This consists of the following elements: TYPE ST_CTRL_3POINT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : BOOL. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the 3-point element. fPosOutOff FALSE ). : FLOAT. : E_CTRL_STATE. : FLOAT.

fNegOutOff FALSE ). : System deviation that will result in bNegOut = FALSE being switched to bNegOut = TRUE (bPosOut = : System deviation that will result in bNegOut = TRUE being switched to bNegOut = FALSE (bPosOut = Development Environment TwinCAT v2.lib TcControllerToolbox.9 from Build 947 TwinCAT v2.lbx TwinCAT PLC Library: Controller Toolbox .9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lb6 TcControllerToolbox.8 TwinCAT v2.BECHHOFF 42 fNegOutOn FALSE ).

TwinCAT PLC Library: Controller Toolbox .fActualValue.BECHHOFF 43 FUNCTION_BLOCK FB_CTRL_3POINT_EXT The function block provides an extended 3-point element in the functional diagram. Behaviour of the output: fIn := fSetpointValue .

BECHHOFF 44 VAR_INPUT VAR_INPUT fActualValue : FLOAT. as soon as an error occurs. eState : E_CTRL_STATE. : BOOL. bError : BOOL. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the extended 3-point element. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. eErrorId : E_CTRL_ERRORCODES. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. | fManSyncValue | < 1 → fOut = 0. TwinCAT PLC Library: Controller Toolbox . : Becomes TRUE. END_VAR fOut eState eErrorId bError : Output of the extended 3-point element. : Input which defines the operating modus of the function block. (* task cycle time [TIME] *) : ST_CTRL_3POINT_EXT_PARAMS. fSetpointValue : FLOAT. This consists of the following elements: TYPE ST_CTRL_3POINT_EXT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms.0 | fManSyncValue | >= 1 → fOut = fE * fGain + fOffset bSync eMode : A rising edge at this input sets the 3-point element to the value fManSyncValue. : FLOAT. : Input through which the extended 3-point element can be set to one of the output branches. : State of the function block. : E_CTRL_MODE. : Set value of the controlled variable. fManSyncValue bSync eMode END_VAR fActualValue fSetpointValue fManSyncValue : Actual value of the controlled variable. : Supplies the error number when the bError output is set.

the output is switched off (set to zero). : Offset.lbx Development Environment TwinCAT v2.BECHHOFF 45 fOutOff fOutOn fGain fOffset END_STRUCT END_TYPE : FLOAT.9 from Build 956 TwinCAT PLC Library: Controller Toolbox . : Amplification factor.lb6 TcControllerToolbox. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.lib TcControllerToolbox. If the block is called in every cycle this corresponds to the task cycle time of the calling task. This must be greater than or equal to the TaskCycleTime.9 from Build 947 TwinCAT v2. : FLOAT. (* x-parameter for threshold OFF *) (* x-parameter for threshold ON *) (* y-parameter gain *) (* y-parameter offset *) tCtrlCycleTime : Cycle time with which the control loop is processed.8 TwinCAT v2. : If the system deviation exceeds this value. : FLOAT. fOutOff fOutOn fGain fOffset : If the system deviation falls below this value. tTaskCycleTime : Cycle time with which the function block is called. the output is switched on. : FLOAT.

because it is not evaluated. can be freely selected. TwinCAT PLC Library: Controller Toolbox . Behaviour of the output: Data array for the example: The value of the array with index (1. that is the left-hand value in the first row.BECHHOFF 46 FUNCTION_BLOCK FB_CTRL_nPOINT The function block provides an n-point transfer element in the functional diagram.1).

: E_CTRL_ERRORCODES. : ST_CTRL_nPOINT_PARAMS. (* task cycle time [TIME] *) pDataTable_ADR : POINTER TO nPOINT_CTRL_TABLE_ELEMENT := 0. : Supplies the error number when the bError output is set. nDataTable_SIZEOF : UINT := 0. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : BOOL. nDataTable_NumberOfRows : UINT := 0. VAR_OUTPUT VAR_OUTPUT bOut eState eErrorId bError END_VAR fOut eState eErrorId bError : Output of the n-point element. : State of the function block. fManValue eMode END_VAR fActualValue fSetpointValue fManValue eMode : Actual value of the controlled variable. : BOOL. : E_CTRL_STATE. as soon as an error occurs. : E_CTRL_MODE. fSetpointValue : FLOAT.BECHHOFF 47 VAR_INPUT VAR_INPUT fActualValue : FLOAT. : Input that specifies the block's operating mode. : Input whose value is output in manual mode. : Set value of the controlled variable. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the n-point element. This consists of the following elements: TYPE ST_CTRL_nPOINT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. TwinCAT PLC Library: Controller Toolbox . : Becomes TRUE. : nPOINT_CTRL_TABLE_ELEMENT.

lbx FUNCTION_BLOCK FB_CTRL_PARAMETER_SWITCH This block can be used to switch the parameter record used by FB_CTRL_PID_SPLITRANGE. The hysteresis range functions as described for Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lb6 TcControllerToolbox. fHysteresisRange FB_CTRL_2POINT. Behaviour of the output: TwinCAT PLC Library: Controller Toolbox . Development Environment TwinCAT v2. see diagram above.9 from Build 947 TwinCAT v2. nDataTable_NumberOfRows :Number of lines in the data table. pDataTable_ADR nDataTable_SIZEOF :Address of the data table.lib TcControllerToolbox. If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* range of the hysteresis loop *) tCtrlCycleTime : Cycle time with which the control loop is processed. tTaskCycleTime : Cycle time with which the function block is called. This must be greater than or equal to the TaskCycleTime.BECHHOFF 48 fHysteresisRange END_STRUCT END_TYPE : FLOAT. :Size of the data table in bytes. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.9 from Build 956 :Hysteresis range.8 TwinCAT v2.

: Input that specifies the block's operating mode. so that the parameter region can be changed. should be used as the input value for the illustrated characteristic hysteresis curve. the limits are set as follows: In the Cooling mode. to deactivate heating operation in summer and to deactivate cooling in winter. This should be the same as the controller's output value. it might have to be 2°C too hot before switching into cooling operation. At least this time must elapse when switch-over is requested to allow for the parameter region to be changed. the parameter range eCTRL_PARAMETER_RECORD_HEATING = heating is selected. In summer. The time tMinWaitTime is specified as an input parameter. The intention of this is to prevent the operating mode being changed immediately simply because the controller overshoots slightly. The bDisableRange1 and bDisableRange2 inputs makes it possible to prevent switching into one of the two ranges. It is therefore possible. Maximum and minimum limits are output in addition to providing the output of the parameter region. : FLOAT. If the FB_CTRL_PARAMETER_SWITCH is in the Heating operating mode.BECHHOFF 49 Description of the function block: This block is used to switch over the parameter record used by FB_CTRL_PID_SPLITRANGE. the limits are set as follows: VAR_INPUT VAR_INPUT fManipulatedVariable nManSyncValue bSync eMode END_VAR fManipulatedVariable : The input value of FB_Parameter_Switch. A request for changeover created by the hysteresis element must be present for at least the specified waiting time. : BOOL. : A rising edge at this input sets the function block to the value nManSyncValue. : E_CTRL_MODE. It would also be possible to make the change in the operating mode depend on the current system deviation. This can also be achieved by connecting the inputs appropriately. TwinCAT PLC Library: Controller Toolbox . and these can be copied into the PID controller's parameter record. nManSyncValue bSync eMode : The input with which the function block can be set to one of the to parameter ranges. for instance. For heating operation. The request for a changeover itself is provided by a 2-point element (see diagram). and to set the limits for the controller. The controller's output magnitude. in other words the control value. This block is particularly intended to switch the parameter records of controllers that can use two actuators to heat and to cool. while for cooling operation the parameter region is eCTRL_PARAMETER_RECORD_COOLING = cooling. for instance. (* fOut from the FB_CTRL_PID_SPLITRANGE *) : eCTRL_PARAMETER_RECORD_HEATING. and for the controller limits set in such a way that it is possible to switch from heating operation to cooling operation. The controllers's parameter records must be specified in accordance with this arrangement.

: E_CTRL_PARAMETER_RECORD. This must be greater than or equal to the TaskCycleTime. : Becomes TRUE. (* task cycle time [TIME] *) tCtrlCycleTime : TIME. as soon as an error occurs. tTaskCycleTime : Cycle time with which the function block is called. (* max limit for heating *) : FLOAT.BECHHOFF 50 VAR_OUTPUT VAR_OUTPUT eParameterRecord fOutMaxLimit fOutMinLimit eState eErrorId bError END_VAR eParameterRecord : The output of the function block. it is passed on to the controller. : E_CTRL_STATE. : The minimum limit. : FLOAT. identifying the parameter region. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. tCtrlCycleTime : Cycle time with which the control loop is processed. : The maximum limit. If the block is called in every cycle this corresponds to the task cycle time of the calling task. fThreshold fOutMaxLimit fOutMinLimit : Switching threshold. (This should be copied into the controller's parameter structure.) eState eErrorId bError : State of the function block. : BOOL. it is passed on to the controller. (* controller cycle time [TIME] *) fThreshold fOutMaxLimit fOutMinLimit tMinWaitTime END_STRUCT END_TYPE : FLOAT. This consists of the following elements: TYPE ST_CTRL_2POINT_PARAMS : STRUCT tTaskCycleTime : TIME. TwinCAT PLC Library: Controller Toolbox . (This should be copied into the controller's parameter structure. see illustration above. (* min limit for heating *) : TIME. : FLOAT. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. fOutMaxLimit : The maximum output value of which the controller is limited. : FLOAT. : Supplies the error number when the bError output is set. : ST_CTRL_PARAMETER_SWITCH_PARAMS.) fOutMinLimit : The minimum value of the output of which the controller is limited. : E_CTRL_ERRORCODES.

9 from Build 947 TwinCAT v2.lb6 TcControllerToolbox. Behaviour of the output: Step response: TwinCAT PLC Library: Controller Toolbox .BECHHOFF 51 tMinWaitTime : Waiting time (see description above) Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.8 TwinCAT v2.lbx Development Environment TwinCAT v2.9 from Build 956 FUNCTION_BLOCK FB_CTRL_PI The function block provides a PI transfer element in the functional diagram.

bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 52 ARW: VAR_INPUT VAR_INPUT fActualValue : FLOAT. : E_CTRL_MODE. : A rising edge at this input sets the PI element to the value fManSyncValue. : A TRUE at this output indicates that the PI element is being restricted. : BOOL. fManSyncValue bSync eMode bHold END_VAR fActualValue fSetpointValue fManSyncValue bSync eMode : Actual value of the controlled variable. independently of the system deviation. : FLOAT. : BOOL. : BOOL. : FLOAT. : Input with which the PI element can be set. : E_CTRL_ERRORCODES. VAR_OUTPUT VAR_OUTPUT fOut bARWactive eState eErrorId bError END_VAR fOut bARWactive : Output of the PI element. : Input that specifies the block's operating mode. : E_CTRL_STATE. : BOOL. : Set value of the controlled variable. fSetpointValue : FLOAT.

tTn fKp : Integral action time : Controller amplification / transfer coefficient : ST_CTRL_PI_PARAMS. the integration of the I-component is halted if the complete controller output reaches the upper or lower limit. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.BECHHOFF 53 eState eErrorId bError : State of the function block. *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. If the block is called in every cycle this corresponds to the task cycle time of the calling task.lb6 TcControllerToolbox.9 from Build 947 TwinCAT v2. Reaching this limit is indicated by a TRUE at the bARWActive output. (* integral action time Tn *) fKp : FLOAT := 0.lib TcControllerToolbox. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PI element. the integration is halted if the I-component (the output of the integrator) reaches some limit. (* minimum output limit *) bARWOnIPartOnly : BOOL := FALSE.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. (* FALSE: Hold the I-part if the entire control output reaches a limit. If it is TRUE. Reaching this limit is indicated by a TRUE at the bARWActive output. fOutMaxLimit : Upper limit at which integration is halted and to which the output is limited (ARW measure). (* task cycle time [TIME] *) tTn : TIME := T#0ms. (Cf.lbx TwinCAT PLC Library: Controller Toolbox . as soon as an error occurs. (* proportional gain *) fOutMaxLimit : FLOAT := 1E38. functional diagram. fOutMinLimit : Lower limit at which integration is halted and to which the output is limited (ARW measure). This must be greater than or equal to the TaskCycleTime. (* maximum output limit *) fOutMinLimit : FLOAT := -1E38. : Becomes TRUE.8 TwinCAT v2. *) (* TRUE: Hold the I-part if only the I-part reaches a limit. This consists of the following elements: TYPE ST_CTRL_PI_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms.) Development Environment TwinCAT v2. : Supplies the error number when the bError output is set. bARWOnIPartOnly: If this parameter is FALSE (the standard setting). tTaskCycleTime : Cycle time with which the function block is called.

BECHHOFF 54 FUNCTION_BLOCK FB_CTRL_PI_PID The function block provides a cascaded PI-PID controller in the functional diagram. this block uses the FB_CTRL_PI. Transfer function of the PI element: Transfer function of the PID element: Functional diagram for the cascaded transfer element: TwinCAT PLC Library: Controller Toolbox . FB_CTRL_LIMITER and FB_CTRL_PID transfer elements. Internally.

: FLOAT. fManSyncValueInnerLoop manual mode or the sync request *) bSyncInnerLoop the fManSyncValue *) eModeInnerLoop *) bHoldInnerLoop : BOOL. (* input value for the manual mode or (* rising edge set the output to the (* sets the mode of the function block (* hold the internal integrator *) : Set value of the controlled variable. (* input value for the (* rising edge set the output to : E_CTRL_MODE. fActualValueInnerLoop control loop. : A TRUE at this input holds the internal state of the PID element (the inner control loop) TwinCAT PLC Library: Controller Toolbox .BECHHOFF 55 VAR_INPUT VAR_INPUT fSetpointValue fActualValueOuterLoop to the PI controller *) : FLOAT. fManSyncValueInnerLoop control loop). to whose value it is possible to set the internal state of the PID element (the inner : A rising edge at this input sets the PID element (the inner control loop) to the value : Input that specifies the operating mode of the PID element (the inner control loop). bSyncInnerLoop fManSyncValueInnerLoop. : FLOAT. : BOOL. : BOOL. eModeInnerLoop bHoldInnerLoop constant at the current value. : BOOL. : E_CTRL_MODE. (* setpoint value *) (* actual value from the process (* actual value from the process to (* pre control value *) fActualValueInnerLoop : FLOAT. the PID controller *) fPreControl : FLOAT. : The actual value of the controlled variable that is fed back to the PI controller of the outer : The actual value of the controlled variable that is fed back to the PID controller of the inner : Pre-control that is connected behind the PI controller. (* sets the mode of the function block (* hold the internal integrator *) fManSyncValueOuterLoop the sync request *) bSyncOuterLoop fManSyncValue *) eModeOuterLoop *) bHoldOuterLoop END_VAR fSetpointValue fActualValueOuterLoop control loop. : Input. fPreControl : FLOAT.

: A TRUE at this input holds the internal state of the PI element (the outer control loop) VAR_OUTPUT VAR_OUTPUT fOut the process *) : FLOAT. bSyncOuterLoop fManSyncValueOuterLoop. TwinCAT PLC Library: Controller Toolbox . : BOOL. : E_CTRL_STATE. bErrorInnerLoop eStateOuterLoop bARWactiveOuterLoop restricted. (* manipulated value to eStateInnerLoop bARWactiveInnerLoop eErrorIdInnerLoop bErrorInnerLoop situation exists *) : BOOL. eErrorIdOuterLoop set. : BOOL. bErrorOuterLoop : E_CTRL_STATE. eModeOuterLoop bHoldOuterLoop constant at the current value. : State of the internal PID element (inner control loop). : E_CTRL_ERRORCODES. (* error code *) (* TRUE if an error situation : Output of the PI-PID element. eErrorIdInnerLoop set. : State of the internal PI element (outer control loop). : A TRUE at this output indicates that the output of the PID element (the inner control loop) is : Returns the error number of the PID element (the inner control loop) when the bError output is : Is set to TRUE as soon as an error occurs in the PID element (the inner control loop). : Input.BECHHOFF 56 fManSyncValueOuterLoop loop). to whose value it is possible to set the internal state of the PI element (the outer control : A rising edge at this input sets the PI element (the outer control loop) to the value : Input that specifies the operating mode of the PI element (the outer control loop). : A TRUE at this output indicates that the PI element's (the outer control loop) output is being : Returns the error number of the PI element (the outer control loop) when the bError output is : Is set to TRUE as soon as an error occurs in the PI element (the outer control loop). : E_CTRL_ERRORCODES. (* error code *) (* TRUE if an error eStateOuterLoop bARWactiveOuterLoop eErrorIdOuterLoop bErrorOuterLoop exists *) END_VAR fOut eStateInnerLoop bARWactiveInnerLoop being restricted. : BOOL.

fMinLimit_InnerLoop : Lower limit at which integration in the PID element is halted and to which the output is limited (ARW measure). fMinLimit_OuterLoop : : Lower limit at which integration in the PID-element is halted and to which the output is limited (ARW measure). fKp_InnerLoop tTn_InnerLoop tTv_InnerLoop tTd_InnerLoop : FLOAT := 0. fMinLimit_InnerLoop : FLOAT := -1E38. The D component is deactivated if this is parameterised as T#0s. fMinLimit_OuterLoop : FLOAT := -1E38. Reaching this limit is indicated by a TRUE at the bARWactiveOuterLoop output. (* task cycle time [TIME] *) fKp_OuterLoop tTn_OuterLoop : FLOAT := 0. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. fMaxLimit_OuterLoop : Upper limit at which integration in the PID element is halted and to which the output is limited (ARW measure). fMaxLimit_InnerLoop: Upper limit at which integration in the PID element is halted and to which the output is limited (ARW measure). Reaching this limit is indicated by a TRUE at the bARWactiveInnerLoop output. END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. tTv_InnerLoop : Derivative action time of the PID element (inner control loop). (* Tn *) : TIME := T#0ms. (* proportional gain *) : TIME := T#0s. fKp_InnerLoop : Controller amplification / controller coefficient of the PID element (inner control loop). If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. fMaxLimit_OuterLoop : FLOAT := 1E38. TwinCAT PLC Library: Controller Toolbox . tTd_InnerLoop : Damping time of the PID element (inner control loop). Reaching this limit is indicated by a TRUE at the bARWactiveOuterLoop output. The I component is deactivated if this is parameterised as T#0s. This must be greater than or equal to the TaskCycleTime. (* proportional gain *) : TIME := T#0ms. (* Tv *) : TIME := T#0ms. The I component is deactivated if this is parameterised as T#0s. This consists of the following elements: TYPE ST_CTRL_PI_PID_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. Reaching this limit is indicated by a TRUE at the bARWactiveInnerLoop output.BECHHOFF 57 VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PI-PID element. (* Td *) fMaxLimit_InnerLoop : FLOAT := 1E38. tTaskCycleTime : Cycle time with which the function block is called. (* Tn *) : ST_CTRL_PI_PID_PARAMS. tTn_OuterLoop : Integral action time of the internal PI element (outer control loop). tTn_InnerLoop : Integral action time of the PID element (inner control loop). fKp_OuterLoop : Controller amplification / controller coefficient of the PI element (outer control loop).

BECHHOFF 58 Development Environment TwinCAT v2.lb6 TcControllerToolbox. A control algorithm with a differential component that is only applied to the controlled variable ( bDInTheFeedbackPath := TRUE ) can avoid this TwinCAT PLC Library: Controller Toolbox . which cause a strain on the control elements and may cause the control system to oscillate.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. Control background: due to the differential component of the control algorithm.9 from Build 947 TwinCAT v2.lib TcControllerToolbox. so that a modified functional diagram can be activated.lbx FUNCTION_BLOCK FB_CTRL_PID The function block provides a PID transfer element in the functional diagram. large control values are generated at set value discontinuities. Transfer function: Functional diagram: The standard functional diagram of a PID controller in additive form has been expanded by the two active boolean inputs bPInTheFeedbackPath and bDInTheFeedbackPath (which act as "switches").8 TwinCAT v2.

TwinCAT PLC Library: Controller Toolbox . The bPInTheFeedbackPath and bDInTheFeedbackPath inputs permit the closed control loop to implement the following transfer functions: with: ! The standard setting for the two bPInTheFeedbackPath and bDInTheFeedbackPath inputs is FALSE.BECHHOFF 59 problem. The PID controller then acts as a standard PID controller in additive form.

BECHHOFF 60 Step response: ARW: TwinCAT PLC Library: Controller Toolbox .

: Set value of the controlled variable. : Input that specifies the block's operating mode. : FLOAT.BECHHOFF 61 VAR_INPUT VAR_INPUT fActualValue fSetpointValue fManSyncValue bSync eMode bHold END_VAR fActualValue fSetpointValue fManSyncValue bSync eMode : Actual value of the controlled variable. : Input. : BOOL. : Supplies the error number when the bError output is set. : E_CTRL_ERRORCODES. : BOOL. This consists of the following elements: : ST_CTRL_PID_PARAMS. : E_CTRL_STATE. VAR_OUTPUT VAR_OUTPUT fOut bARWactive eState eErrorId bError END_VAR fOut bARWactive eState eErrorId bError : Output of the PID element. : FLOAT. TwinCAT PLC Library: Controller Toolbox . : State of the function block. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PID element. to whose value it is possible to set the internal state of the PID element. : BOOL. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : BOOL. : FLOAT. : Becomes TRUE. : FLOAT. independently of the system deviation. : A rising edge at this input sets the PID element to the value fManSyncValue. as soon as an error occurs. : E_CTRL_MODE. : A TRUE at this output indicates that the PID element is being restricted.

bARWOnIPartOnly END_STRUCT END_TYPE : BOOL. fKp tTn tTv tTd : Controller amplification / controller coefficient : Integral action time. (* proportional gain *) : TIME := T#0ms. : FLOAT := -1E38. tTaskCycleTime : Cycle time with which the function block is called.) Development Environment TwinCAT v2. : Derivative action time. fOutMinLimit : Lower limit at which integration is halted and to which the output is limited (ARW measure).BECHHOFF 62 TYPE ST_CTRL_PID_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. bDInTheFeedbackPath : BOOL. The D component is deactivated if this is parameterised as T#0s. (Cf. bPInTheFeedbackPath : Input value of the internal P element can be selected with this input (see functional diagram). (* maximum output limit *) (* minimum output limit *) fOutMaxLimit fOutMinLimit bPInTheFeedbackPath : BOOL. Reaching this limit is indicated by a TRUE at the bARWActive output. the integration is halted if the I component (the output of the integrator) reaches some limit. Standard setting: FALSE bARWOnIPartOnly: If this parameter is FALSE (the standard setting). If the block is called in every cycle this corresponds to the task cycle time of the calling task.lib TcControllerToolbox. Standard setting: FALSE bDInTheFeedbackPath : Input value of the internal D element can be selected with this input (see functional diagram).lbx TwinCAT PLC Library: Controller Toolbox . If it is TRUE.9 from Build 947 TwinCAT v2. (* Tn *) : TIME := T#0ms.lb6 TcControllerToolbox.8 TwinCAT v2. The I component is deactivated if this is parameterised as T#0s. : Damping time fOutMaxLimit : Upper limit at which integration is halted and to which the output is limited (ARW measure). The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. the integration of the I component is halted if the complete controller output reaches the upper or lower limit. (* Td *) : FLOAT := 1E38. (* Tv *) : TIME := T#0ms. functional diagram. This must be greater than or equal to the TaskCycleTime.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. Reaching this limit is indicated by a TRUE at the bARWActive output. tCtrlCycleTime : Cycle time with which the control loop is processed. (* task cycle time [TIME] *) fKp tTn tTv tTd : FLOAT := 0. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.

To optimise the regulation of such an arrangement. With this controller it is possible to switch between two different parameter records while the regulation is active. it is possible to switch between two PID parameter records. Description: This function block is an extension of FB_CTRL_PID_EXT. Transfer function: Functional diagram: TwinCAT PLC Library: Controller Toolbox . The nParameterChangeCycleTicks parameter can be used to specify the number of task cycles over which the continuous change between the two parameter records takes place. which means that the controller can be used to control systems with two controlled devices for which the transfer behaviours are different. A system with one actuator for heating and another actuator for cooling would be a typical application. Switching between the parameter records is implemented in such a way that the control value remains continuous even as the parameter records are changed. time-dependent transition between the two parameter records. The functionalities of the inner and outer windows and of the input and output dead bands are available in addition. The switching algorithm calculates a linear.BECHHOFF 63 FUNCTION_BLOCK FB_CTRL_PID_EXT_SPLITRANGE The function block provides an extended PID transfer element in the functional diagram.

large control values are generated at set value discontinuities. The PID controller then acts as a standard PID controller in additive form. A control algorithm with a differential component that is only applied to the controlled variable ( bDInTheFeedbackPath := TRUE ) can avoid this problem. TwinCAT PLC Library: Controller Toolbox . The bPInTheFeedbackPath and bDInTheFeedbackPath inputs permit the closed control loop to implement the following transfer functions: with: ! The standard setting for the two bPInTheFeedbackPath and bDInTheFeedbackPath inputs is FALSE.BECHHOFF 64 The standard functional diagram of a PID controller in additive form has been expanded by the two active boolean inputs bPInTheFeedbackPath and bDInTheFeedbackPath (which act as "switches"). so that a modified functional diagram can be activated. Control background: due to the differential component of the control algorithm. which cause a strain on the control elements and may cause the control system to oscillate.

Input dead band If the parameter fDeadBandInput is set > 0 then the output is held constant for as long as the system deviation remains within the range of [ -fDeadBandInput . fDeadBandOutput ]. Output dead band If the parameter fDeadBandOutput is set > 0. If it is not wanted.BECHHOFF 65 Additional functions: Switching off the I component in the Outer Window Integration of the system deviation is halted if the system deviation is greater than the fOuterWindow parameter. If it is not wanted. Linear reduction of the I component in the Inner Window With this function it is possible to drive the I component linearly down to zero in the range specified by the fInnerWindow parameter.. the output is set to zero when it is within the range of [ -fDeadBandOutput . the function can be disabled by setting fInnerWindow := 0. Step response: TwinCAT PLC Library: Controller Toolbox ... In this way it is possible to prevent an extremely large I component from developing if the system deviation is large. the function can be disabled by setting fOuterWindow := 0. since this could lead to a marked overshoot.. fDeadBandInput ].

VAR_OUTPUT VAR_OUTPUT fOutPos fOutNeg fOut : FLOAT. : Input that specifies the block's operating mode. : Index of the active parameter record : Input with which the PI element can be set. : A rising edge at this input sets the PI element to the value fManSyncValue. : BOOL. independently of the system deviation. : E_CTRL_PARAMETER_RECORD. : FLOAT. : FLOAT. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : FLOAT. : E_CTRL_MODE. : FLOAT. : FLOAT. : Set value of the controlled variable. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 66 ARW: VAR_INPUT VAR_INPUT fActualValue fSetpointValue eParameterRecord fManSyncValue bSync eMode bHold END_VAR fActualValue fSetpointValue eParameterRecord fManSyncValue bSync eMode : Actual value of the controlled variable. : BOOL.

(* ARW active ? [TRUE/FALSE] -> freeze I-part *) bParameterChangeActive : BOOL. : Output of the PID element. fDeadBandInput fDeadBandOutput fInnerWindow : REAL := 0. This consists of the following elements: TYPE ST_CTRL_PID_SPLITRANGE_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : Supplies the error number when the bError output is set. bError eErrorId : BOOL.BECHHOFF 67 bARWActive : BOOL := FALSE. : E_CTRL_ERRORCODES. (* proportional gain *) : TIME := T#0ms. : A TRUE at this output indicates that the PID element is being restricted. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. (* Tv *) : TIME := T#0ms. bParameterChangeActive : A TRUE at this output indicates that the change from one parameter record to the other is in progress. (* ctrl output dead band/neutral zone for zero output *) : REAL := 0.0.0. (* inner window for reduced I-part ( dE-window) *) TwinCAT PLC Library: Controller Toolbox . fCtrlDerivation eErrorId bError : A TRUE at this output indicates that the PID element is being restricted. A zero is output otherwise. (* Tv *) : TIME := T#0ms.0. (* ctrl deviation dead band/neutral zone for const output *) : REAL := 0. (* Tn *) : TIME := T#0ms. (* Td *) : ST_CTRL_PID_EXT_PARAMS. : Output of the PID element when the control value is negative. as soon as an error occurs. (* Td *) : FLOAT := 0. (* error flag *) (* error code *) END_VAR fOutPos fOutNeg fOut bARWactive : Output of the PID element when the control value is positive. (* task cycle time [TIME] *) fKp_heating tTn_heating tTv_heating tTd_heating fKp_cooling tTn_cooling tTv_cooling tTd_cooling : FLOAT := 0. : Becomes TRUE. (* proportional gain *) : TIME := T#0ms. A zero is output otherwise. nParameterChangeCycleTicks : INT. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PID element. (* Tn *) : TIME := T#0ms.

bDInTheFeedbackPath : Input value of the D element can be selected with this input (see functional diagram). : Damping time eCTRL_PARAMETER_RECORD_COOLING region: fKp_cooling tTn_cooling tTv_cooling tTd_cooling : Controller amplification / controller coefficient : Integral action time. : Damping time nParameterChangeCycleTicks: The number of task cycles over which the change from one parameter record to the other takes place. (* outer window for disabling I-part (dE-window) *) : FLOAT := 1E38. fOutMinLimit : Lower limit at which integration is halted and to which the output is limited (ARW measure). The I component is deactivated if this is parameterised as T#0s. Reaching this limit is indicated by a TRUE at the bARWActive output. The D component is deactivated if this is parameterised as T#0s. If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* minimum output limit *) : BOOL. The I component is deactivated if this is parameterised as T#0s. This must be greater than or equal to the TaskCycleTime. TwinCAT PLC Library: Controller Toolbox . Reaching this limit is indicated by a TRUE at the bARWActive output. eCTRL_PARAMETER_RECORD_HEATING region: fKp_heating tTn_heating tTv_heating tTd_heating : Controller amplification / controller coefficient : Integral action time. : Derivative action time.0. : BOOL. : BOOL. fDeadBandInput : See description above fDeadBandOutput: See description above fInnerWindow fOuterWindow : See description above : See description above fOutMaxLimit : Upper limit at which integration is halted and to which the output is limited (ARW measure). The D component is deactivated if this is parameterised as T#0s. bPInTheFeedbackPath bDInTheFeedbackPath bARWOnIPartOnly END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. : Derivative action time. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* maximum output limit *) : FLOAT := -1E38.BECHHOFF 68 fOuterWindow fOutMaxLimit fOutMinLimit : REAL := 0. tTaskCycleTime : Cycle time with which the function block is called. bPInTheFeedbackPath : Input value of the P element can be selected with this input (see functional diagram).

Transfer function: Functional diagram: TwinCAT PLC Library: Controller Toolbox .lbx FUNCTION_BLOCK FB_CTRL_PID_EXT The function block provides an extended PID element in the functional diagram.8 TwinCAT v2.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. the integration of the I component is halted if the complete controller output reaches the upper or lower limit.lib TcControllerToolbox. If it is TRUE. the integration is halted if the I component (the output of the integrator) reaches some limit. (Cf.lb6 TcControllerToolbox.) Development Environment TwinCAT v2.BECHHOFF 69 bARWOnIPartOnly: If this parameter is FALSE (the standard setting).9 from Build 947 TwinCAT v2. functional diagram.

A control algorithm with a differential component that is only applied to the controlled variable ( bDInTheFeedbackPath := TRUE ) can avoid this problem. The PID controller then acts as a standard PID controller in additive form. large control values are generated at set value discontinuities.BECHHOFF 70 The standard functional diagram of a PID controller in additive form has been expanded by the two active boolean inputs bPInTheFeedbackPath and bDInTheFeedbackPath (which act as "switches"). Control background: due to the differential component of the control algorithm. so that a modified functional diagram can be activated. TwinCAT PLC Library: Controller Toolbox . The bPInTheFeedbackPath and bDInTheFeedbackPath inputs permit the closed control loop to implement the following transfer functions: with: ! The standard setting for the two bPInTheFeedbackPath and bDInTheFeedbackPath inputs is FALSE. which cause a strain on the control elements and may cause the control system to oscillate.

. If it is not wanted. Output dead band If the parameter fDeadBandOutput is set > 0. since this could lead to a marked overshoot. Step response: TwinCAT PLC Library: Controller Toolbox .BECHHOFF 71 Additional functions: Switching off the I component in the Outer Window Integration of the system deviation is halted if the system deviation is greater than the fOuterWindow parameter... the function can be disabled by setting fInnerWindow := 0. the output is set to zero when it is within the range of [ -fDeadBandOutput .. the function can be disabled by setting fOuterWindow := 0. If it is not wanted. Input dead band If the parameter fDeadBandInput is set > 0 then the output is held constant for as long as the system deviation remains within the range of [ -fDeadBandInput . fDeadBandOutput ]. Linear reduction of the I component in the Inner Window With this function it is possible to drive the I component linearly down to zero in the range specified by the fInnerWindow parameter. fDeadBandInput ]. In this way it is possible to prevent an extremely large I component from developing if the system deviation is large.

: E_CTRL_MODE. independently of the system deviation. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value.BECHHOFF 72 ARW: VAR_INPUT VAR_INPUT fActualValue fSetpointValue fManSyncValue bSync eMode bHold END_VAR fActualValue fSetpointValue fManSyncValue bSync eMode : Actual value of the controlled variable. : FLOAT. : BOOL. : A rising edge at this input sets the PID element to the value fManSyncValue. : BOOL. : Input that specifies the block's operating mode. (* maximum limitation active ? [TRUE/FALSE] -> ARW *) bMaxLimitReached TwinCAT PLC Library: Controller Toolbox . : FLOAT. : Input with which the PID element can be set. : FLOAT. (* minimum limitation active ? [TRUE/FALSE] -> ARW *) bMinLimitReached : BOOL := FALSE. : BOOL := FALSE. : Set value of the controlled variable. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT.

:= 0. bMinLimitReached : The output is TRUE when the block is at its lower limit. (* error flag *) (* error code *) END_VAR fOut : Output of the PID-element. (* task cycle time [TIME] *) fKp tTn tTv tTd : FLOAT := 0.0. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PID element. : BOOL. fInnerWindow fOuterWindow fOutMaxLimit fOutMinLimit : REAL : REAL := 0. (* proportional gain *) : TIME := T#0ms. fDeadBandOutput : REAL := 0. bPInTheFeedbackPath : BOOL. : FLOAT := 1E38. (* Td *) (* ctrl deviation dead band/neutral zone for const output *) (* ctrl output dead band/neutral zone for zero output *) (* inner window for reduced I-part (dE-window) *) (* outer window for disabling I-part (dE-window) *) (* maximum output limit *) (* minimum output limit *) : ST_CTRL_PID_EXT_PARAMS. This consists of the following elements: TYPE ST_CTRL_PID_EXT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. bDInTheFeedbackPath : BOOL. TwinCAT PLC Library: Controller Toolbox . fDeadBandInput : REAL := 0. : FLOAT := -1E38. bMaxLimitReached : The output is TRUE when the block is at its upper limit. (* Tn *) : TIME := T#0ms.0.0. : State of the function block. (* Tv *) : TIME := T#0ms.BECHHOFF 73 bARWActive : BOOL := FALSE. : Becomes TRUE. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : E_CTRL_ERRORCODES. as soon as an error occurs. (* controller command derivation dy/dt *) eState bError eErrorId : E_CTRL_STATE. : Supplies the error number when the bError output is set.0. (* ARW active ? [TRUE/FALSE] -> freeze I-part *) fCtrlDerivation : FLOAT. bARWactive fCtrlDerivation eState eErrorId bError : A TRUE at this output indicates that the PID element is being restricted. : A TRUE at this output indicates that the PID element is being restricted.

tCtrlCycleTime : Cycle time with which the control loop is processed.BECHHOFF 74 bARWOnIPartOnly END_STRUCT END_TYPE : BOOL. functional diagram.) Development Environment TwinCAT v2. (Cf. If the block is called in every cycle this corresponds to the task cycle time of the calling task. fOutMinLimit : Lower limit at which integration is halted and to which the output is limited (ARW measure). the integration of the I component is halted if the complete controller output reaches the upper or lower limit. The I component is deactivated if this is parameterised as T#0s. This must be greater than or equal to the TaskCycleTime.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. tTaskCycleTime : Cycle time with which the function block is called. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : Damping time fDeadBandInput : See description above fDeadBandOutput: See description above fInnerWindow fOuterWindow : See description above : See description above fOutMaxLimit : Upper limit at which integration is halted and to which the output is limited (ARW measure). Reaching this limit is indicated by a TRUE at the bARWActive output. : Derivative action time. the integration is halted if the I component (the output of the integrator) reaches some limit.lbx TwinCAT PLC Library: Controller Toolbox . bDInTheFeedbackPath : Input value of the D element can be selected with this input (see functional diagram). The D component is deactivated if this is parameterised as T#0s.lib TcControllerToolbox. Reaching this limit is indicated by a TRUE at the bARWActive output.lb6 TcControllerToolbox. bPInTheFeedbackPath : Input value of the P element can be selected with this input (see functional diagram).9 from Build 947 TwinCAT v2. bARWOnIPartOnly: If this parameter is FALSE (the standard setting). fKp tTn tTv tTd : Controller amplification / controller coefficient : Integral action time.8 TwinCAT v2. If it is TRUE.

so that a modified functional diagram can be activated. Description: This function block is an extension of FB_CTRL_PID. A system with one actuator for heating and another actuator for cooling would be a typical application. With this controller it is possible to switch between two different parameter records while the regulation is active. To optimise the regulation of such an arrangement. which means that the controller can be used to control systems with two controlled devices for which the transfer behaviours are different. time-dependent transition between the two parameter records.BECHHOFF 75 FUNCTION_BLOCK FB_CTRL_PID_SPLITRANGE The function block provides an extended PID transfer element in the functional diagram. TwinCAT PLC Library: Controller Toolbox . it is possible to switch between two PID parameter records. Transfer function: Functional diagram: The standard functional diagram of a PID controller in additive form has been expanded by the two active boolean inputs bPInTheFeedbackPath and bDInTheFeedbackPath (which act as "switches"). Switching between the parameter records is implemented in such a way that the control value remains continuous even as the parameter records are changed. The nParameterChangeCycleTicks parameter can be used to specify the number of task cycles over which the continuous change between the two parameter records takes place. The switching algorithm calculates a linear.

TwinCAT PLC Library: Controller Toolbox . large control values are generated at set value discontinuities. The PID controller then acts as a standard PID controller in additive form. The bPInTheFeedbackPath and bDInTheFeedbackPath inputs permit the closed control loop to implement the following transfer functions: with: ! The standard setting for the two bPInTheFeedbackPath and bDInTheFeedbackPath inputs is FALSE. which cause a strain on the control elements and may cause the control system to oscillate.BECHHOFF 76 Control background: due to the differential component of the control algorithm. A control algorithm with a differential component that is only applied to the controlled variable ( bDInTheFeedbackPath := TRUE ) can avoid this problem.

BECHHOFF 77 Step response: ARW: TwinCAT PLC Library: Controller Toolbox .

bARWActive freeze I-part *) bParameterChangeActive : BOOL := FALSE. : FLOAT. : FLOAT. : BOOL. : BOOL. (* error flag *) (* error code *) END_VAR fOutPos fOutNeg : Output of the PID element when the control value is positive. : A rising edge at this input sets the PI element to the value fManSyncValue. : Input that specifies the block's operating mode. : BOOL. A zero is output otherwise. (* ARW active ? [TRUE/FALSE] -> eState bError eErrorId : E_CTRL_STATE. VAR_OUTPUT VAR_OUTPUT fOutPos fOutNeg fOut : FLOAT. : E_CTRL_ERRORCODES. : E_CTRL_PARAMETER_RECORD. A zero is output otherwise. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : FLOAT. : Output of the PID element when the control value is negative. independently of the system deviation. : E_CTRL_MODE. : Index of the active parameter record : Input with which the PI element can be set.BECHHOFF 78 VAR_INPUT VAR_INPUT fActualValue fSetpointValue eParameterRecord fManSyncValue bSync eMode bHold END_VAR fActualValue fSetpointValue eParameterRecord fManSyncValue bSync eMode : Actual value of the controlled variable. : Set value of the controlled variable. : BOOL. TwinCAT PLC Library: Controller Toolbox . : FLOAT. : FLOAT.

nParameterChangeCycleTicks : INT. as soon as an error occurs. : BOOL. (* proportional gain *) : TIME := T#0ms. (* proportional gain *) : TIME := T#0ms. tTaskCycleTime : Cycle time with which the function block is called. (* Td *) : ST_CTRL_PID_EXT_PARAMS. (* Tv *) : TIME := T#0ms. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : A TRUE at this output indicates that the PID element is being restricted. This must be greater than or equal to the TaskCycleTime. (* Tn *) : TIME := T#0ms. (* Tn *) : TIME := T#0ms. fCtrlDerivation eState eErrorId bError : A TRUE at this output indicates that the PID element is being restricted. : BOOL. (* Tv *) : TIME := T#0ms. (* task cycle time [TIME] *) fKp_heating tTn_heating tTv_heating tTd_heating fKp_cooling tTn_cooling tTv_cooling tTd_cooling : FLOAT := 0. : State of the function block. eCTRL_PARAMETER_RECORD_HEATING region: fKp_heating : Controller amplification / controller coefficient TwinCAT PLC Library: Controller Toolbox . bPInTheFeedbackPath bDInTheFeedbackPath bARWOnIPartOnly END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. : Becomes TRUE. If the block is called in every cycle this corresponds to the task cycle time of the calling task. bParameterChangeActive : A TRUE at this output indicates that the change from one parameter record to the other is in progress. fOutMaxLimit fOutMinLimit : FLOAT := 1E38. This consists of the following elements: TYPE ST_CTRL_PID_SPLITRANGE_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. (* maximum output limit *) : FLOAT := -1E38. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PID element.BECHHOFF 79 fOut bARWactive : Output of the PID element. (* Td *) : FLOAT := 0. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : Supplies the error number when the bError output is set. (* minimum output limit *) : BOOL.

9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.BECHHOFF 80 tTn_heating tTv_heating tTd_heating : Integral action time.lbx TwinCAT PLC Library: Controller Toolbox .) Development Environment TwinCAT v2. bPInTheFeedbackPath : Input value of the P element can be selected with this input (see functional diagram). (Cf. The D component is deactivated if this is parameterised as T#0s. The I component is deactivated if this is parameterised as T#0s. : Damping time eCTRL_PARAMETER_RECORD_COOLING region: fKp_cooling tTn_cooling tTv_cooling tTd_cooling : Controller amplification / controller coefficient : Integral action time. : Derivative action time.8 TwinCAT v2. the integration is halted if the I component (the output of the integrator) reaches some limit. : Damping time nParameterChangeCycleTicks: The number of task cycles over which the change from one parameter record to the other takes place. The I component is deactivated if this is parameterised as T#0s. bDInTheFeedbackPath : Input value of the D element can be selected with this input (see functional diagram). fOutMaxLimit : Upper limit at which integration is halted and to which the output is limited (ARW measure). : Derivative action time. Reaching this limit is indicated by a TRUE at the bARWActive output.lib TcControllerToolbox. Reaching this limit is indicated by a TRUE at the bARWActive output. the integration of the I component is halted if the complete controller output reaches the upper or lower limit. bARWOnIPartOnly: If this parameter is FALSE (the standard setting). The D component is deactivated if this is parameterised as T#0s. fOutMinLimit : Lower limit at which integration is halted and to which the output is limited (ARW measure). If it is TRUE.lb6 TcControllerToolbox. functional diagram.9 from Build 947 TwinCAT v2.

VAR_OUTPUT VAR_OUTPUT fOut eState : FLOAT. VAR_INPUT VAR_INPUT fActualValue : FLOAT. TwinCAT PLC Library: Controller Toolbox . If the specified window is exceeded for more than three cycles. : E_CTRL_MODE.BECHHOFF 81 3. fDeltaMax. : Input variable whose value is output in manual mode. then the current input value is suppressed for a maximum of three cycles. Behaviour of the output: This block allows a plausibility check to be carried out on a measured input variable. : Set value of the controlled variable. : Input that specifies the block's operating mode. If the difference between two sampling values in sequence (measurements) is larger than the specified window. The behaviour of the output is illustrated in the diagram above. Filter FUNCTION_BLOCKFB_CTRL_ACTUAL_VALUE_FILTER The function block allows a measured input variable to be checked for plausibility and filtered. the output will again follow the input variable.4. : E_CTRL_STATE. fManValue eMode END_VAR fActualValue fSetpointValue fManValue eMode : Actual value of the controlled variable. During this time the output value is extrapolated from the previous input values. : FLOAT. fSetpointValue : FLOAT.

If the block is called in every cycle this corresponds to the task cycle time of the calling task. as soon as an error occurs. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* task cycle time [TIME] *) fDeltaMax END_STRUCT END_TYPE :FLOAT. See description above. tTaskCycleTime : Cycle time with which the function block is called. : Supplies the error number when the bError output is set.9 from Build 956 TwinCAT PLC Library: Controller Toolbox . : State of the function block. : FB_CTRL_ACTUAL_VALUE_FILTER.9 from Build 947 TwinCAT v2. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the actual value filter element.lb6 TcControllerToolbox. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. tCtrlCycleTime : Cycle time with which the control loop is processed. fDeltaMax : Maximum difference between two input values in sequence.BECHHOFF 82 eErrorId bError END_VAR fOut eState eErrorId bError : E_CTRL_ERRORCODES. : Output of the function block.lib TcControllerToolbox.lbx Development Environment TwinCAT v2. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.8 TwinCAT v2. : Becomes TRUE. This consists of the following elements: TYPE FB_CTRL_ACTUAL_VALUE_FILTER: STRUCT tCtrlCycleTime : TIME := T#0ms. : BOOL. This must be greater than or equal to the TaskCycleTime.

: Input that specifies the block's operating mode. : E_CTRL_ERRORCODES. : BOOL. : BOOL.BECHHOFF 83 FUNCTION_BLOCK FB_CTRL_ARITHMETIC_MEAN Calculating the mean value: VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode bHold END_VAR fIn fManSyncValue bSync eMode : Input value for the mean value filter. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : Input value to which the mean value filter can be set. : BOOL. : FLOAT. independently of the input value. : E_CTRL_MODE. TwinCAT PLC Library: Controller Toolbox . or that is issued at the output in manual mode. : E_CTRL_STATE. : FLOAT. : A rising edge at this input sets the mean value filter to the value fManSyncValue. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR : FLOAT.

VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the mean value filter.lbx : ST_CTRL_ARITHMETIC_MEAN_PARAMS.lb6 TcControllerToolbox. : Becomes TRUE. : State of the function block.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. : Supplies the error number when the bError output is set. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* task cycle time [TIME] *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed.8 TwinCAT v2. tTaskCycleTime : Cycle time with which the function block is called.lib TcControllerToolbox. If the block is called in every cycle this corresponds to the task cycle time of the calling task.9 from Build 947 TwinCAT v2. The coefficients for the following transfer structure are stored in the parameter arrays: TwinCAT PLC Library: Controller Toolbox . FUNCTION_BLOCK FB_CTRL_DIGITAL_FILTER This block calculates a discrete transfer function with the structure described below. This must be greater than or equal to the TaskCycleTime. The transfer function here can be of any order. Development Environment TwinCAT v2.BECHHOFF 84 fOut eState eErrorId bError : Output of the mean value filter. This structure allows either an FIR filter (Finite Impulse Response) or an IIR filter (Infinite Impulse Response) to be implemented. This consists of the following elements: TYPE ST_CTRL_ARITHMETIC_MEAN_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. as soon as an error occurs. n.

The coefficients a1 to an are stored in the array ar_CoefficientsArray_a. (* not being evaluated *) ar_DenominatorArray [ 2 ] := a2. The coefficients b1 to bn are stored in the array ar_CoefficientsArray_b.nFilterOrder+1] OF FLOAT. := bn..nFilterOrder+1] OF FLOAT..BECHHOFF 85 The programmer must create the following arrays in the PLC if this function block is to be used: ar_CoefficientsArray_a : ARRAY[1. TwinCAT PLC Library: Controller Toolbox . ar_CoefficientsArray_b : ARRAY[1. This must be organised as follows: ar_fNumeratorArray[ 1 ] ar_fNumeratorArray[ 2 ] . . VAR_INPUT VAR_INPUT fIn fManValue eMode END_VAR : FLOAT. The internal data required by the block is stored in the ar_stDigitalFilterData array. : FLOAT. This must be organised as follows: ar_DenominatorArray [ 1 ] := xxx.nFilterOrder ] OF ST_CTRL_DIGITAL_FILTER_DATA. := bn-1. ar_DenominatorArray [ n-1 ] := an-1. ar_fNumeratorArray[ n-1 ] ar_fNumeratorArray[ n ] := b1.. This procedure is also illustrated in the example program listed below. This data must never be modified from within the PLC program. := b2. : E_CTRL_MODE... ar_stDigitalFilterData : ARRAY[1... ar_DenominatorArray [ n ] := an.

nDigitalFilterData_SIZEOF : UINT. : E_CTRL_ERRORCODES. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block.. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. tCtrlCycleTime : Cycle time with which the control loop is processed. pCoefficientsArray_b_ADR : POINTER TO FLOAT := 0. : Order of the digital filter [0.BECHHOFF 86 fIn fManValue eMode : Input of the digital filter. (* controller cycle time *) nFilterOrder : USINT. ] nFilterOrder TwinCAT PLC Library: Controller Toolbox . : Supplies the error number when the bError output is set. This consists of the following elements: TYPE ST_CTRL_DIGITAL_FILTER_PARAMS : STRUCT tTaskCycleTime : TIME. (* task cycle time *) tCtrlCycleTime : TIME := T#0ms. VAR_OUTPUT VAR_OUTPUT fOut eState bError eErrorId END_VAR fOut eState eErrorId bError : Output of the digital filter. : FLOAT. : Becomes TRUE. : Input that specifies the block's operating mode. : BOOL. END_STRUCT END_TYPE tTaskCycleTime : Cycle time with which the function block is called. as soon as an error occurs. : E_CTRL_STATE. If the block is called in every cycle this corresponds to the task cycle time of the calling task. nCoefficientsArray_b_SIZEOF : UINT. nCoefficientsArray_a_SIZEOF : UINT. This must be greater than or equal to the TaskCycleTime. pCoefficientsArray_a_ADR : POINTER TO FLOAT := 0. pDigitalFilterData_ADR : POINTER TO ST_CTRL_DIGITAL_FILTER_DATA. : Input whose value is present at the output in manual mode. : State of the function block.. : ST_CTRL_DIGITAL_FILTER_PARAMS.

ar_CoefficientsArray_a[3] := 0.nFilterOrder := 2. (* set values in the parameter struct *) stParams.6. (* not used *) ar_CoefficientsArray_a[2] := 0. END_STRUCT END_TYPE Example: PROGRAM PRG_DIGITAL_FILTER_TEST VAR fbDigitalFilter : FB_CTRL_DIGITAL_FILTER. (* set the mode *) eMode := eCTRL_MODE_ACTIVE.tTaskCycleTime := T#2ms. :Size of the array containing the a coefficients.BECHHOFF 87 pCoefficientsArray_a_ADR nCoefficientsArray_a_SIZEOF pCoefficientsArray_b_ADR nCoefficientsArray_b_SIZEOF pDigitalFilterData_ADR nDigitalFilterData_SIZEOF : Address of the array containing the a coefficients. bInit := FALSE. TYPE ST_CTRL_DIGITAL_FILTER_DATA STRUCT Internal structure. END_IF TwinCAT PLC Library: Controller Toolbox . ar_CoefficientsArray_b[3] := 0. Write access to this structure is not permitted.tCtrlCycleTime := T#2ms.3 ] OF FLOAT.2.3 ] OF FLOAT.4. END_VAR IF bInit THEN (* set values in the local arrays *) ar_CoefficientsArray_a[1] := 0. : Address of the data array. stParams : ST_CTRL_DIGITAL_FILTER_PARAMS. ar_stDigitalFilterData : ARRAY[1. : Address of the array containing the b coefficients. ar_CoefficientsArray_b[2] := 0. stParams.. in bytes. in bytes. ar_CoefficientsArray_b[1] := 0. ar_CoefficientsArray_b : ARRAY[1.2 ] OF ST_CTRL_DIGITAL_FILTER_DATA. ar_CoefficientsArray_a : ARRAY[1. : Size of the array containing the b coefficients. eMode : E_CTRL_MODE. bError : BOOL.0.1. stParams. eErrorId : E_CTRL_ERRORCODES. : Size of the data array in bytes..2. bInit : BOOL := TRUE. : FLOAT.. fIn fOut : FLOAT := 0.

nDigitalFilterData_SIZEOF := SIZEOF( ar_stDigitalFilterData ).nCoefficientsArray_b_SIZEOF := SIZEOF( ar_CoefficientsArray_b).lib TcControllerToolbox. Description: The arithmetic mean of the last n values is calculated.pCoefficientsArray_b_ADR := ADR( ar_CoefficientsArray_b). n ] of FLOAT.9. eErrorId => eErrorId.pDigitalFilterData_ADR := ADR( ar_stDigitalFilterData ).lbx FUNCTION_BLOCK FB_CTRL_MOVING_AVERAGE The function block provides a moving mean value filter in the functional diagram. fOut => fOut. eMode := eMode. bError => bError).8 TwinCAT v2.. fbDigitalFilter ( fIn := fIn. Development environment TwinCAT v2.nCoefficientsArray_a_SIZEOF := SIZEOF( ar_CoefficientsArray_a). stParams. stParams. stParams.lb6 TcControllerToolbox. TwinCAT PLC Library: Controller Toolbox .9.pCoefficientsArray_a_ADR := ADR( ar_CoefficientsArray_a). build 947 onwards TwinCAT v2. stParams. The programmer must create an array. in which the function block can store the data that it requires internally.BECHHOFF 88 (* set addresses *) stParams. stParams. build 956 onwards Target system type PC (i386) BC BX PLC libraries to be linked TcControllerToolbox. ARRAY [ 1. stParams := stParams.

: BOOL. : Input value to which the moving average filter can be set. : State of the function block. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR fOut eState eErrorId bError : Output of the moving average filter. as soon as an error occurs. : BOOL. : E_CTRL_ERRORCODES. : E_CTRL_STATE. : A rising edge at this input sets the moving average filter to the value fManSyncValue. TwinCAT PLC Library: Controller Toolbox . : FLOAT. : FLOAT. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the moving average filter. or that is issued at the output in manual mode. independently of the input value.BECHHOFF 89 VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode bHold END_VAR fIn fManSyncValue bSync eMode : Input variable for the moving average filter. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : Becomes TRUE. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. This consists of the following elements: TYPE ST_CTRL_MOVING_AVERAGE_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. : BOOL. : E_CTRL_MODE. : FLOAT. : Supplies the error number when the bError output is set. (* task cycle time [TIME] *) nSamplesToFilter : UINT. : Input that specifies the block's operating mode. : ST_CTRL_MOVING_AVERAGE_PARAMS.

. Development Environment TwinCAT v2. n. fAmplitude/2 ] . This must be greater than or equal to the TaskCycleTime. TwinCAT PLC Library: Controller Toolbox . tTaskCycleTime : Cycle time with which the function block is called. nWorkArray_SIZEOF: The size of the work array. Output signal: Output signal with an amplitude of 5.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.0. END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. If the block is called in every cycle this corresponds to the task cycle time of the calling task.. nSamplesToFilter pWorkArray_ADR : The number of values. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.lbx FUNCTION_BLOCK FB_CTRL_NOISE_GENERATOR(only on a PC system) This function block generates a noise signal on the basis of the pseudo-random number in the range [ -fAmplitude/2 .BECHHOFF 90 pWorkArray_ADR : POINTER TO FLOAT := 0.lb6 TcControllerToolbox. nWorkArray_SIZEOF : UINT := 0.lib TcControllerToolbox. whose arithmetic mean is calculated.9 from Build 947 TwinCAT v2. : The address of the array where the input values are temporarily stored.8 TwinCAT v2.

fAmplitude : Amplitude of the output signal.0 . This consists of the following elements: TYPE ST_CTRL_NOISE_GENERATOR_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. : Input that specifies the block's operating mode. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : FLOAT. as soon as an error occurs. : Becomes TRUE.0 ] is created at the function block's output. If the block is called in every cycle this corresponds to the task cycle time of the calling task. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the noise generator. : E_CTRL_ERRORCODES. This must be greater than or equal to the TaskCycleTime. : BOOL. : E_CTRL_MODE..BECHHOFF 91 VAR_INPUT VAR_INPUT fManSyncValue eMode END_VAR fManSyncValue eMode : Input magnitude whose value is sent to the output in manual mode. : Cycle time with which the control loop is processed. (* task cycle time [TIME] *) fAmplitude END_TYPE tCtrlCycleTime : FLOAT := 0. fAmplitude/2. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. TwinCAT PLC Library: Controller Toolbox . : Supplies the error number when the bError output is set.. : E_CTRL_STATE. : State of the function block. A noise signal extending over the range [ -fAmplitude/2. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR fOut eState eErrorId bError : Output of the noise generator. tTaskCycleTime : Cycle time with which the function block is called. : FLOAT. : ST_CTRL_NOISE_GENERATOR_PARAMS.

8 Target system type PC (i386) PLC libraries to be linked TcControllerToolbox.lib FUNCTION_BLOCK FB_CTRL_PT1 The function block provides a PT1 transfer element in the functional diagram. Transfer function: Step response: TwinCAT PLC Library: Controller Toolbox .BECHHOFF 92 Development environment TwinCAT v2.

: FLOAT. independently of the input value. TYPE ST_CTRL_PT1_PARAMS : STRUCT TwinCAT PLC Library: Controller Toolbox . VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PT1 element. : E_CTRL_ERRORCODES. : Supplies the error number when the bError output is set. as soon as an error occurs. : E_CTRL_STATE. or that is issued at the output in manual mode. : State of the function block. : A rising edge at this input sets the PT1 element to the value fManSyncValue. : Becomes TRUE. : BOOL. : Input value to which the PT1 element can be set. : BOOL. This consists of the following elements: : ST_CTRL_PT1_PARAMS. : FLOAT. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR fOut eState eErrorId bError : Output of the PT1 element.BECHHOFF 93 VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode bHold END_VAR fIn fManSyncValue bSync eMode : Input value of the PT1 element. : Input that specifies the block's operating mode. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. : BOOL. : FLOAT. : E_CTRL_MODE.

8 TwinCAT v2.lbx Development Environment TwinCAT v2. (* task cycle time [TIME] *) fKp tT1 END_STRUCT END_TYPE : FLOAT : TIME := 0. (* proportional gain *) := T#0ms. This must be greater than or equal to the TaskCycleTime.9 from Build 956 FUNCTION_BLOCK FB_CTRL_PT2 The function block provides a non-oscillating PT2 transfer element in the functional diagram. tTaskCycleTime : Cycle time with which the function block is called. (* controller cycle time [TIME] *) := T#0ms. Transfer function: TwinCAT PLC Library: Controller Toolbox .lb6 TcControllerToolbox.BECHHOFF 94 tCtrlCycleTime tTaskCycleTime : TIME : TIME := T#0ms. If the block is called in every cycle this corresponds to the task cycle time of the calling task. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.9 from Build 947 TwinCAT v2. (* T1 *) tCtrlCycleTime : Cycle time with which the control loop is processed.lib TcControllerToolbox. fKp tT1 : Controller amplification / transfer coefficient : Time constant Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.

END_VAR TwinCAT PLC Library: Controller Toolbox . bError : BOOL. : E_CTRL_STATE. independently of the input value. : Input value that is output in manual mode.BECHHOFF 95 Step response: VAR_INPUT VAR_INPUT fIn fManValue eMode bHold END_VAR fIn fManValue eMode : Input value of the PT2 element. eErrorId : E_CTRL_ERRORCODES. : FLOAT. : BOOL. : Input that specifies the block's operating mode. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. VAR_OUTPUT VAR_OUTPUT fOut eState : FLOAT. : FLOAT. : E_CTRL_MODE.

: State of the function block. This consists of the following elements: TYPE ST_CTRL_PT2_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. (* task cycle time [TIME] *) fKp : FLOAT := 0. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PT2 element. fKp tT1 tT2 : Controller amplification / transfer coefficient : Time constant T1 : Time constant T2 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.9 from Build 956 TwinCAT PLC Library: Controller Toolbox .lbx : ST_CTRL_PT2_PARAMS.9 from Build 947 TwinCAT v2.8 TwinCAT v2. This must be greater than or equal to the TaskCycleTime. : Becomes TRUE. : Supplies the error number when the bError output is set. as soon as an error occurs. (* T2 *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. (* proportional gain *) tT1 : TIME := T#0ms.lb6 TcControllerToolbox. Development Environment TwinCAT v2.BECHHOFF 96 fOut eState eErrorId bError : Output of the PT2 element. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* T1 *) tT2 : TIME := T#0ms. tTaskCycleTime : Cycle time with which the function block is called.lib TcControllerToolbox. If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.

: BOOL.BECHHOFF 97 FUNCTION_BLOCK FB_CTRL_PT2oscillation The function block provides an oscillating PT2 transfer element in the functional diagram. : E_CTRL_MODE. : FLOAT. Transfer function: Step response: VAR_INPUT VAR_INPUT fIn fManValue eMode bHold END_VAR : FLOAT. TwinCAT PLC Library: Controller Toolbox .

If the block is called in every cycle this corresponds to the task cycle time of the calling task. eErrorId : E_CTRL_ERRORCODES. : Input value that is output in manual mode. independently of the input value. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. (* damping ratio *) : TIME := T#0ms. : Becomes TRUE. (* T0 *) : ST_CTRL_PT2oscillation_PARAMS. as soon as an error occurs. bError : BOOL. tTaskCycleTime : Cycle time with which the function block is called. : Input that specifies the block's operating mode. END_VAR fOut eErrorId bError : Output of the PT2 element. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : Supplies the error number when the bError output is set. This consists of the following elements: TYPE ST_CTRL_PT2oscillation_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. (* task cycle time [TIME] *) fKp fTheta tT0 END_STRUCT END_TYPE : FLOAT := 0. tCtrlCycleTime : Cycle time with which the control loop is processed. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the oscillating PT2 element. (* proportional gain *) : FLOAT := 0. eState : E_CTRL_STATE. fKp fTheta tT0 : Proportional gain : Damping ratio : Characteristic time TwinCAT PLC Library: Controller Toolbox . (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value.BECHHOFF 98 fIn fManValue eState eMode : Input variable of the oscillating PT2 element. : State of the function block.

Transfer function: Step response: TwinCAT PLC Library: Controller Toolbox .BECHHOFF 99 Development Environment TwinCAT v2.lb6 TcControllerToolbox.lbx FUNCTION_BLOCK FB_CTRL_PT3 The function block provides a non-oscillating PT3 transfer element in the functional diagram.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.9 from Build 947 TwinCAT v2.8 TwinCAT v2.

: State of the function block. as soon as an error occurs. This consists of the following elements: TYPE ST_CTRL_PT3_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : BOOL. bError : BOOL. TwinCAT PLC Library: Controller Toolbox . END_VAR fOut eState eErrorId bError : Output of the PT3 element. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. eErrorId : E_CTRL_ERRORCODES. : Input that specifies the block's operating mode. (* proportional gain *) : TIME := T#0ms. : Input value that is output in manual mode.BECHHOFF 100 VAR_INPUT VAR_INPUT fIn fManValue eMode bHold END_VAR fIn fManValue eMode : Input value of the PT3 element. eState : E_CTRL_STATE. independently of the input value. (* task cycle time [TIME] *) fKp tT1 : FLOAT := 0. : Supplies the error number when the bError output is set. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. : E_CTRL_MODE. : Becomes TRUE. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PT3 element. : FLOAT. (* T1 *) : ST_CTRL_PT3_PARAMS. : FLOAT.

(* T3 *) tCtrlCycleTime : Cycle time with which the control loop is processed. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.BECHHOFF 101 tT2 : TIME tT3 : TIME END_STRUCT END_TYPE := T#0ms.8 TwinCAT v2.9 from Build 947 TwinCAT v2. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tTaskCycleTime : Cycle time with which the function block is called. This must be greater than or equal to the TaskCycleTime.lb6 TcControllerToolbox. (* T2 *) := T#0ms.lib TcControllerToolbox. fKp tT1 tT2 tT3 : Controller amplification / transfer coefficient : Time constant T1 : Time constant T2 : Time constant T3 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.9 from Build 956 FUNCTION_BLOCK FB_CTRL_PTn This function block provides a non-oscillating PTn transfer element with (n<= 10) and equal time constants in the functional diagram.lbx Development Environment TwinCAT v2. Transfer function: Step response with n=10: TwinCAT PLC Library: Controller Toolbox .

END_VAR fOut eState eErrorId bError : Output of the PTn element. : FLOAT. eErrorId : E_CTRL_ERRORCODES. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. bError : BOOL. : Input value that is output in manual mode. : Becomes TRUE. TwinCAT PLC Library: Controller Toolbox . : BOOL. independently of the input value. : E_CTRL_MODE.BECHHOFF 102 VAR_INPUT VAR_INPUT fIn fManValue eMode bHold END_VAR fIn fManValue eMode : Input value of the PTn element. as soon as an error occurs. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. eState : E_CTRL_STATE. : Input that specifies the block's operating mode. : FLOAT. : State of the function block. : Supplies the error number when the bError output is set.

8 TwinCAT v2. Development Environment TwinCAT v2. (* proportional gain *) tT1 : TIME := T#0ms. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.9 from Build 947 TwinCAT v2. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. This consists of the following elements: TYPE ST_CTRL_PTn_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms.lbx : ST_CTRL_PTn_PARAMS.BECHHOFF 103 VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PTn element. (* T1 *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. If the block is called in every cycle this corresponds to the task cycle time of the calling task. (* task cycle time [TIME] *) fKp : FLOAT := 0.lb6 TcControllerToolbox. tTaskCycleTime : Cycle time with which the function block is called. This must be greater than or equal to the TaskCycleTime.9 from Build 956 FUNCTION_BLOCK FB_CTRL_PTt The function block provides an PTt transfer element in the functional diagram.lib TcControllerToolbox. Transfer function: TwinCAT PLC Library: Controller Toolbox . fKp tT1 : Controller amplification / transfer coefficient : Time constant T1 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.

: Becomes TRUE. VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode END_VAR fIn fManSyncValue bSync eMode : Input variable of the PTt element. : FLOAT. the sampling time is extended internally to make it possible to reach the requested dead time. bSampleRateChanged eErrorId bError END_VAR fOut bSampleRateChanged : Output that indicates whether the block has internally reduced the sampling rate because of the array being used to delay the input signal not otherwise providing sufficient room. or that is issued at the output in manual mode.BECHHOFF 104 Description: This function block contains internally an array of 500 elements with which the input values can be delayed. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PTt element. however. This consists of the following elements: TYPE ST_CTRL_PTt_PARAMS : : ST_CTRL_PTt_PARAMS. this is indicated by a TRUE on the bSampleRateChanged output. eErrorId bError : Supplies the error number when the bError output is set. : Input that specifies the block's operating mode. If this maximum delay is insufficient. : A rising edge at this input sets the PTt element to the value fManSyncValue. Using tCtrlCycleTime yields a maximum delay of 500 * tCtrlCycleTime. It should. : BOOL. : Input value to which the PTt element can be set. : E_CTRL_MODE. : FLOAT. : E_CTRL_ERRORCODES. : Output of the PTt element. : BOOL. TwinCAT PLC Library: Controller Toolbox . VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. : BOOL. If a new sampling time has been calculated. be remembered that this process involves increasing the time between the discretisation steps. as soon as an error occurs.

The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.9 from Build 956 FUNCTION_BLOCK FB_CTRL_SERVO_MOTOR_SIMULATION (only on a PC system) The behaviour of an actuator can be simulated with this function block. Behaviour of the output: TwinCAT PLC Library: Controller Toolbox . (* task cycle time [TIME] *) fKp : FLOAT := 0.lbx Development Environment TwinCAT v2.lib TcControllerToolbox. (* proportional gain *) tTt : TIME := T#0ms.9 from Build 947 TwinCAT v2.BECHHOFF 105 STRUCT tCtrlCycleTime : TIME := T#0ms.lb6 TcControllerToolbox. This must be greater than or equal to the TaskCycleTime. (* Tt *) END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tTaskCycleTime : Cycle time with which the function block is called. fKp tTt : Controller amplification / transfer coefficient : Delay time Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.8 TwinCAT v2.

.. bUpperLimitSwitch bLowerLimitSwitch eState eErrorId bError END_VAR fMotorPosition fMotorState : E_CTRL_STATE. : E_CTRL_MODE. (* [ fMovingRangeMin . fMovingRangeMax ] *) : FLOAT.0 ]. (* [ 0 . or the value to which movement takes place in : A rising edge at this input sets the simulated motor position to the value fManSyncValue.. 100 ] *) : BOOL. fMovingRangeMax ]. : Simulated motor position in the range [ fMovingRangeMin . : BOOL. : Input that specifies the block's operating mode.. : Input that moves the simulated actuator in the negative direction. : Simulated motor position in the range [ 0 … 100.BECHHOFF 106 VAR_INPUT VAR_INPUT bMovePos bMoveNeg fManSyncValue bSync eMode END_VAR bMovePos bMoveNeg fManSyncValue manual mode. : BOOL. : BOOL. : Input with which the simulated motor position can be set. : BOOL.. bSync eMode : Input that moves the simulated actuator in the positive direction. TwinCAT PLC Library: Controller Toolbox . VAR_OUTPUT VAR_OUTPUT fMotorPositon fMotorState : FLOAT. : FLOAT. : E_CTRL_ERRORCODES.. : BOOL.

This must be greater than or equal to the TaskCycleTime. tTaskCycleTime : Cycle time with which the function block is called.lib TwinCAT PLC Library: Controller Toolbox . : Cycle time with which the control loop is processed. : Simulated limit switch at the actuator's negative stop.g. : Becomes TRUE. : FLOAT := 0. (* min position in the moving range. : TIME := T#0ms. fMovingRangeMin : Minimum position of the simulated actuator. : Supplies the error number when the bError output is set. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : State of the function block. (* task cycle time [TIME] *) fMovingRangeMin fMovingRangeMax tMovingTime tDeadTime END_STRUCT END_TYPE tCtrlCycleTime : FLOAT := 0. e.BECHHOFF 107 bUpperLimitSwitch bLowerLimitSwitch eState eErrorId bError : Simulated limit switch at the actuator's positive stop. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. 0° *) (* max position in the moving range. 360° *) (* time to move from the min to the max *) (* wait dead time before starting the movement *) : ST_CTRL_SERVO_MOTOR_SIMULATION_PARAMS. as soon as an error occurs.8 Target system type PC (i386) PLC libraries to be linked TcControllerToolbox. : Delay time of the simulated actuator. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : TIME := T#0ms. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. fMovingRangeMax : Maximum position of the simulated actuator. tMovingTime tDeadTime : The time required to move the simulated actuator from one stop to the other. e.g. This consists of the following elements: TYPE ST_CTRL_SERVO_MOTOR_SIMULATION_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. Development environment TwinCAT v2.

: BOOL. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 108 FUNCTION_BLOCK FB_CTRL_TuTg The function block provides a TuTg transfer element (a dead time delay element) in the functional diagram. : E_CTRL_MODE. : BOOL. Transfer function: Step response: VAR_INPUT VAR_INPUT fIn fManSyncValue bSync eMode bHold END_VAR : FLOAT. : FLOAT.

: Becomes TRUE. (* task cycle time [TIME] *) fKp tTu tTg END_TYPE : FLOAT := 0. : Input that specifies the block's operating mode. (* proportional gain *) : TIME := T#0ms. : BOOL. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : Supplies the error number when the bError output is set. bSampleRateChanged eState eErrorId bError END_VAR fOut : E_CTRL_STATE. independently of the input value. tTaskCycleTime : Cycle time with which the function block is called. (* dead time *) : TIME := T#0ms. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the TuTg element. This consists of the following elements: TYPE ST_CTRL_TuTg_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : Output of the TuTg element. tCtrlCycleTime : Cycle time with which the control loop is processed. : E_CTRL_ERRORCODES. eState eErrorId bError : State of the function block. : A rising edge at this input sets the TuTg element to the value fManSyncValue. or that is issued at the output in manual mode. (* delay time *)END_STRUCT : ST_CTRL_TuTg_PARAMS. as soon as an error occurs. bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value. If the block is called in every cycle this corresponds to the task cycle time of the calling task. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. : BOOL.BECHHOFF 109 fIn fManSyncValue bSync eMode : Input value of the TuTg element. : Input value to which the TuTg element can be set. fKp : Controller amplification / transfer coefficient TwinCAT PLC Library: Controller Toolbox . (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. This must be greater than or equal to the TaskCycleTime. bSmpleRateChanged : Output that indicates whether the block has internally reduced the sampling rate because of the array being used to delay the input signal not otherwise providing sufficient room.

arrTable[6. arrTable[2.1] := 21.2] := 7.1] := 10.lib TcControllerToolbox.8 TwinCAT v2. arrTable[4.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.1] := 30. fOut arrTable[1. TwinCAT PLC Library: Controller Toolbox . arrTable[2.1] := 22.5. arrTable[4. arrTable[5. Behaviour of the output: fIn arrTable[1.9 from Build 947 TwinCAT v2.1] := 15.BECHHOFF 110 tTu tTg : Delay time : Time constant Development Environment TwinCAT v2.2] := 6. Interpolation FUNCTION_BLOCK FB_CTRL_LIN_INTERPOLATION This block performs linear interpolation to obtain values on the basis of a table of interpolation points.2] := 9. arrTable[3.2] := 10.2] := 2. arrTable[3.2] := 3. arrTable[6.lb6 TcControllerToolbox.lbx 3. arrTable[5.1] := 40.

: E_CTRL_ERRORCODES. bExtrapolate : If this input is FALSE.BECHHOFF 111 VAR_INPUT VAR_INPUT fIn fManValue bExtrapolate eMode END_VAR fIn bManValue : Input variable for the interpolation block. : Input variable whose value is output in manual mode. bInIsGreaterThanMaxElement bInIsLessThanMinElement eState eErrorId bError END_VAR fOut bInIsGreaterThanMaxElement largest interpolation point. then the value of the last interpolation point is output if the limits of the table are exceeded. eMode : Input that specifies the block's operating mode. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. then extrapolation is performed on the basis of the last two interpolation points. : BOOL. : BOOL. : Table value from linear interpolation. : A TRUE at this output indicates that the magnitude of the input is greater than the TwinCAT PLC Library: Controller Toolbox . : BOOL. : BOOL. : FLOAT. : FLOAT. it is TRUE. however. : E_CTRL_MODE. : E_CTRL_STATE. If.

as soon as an error occurs. nDataTable_SIZEOF : UINT := 0. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : Supplies the error number when the bError output is set. nDataTable_NumberOfRows : UINT := 0. tTaskCycleTime : Cycle time with which the function block is called. This consists of the following elements: TYPE ST_CTRL_2POINT_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. : Becomes TRUE.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.BECHHOFF 112 bInIsLessThanMinElement smallest interpolation point. TwinCAT PLC Library: Controller Toolbox .8 TwinCAT v2. Development Environment TwinCAT v2. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the interpolation element. This must be greater than or equal to the TaskCycleTime.9 from Build 947 TwinCAT v2. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.lib TcControllerToolbox. (* task cycle time [TIME] *) pDataTable_ADR : POINTER TO FLOAT := 0. eState eErrorId bError : A TRUE at this output indicates that the magnitude of the input is smaller than the : State of the function block.lb6 TcControllerToolbox.lbx : ST_CTRL_LIN_INTERPOLATION_PARAMS. pDataTable_NumberOfRows : Number of rows in the array. pDataTable_ADR : Address of the n x 2 array on which linear interpolation is to be carried out pDataTable_SIZEOF : Size of the n x 2 array.

2] := -70. arrTable[2. The inverse characteristic curve is calculated from this characteristic curve: TwinCAT PLC Library: Controller Toolbox .1] := 1.2] := -100. The function block uses this to calculate the inverse characteristic curve with which the linearisation can be carried out. Control value arrTable[1.1] := -6. arrTable[3. arrTable[4.1] := 6. Valve position arrTable[1. The characteristic curve of the transfer element that is to be linearised is stored in the table associated with this block.2] := 100.2] := 70. arrTable[4. with the aid of an inverse characteristic curve.BECHHOFF 113 FUNCTION_BLOCK FB_CTRL_NORMALIZE This function block can be used to linearise a non-linear transfer element. Example: The following characteristic curve for a valve is stored in the table with 4 interpolation points. arrTable[3.1] := -1. arrTable[2.

TwinCAT PLC Library: Controller Toolbox . applying these two characteristic curves in series will result in a linear transfer behaviour. : BOOL. : E_CTRL_MODE. : FLOAT. VAR_INPUT VAR_INPUT fIn fManValue bExtrapolate eMode END_VAR : FLOAT.BECHHOFF 114 In the ideal case.

bInIsGreaterThanMaxElement bInIsLessThanMinElement eState eErrorId bError END_VAR fOut bInIsGreaterThanMaxElement largest interpolation point. : Supplies the error number when the bError output is set. VAR_OUTPUT VAR_OUTPUT fOut : FLOAT. This consists of the following elements: TYPE ST_CTRL_NORMALIZE_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. eState eErrorId bError : E_CTRL_STATE. : BOOL. : A TRUE at this output indicates that the magnitude of the input is greater than the : A TRUE at this output indicates that the magnitude of the input is smaller than the : State of the function block. (* task cycle time [TIME] *) pDataTable_ADR : POINTER TO FLOAT := 0. however. as soon as an error occurs. bInIsLessThanMinElement smallest interpolation point. : E_CTRL_ERRORCODES. nDataTable_NumberOfRows : UINT := 0. : Table value from linear interpolation. This must be greater than or equal to the TaskCycleTime. it is TRUE. : BOOL. : Becomes TRUE. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : ST_CTRL_NORMALIZE_PARAMS. bExtrapolate : If this input is FALSE. : Input variable whose value is output in manual mode.BECHHOFF 115 fIn bManValue : Input value. TwinCAT PLC Library: Controller Toolbox . then the value of the last interpolation point is output if the limits of the table are exceeded. nDataTable_SIZEOF : UINT := 0. END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. then extrapolation is performed on the basis of the last two interpolation points. eMode : Input that specifies the block's operating mode. If. : BOOL.

lbx 3. Monitoring/Alarming FUNCTION_BLOCK FB_CTRL_CHECK_IF_IN_BAND This function block monitors whether the input value is within the range [ fMin . VAR_OUTPUT VAR_OUTPUT bInBand bNotInBand eErrorId bError END_VAR : BOOL. TwinCAT PLC Library: Controller Toolbox .6.. : E_CTRL_ERRORCODES. If the block is called in every cycle this corresponds to the task cycle time of the calling task.lb6 TcControllerToolbox. : FLOAT. pDataTable_NumberOfRows : Number of rows in the array. VAR_INPUT VAR_INPUT fIn END_VAR fIn : The input variable to be monitored.8 TwinCAT v2..BECHHOFF 116 tTaskCycleTime : Cycle time with which the function block is called. : BOOL.9 from Build 947 TwinCAT v2. : BOOL. i.e.lib TcControllerToolbox. fMax ]. pDataTable_ADR : Address of the n x 2 array on which linear interpolation is to be carried out pDataTable_SIZEOF : Size of the n x 2 array. whether the inequality is satisfied.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. Development Environment TwinCAT v2.

8 TwinCAT v2. : Becomes TRUE.BECHHOFF 117 bInBand bNotInBand eErrorId bError : A TRUE at this output indicates that the input value is within the specified range. This must be greater than or equal to the TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. : Supplies the error number when the bError output is set. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : ST_CTRL_CHECK_IF_IN_BAND_PARAMS. fMin fMax : Lower limit of the range.9 from Build 947 TwinCAT v2. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. as soon as an error occurs. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tTaskCycleTime : Cycle time with which the function block is called. (* task cycle time [TIME] *) fMin fMax END_STRUCT END_TYPE : FLOAT.lib TcControllerToolbox.lb6 TcControllerToolbox. : Upper limit of the range.lbx Development Environment TwinCAT v2. tCtrlCycleTime : Cycle time with which the control loop is processed.9 from Build 956 TwinCAT PLC Library: Controller Toolbox . This consists of the following elements: TYPE ST_CTRL_CHECK_IF_IN_BAND_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. : FLOAT. : A TRUE at this output indicates that the input value is not within the specified range. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block.

tLogCycleTime := T\#2s is chosen. The file remains open until the block's mode is set to eCTRL_MODE_PASSIVE. an internal buffer with the size of 1500 bytes is used. for example. : T_CTRL_LOGGER_DATA. for instance. and this buffer is written into the file as quickly as possible.CSV format. The single entries are seperated by a comma. If this is not done. The fill level of the internal buffer is shown at the output fBufferUsage.nCTRL_LOGGER_DATA_ARRAY_SIZE] OF FLOAT. it is possible that not all the entries will be written into the file. The bBusy output is TRUE when the logging of a line has been started. then an entry is made in the file every 2s. In the absence of an external buffer. It is essential that the file is closed by switching into eCTRL_MODE_PASSIVE before attempting to analyse the log file. The column headings specified by the user are written in the first line of this file. • Operating without an external buffer: Operating with an external buffer: VAR_INPUT VAR_INPUT fLogData eMode END_VAR VAR_GLOBAL CONSTANT nCTRL_LOGGER_DATA_ARRAY_SIZE END_VAR TYPE T_CTRL_LOGGER_DATA END_TYPE :UINT := 10. This interval is specified with the tLogCycleTime parameter.. The files that were generated can be analysed with a spreadsheet program. is stored in the first column of the file. The fBufferUsage output indicates how full the buffer is. The further rows contain the the data of the function block input fLogDta. The time stamp of the log entry. The block is stopped and an error is output if the buffer overflows. The following data set will not be logged until the bBusy output is FALSE again. The individual messages are temporarily stored in the external buffer. The external buffer is used if a buffer address and a buffer size greater than zero are parameterised. If. Warning: • When the mode is set to eCTRL_MODE_ACTIVE the log file is opened and entries are written into the file. The input data is written at equal time intervals in the following lines. The function block makes it possible to work with or without an external buffer. :ARRAY [1. TwinCAT PLC Library: Controller Toolbox . : E_CTRL_MODE. in which a maximum of 10 variables may be recorded. The user must create a buffer larger than 1500 bytes and with the type ARRAY OF BYTES.BECHHOFF 118 FUNCTION_BLOCK FB_CTRL_LOG_DATA (only on a PC system) This function block allows a log file to be created in *. in s.

bBusy eErrorId bError : A TRUE at this output indicates that logging a row is active. : E_CTRL_STATE. (* task cycle time [TIME] *) sFileName nNumberOfRows : STRING. : Becomes TRUE. : INT(1. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the logging block. : A TRUE at this output indicates that the file has successfully been opened.10] OF STRING(25). : A TRUE at this output indicates that the file has successfully been closed. This consists of the following elements: TYPE ST_CTRL_LOG_MAT_FILE_PARAMS: STRUCT tLogCycleTime : TIME := T#0ms. TwinCAT PLC Library: Controller Toolbox . (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.BECHHOFF 119 fLogData eMode : Array containing the values that are to be written into the log file. : Input that specifies the block's operating mode. nLogBuffer_SIZEOF : UDINT. : BOOL.. VAR_OUTPUT VAR_OUTPUT eState bFileOpen bFileClosed fBufferUsage bBusy eErrorId bError END_VAR eState bFileOpen bFileClosed : State of the function block.10). bWriteRowDescription : BOOL := TRUE. arRowDescription : ARRAY [1. : Supplies the error number when the bError output is set. : ST_CTRL_LOG_DATA_PARAMS.. pLogBuffer_ADR : POINTER TO ST_CTRL_MULTIPLE_PWM_OUT_DATA. fBufferUsage : Current fill level of the used buffer in percent. 100] *) : BOOL : E_CTRL_ERRORCODES.. as soon as an error occurs.. : BOOL : BOOL : FLOAT (* Buffer fill level in percent [0 . sMatrixName : STRING. bWriteTimeStamps : BOOL := TRUE.

a double array and a cell array. then new data sets are appended when a file is opened again.mat) format. nLogBuffer_SIZEOF : Size of the LogBuffer. The input data is written at equal time intervals in the columns of the data array. bWriteColumnHeadings : If this parameter is set to TRUE. A time stamp for the relevant entry. can be stored in the first column. in s. e. The name of the cell array is derived from the name of the double array by appending "_Info" to the variable name. The size of the buffer can be optimised with the aid of the fBufferUsage output.csv. arColumnHeadings: Array of strings that contain the column headings. The time interval between the entries is specified in the tLogCycleTime parameter. bAppendData : If this parameter is TRUE. the time stamp of the measurement is written into the first column of the file.g. the buffer's address must be unequal to 0. To be recognised. tTaskCycleTime : Cycle time with which the function block is called. the column headers are written into the first row of the file. bWriteTimeStamps : If this parameter is set to TRUE. The identifiers of the individual lines are stored in the cell array.: d:\Logfile.BECHHOFF 120 END_STRUCT END_TYPE tLogCycleTime : Cycle time with which entries are written into the log file. Two variables are created in the file. for instance. pLogBuffer_ADR : Address of the external LogBuffer. Warning::The parameter set can only be changed when the file is closed (bFileClosed = TRUE)! Otherwise errors can occur during file handling! Development Environment TwinCAT v2. This must be greater than or equal to the TaskCycleTime. in which a maximum of 10 magnitudes may be recorded. sFileName : Name and path of the log file. line-by-line. TwinCAT PLC Library: Controller Toolbox . The buffer must be an ARRAY OF BYTE with at least 256 elements. The recorded magnitudes are recorded. nNumberOfColums: Number of columns written into the file (maximum 10). If. If the block is called in every cycle this corresponds to the task cycle time of the calling task. The user can specify the name used for the double array in the function block's parameter structure. in the double array. and this will delete any content that already exists.lib FUNCTION_BLOCK FB_CTRL_LOG_MAT_FILE (only on a PC system) This function block allows a log file to be created in Matlab 5 (*.8 Target System PC (i386) PLC libraries to include TcControllerToolbox. Otherwise the file is overwritten without query.

The following data set will not be logged until the bBusy output is FALSE again. bBusy eErrorId : BOOL : E_CTRL_ERRORCODES. an internal buffer with the size of 1500 bytes is used. : Input that specifies the block's operating mode. The fBufferUsage output indicates how full the buffer is. The external buffer is used if a buffer address and a buffer size greater than zero are parameterised. The file remains open until the block's mode is set to eCTRL_MODE_PASSIVE. In the absence of an external buffer. Warning: • When the mode is set to eCTRL_MODE_ACTIVE the log file is opened and entries are written into the file..nCTRL_LOGGER_DATA_ARRAY_SIZE] OF FLOAT. VAR_OUTPUT VAR_OUTPUT eState bFileOpen bFileClosed fBufferUsage : E_CTRL_STATE. The function block makes it possible to work with or without an external buffer. fLogData eMode : Array containing the values that are to be written into the log file. If this is not done. The individual messages are temporarily stored in the external buffer. and this buffer is written into the file as quickly as possible. : T_CTRL_LOGGER_DATA. It is essential that the file is closed by switching into eCTRL_MODE_PASSIVE before attempting to analyse the log file. TwinCAT PLC Library: Controller Toolbox . :ARRAY [1.. it is possible that not all the entries will be written into the file. The bBusy output is TRUE when the logging of a line has been started. which will then not be consistent. The user must create a buffer larger than 1500 bytes and with the type ARRAY OF BYTES. then an entry is made in the file every 2s.. • Operating without an external buffer: Operating with an external buffer: VAR_INPUT VAR_INPUT fLogData eMode END_VAR VAR_GLOBAL CONSTANT nCTRL_LOGGER_DATA_ARRAY_SIZE END_VAR TYPE T_CTRL_LOGGER_DATA END_TYPE :UINT := 10.BECHHOFF 121 tLogCycleTime := T\#2s is chosen. : E_CTRL_MODE. The block is stopped and an error is output if the buffer overflows. : BOOL : BOOL : FLOAT (* Buffer fill level in percent [0 . 100] *) nLoggedColumns : DINT. The fBufferUsage output indicates how full the internal buffer is.

arRowDescription : Array of strings that contain the line headings.10] OF STRING(25). : Number of columns written into the file (maximum 10). VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the logging block. tTaskCycleTime : Cycle time with which the function block is called. bBusy eErrorId bError : A TRUE at this output indicates that logging a row is active.10). : ST_CTRL_LOG_MAT_FILE_PARAMS. : INT(1. TwinCAT PLC Library: Controller Toolbox . : Name of the data array. : State of the function block. If the block is called in every cycle this corresponds to the task cycle time of the calling task. bWriteRowDescription : BOOL := TRUE.g. : Supplies the error number when the bError output is set.mat. bWriteTimeStamps : BOOL := TRUE. e. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. END_STRUCT END_TYPE tLogCycleTime : Cycle time with which entries are written into the log file. the time stamp of the measurement is written into the first column of the data array. : A TRUE at this output indicates that the file has successfully been opened. nLogBuffer_SIZEOF : UDINT. This must be greater than or equal to the TaskCycleTime. bWriteTimeStamps: If this parameter is set to TRUE. (* task cycle time [TIME] *) sFileName nNumberOfRows : STRING.. sMatrixName : STRING. : Becomes TRUE. nLoggedColumns : Number of columns written in the file. This consists of the following elements: TYPE ST_CTRL_LOG_MAT_FILE_PARAMS: STRUCT tLogCycleTime : TIME := T#0ms. : A TRUE at this output indicates that the file has successfully been closed.BECHHOFF 122 bError END_VAR eState bFileOpen bFileClosed fBufferUsage : BOOL..: d:\Logfile. arRowDescription : ARRAY [1. as soon as an error occurs. sFileName nNumberOfRows sMatrixName : Name and path of the log file. pLogBuffer_ADR : POINTER TO ST_CTRL_MULTIPLE_PWM_OUT_DATA. : Current fill level of the external buffer as a percentage.

pLogBuffer_ADR : Address of the external LogBuffer. eErrorId bError : E_CTRL_ERRORCODES. := T#2ms. TwinCAT PLC Library: Controller Toolbox . fbCtrlLogMatFile LogBuffer bInit fIn fOut : FB_CTRL_LOG_MAT_FILE. stCtrl_GLOBAL_CycleTimeInterpretation.. The size of the buffer can be optimised with the aid of the fBufferUsage output. : LREAL. : LREAL. : ST_CTRL_LOG_MAT_FILE_PARAMS. : ARRAY[0. nLogBuffer_SIZEOF: Size of the LogBuffer.tLogCycleTime stParams. IF bInit THEN stCtrl_GLOBAL_CycleTimeInterpretation. the buffer's address must be unequal to 0. Warning: The parameter set can only be changed when the file is closed (bFileClosed = TRUE)! Otherwise errors can occur during file handling! Example PROGRAM PRG_LOG_MAT_FILE_TEST_BUFFERED VAR eMode stParams LoggerData : E_CTRL_MODE. The buffer must be an ARRAY OF BYTE with at least 1501 elements. fMaxBufferUsage END_VAR : LREAL. : T_CTRL_LOGGER_DATA. : BOOL. To be recognised.fBaseTime := 0.bInterpretCycleTimeAsTicks := FALSE.tTaskCycleTime := T#2ms. : BOOL := TRUE.2000] OF BYTE. stParams.BECHHOFF 123 bWriteRowDescription: If this parameter is set to TRUE a cell array is created into which the descriptions of the lines are written.

01.nLogBuffer_SIZEOF stParams. (* log only 1000 columns *) IF fbCtrlLogMatFile. eMode bInit END_IF := eCTRL_MODE_ACTIVE. (* creat test data *) fIn := fIn + 0. stParams. stParams.mat'.nLoggedColumns >= 25 THEN eMode := eCTRL_MODE_Passive.arRowDescription[2] stParams.bWriteTimeStamps := TRUE. END_IF (* call logger *) fbCtrlLogMatFile( fLogData := LoggerData. fOut := SIN(fIn).nNumberOfRows stParams. (* copy test data to the Logger-Input *) LoggerData[ 1 ] := fIn. stParams. := ADR( LogBuffer ).sFileName stParams. stParams. LoggerData[ 3 ] := fOut * 2. := 'D:\test. := 'Output 2'. := 'Output 1'. := 'TwinCAT_ControllerToolbox_Log'. := FALSE. LoggerData[ 2 ] := fOut.arRowDescription[1] stParams. TwinCAT PLC Library: Controller Toolbox .bWriteRowDescription := TRUE.sMatrixName := 3.arRowDescription[3] := 'Input'.pLogBuffer_ADR := SIZEOF( LogBuffer ).BECHHOFF 124 stParams.

fMaxBufferUsage). eErrorId => eErrorId.8 Target system type PC (i386) PLC libraries to be linked TcControllerToolbox. bError => bError). stParams :=stParams.lib TwinCAT PLC Library: Controller Toolbox .BECHHOFF 125 eMode := eMode. Development environment TwinCAT v2. (* get max buffer usage *) fMaxBufferUsage := MAX(fbCtrlLogMatFile.fBufferUsage.

: FLOAT.BECHHOFF 126 3.7. TwinCAT PLC Library: Controller Toolbox . VAR_OUTPUT VAR_OUTPUT fOut bInIsUnderThreshold eState : FLOAT. : E_CTRL_STATE. this is indicated by the bInIsUnderThreshold output. If the input signal is within the dead band. Output to controlling equipment FUNCTION_BLOCK FB_CTRL_DEADBAND This block provides a dead band for the input signal. Description of the output behaviour: VAR_INPUT VAR_INPUT fIn END_VAR fIn : Input value. : BOOL.

Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. This consists of the following elements: TYPE ST_CTRL_DEADBAND_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block.lib TcControllerToolbox. : BOOL. tCtrlCycleTime : Cycle time with which the control loop is processed. : ST_CTRL_DEADBAND_PARAMS. see diagram. : A TRUE at this output indicates that the input value is within the dead band.lb6 TcControllerToolbox.BECHHOFF 127 eErrorId bError END_VAR fOut bInIsUnderThreshold eErrorId bError : Output of the function block. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.lbx Development Environment TwinCAT v2. If the block is called in every cycle this corresponds to the task cycle time of the calling task. fThreshold : The function block's dead band.8 TwinCAT v2. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.9 from Build 947 TwinCAT v2. : Becomes TRUE. : Supplies the error number when the bError output is set. as soon as an error occurs. (* task cycle time [TIME] *) fThreshold END_STRUCT END_TYPE : FLOAT. This must be greater than or equal to the TaskCycleTime. tTaskCycleTime : Cycle time with which the function block is called. : E_CTRL_ERRORCODES.9 from Build 956 TwinCAT PLC Library: Controller Toolbox .

: BOOL. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 128 FUNCTION_BLOCK FB_CTRL_LIMITER This block limits an input signal to a parameterisable interval. : A TRUE at this output indicates that the output has reached the upper limit. : BOOL. VAR_OUTPUT VAR_OUTPUT fOut bMinLimit bMaxLimit eErrorId bError END_VAR fOut bMinLimit bMaxLimit : Output of the function block. : FLOAT. : E_CTRL_ERRORCODES. : FLOAT. : BOOL. Description of the output behaviour: VAR_INPUT VAR_INPUT fIn END_VAR fIn : Input value for the function block. : A TRUE at this output indicates that the output has reached the lower limit.

: Upper limit to which the output is restricted. : Cycle time with which the control loop is processed. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. : ST_CTRL_LIMITER_PARAMS.lib TcControllerToolbox.BECHHOFF 129 eErrorId bError : Supplies the error number when the bError output is set. This must be greater than or equal to the TaskCycleTime. : Becomes TRUE.lb6 TcControllerToolbox. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.9 from Build 947 TwinCAT v2. tTaskCycleTime : Cycle time with which the function block is called.lbx Development Environment TwinCAT v2. fMinOutput fMaxOutput : Lower limit to which the output is restricted.9 from Build 956 TwinCAT PLC Library: Controller Toolbox . (* task cycle time [TIME] *) fMinOutput fMaxOutput END_STRUCT END_TYPE tCtrlCycleTime : FLOAT. : FLOAT.8 TwinCAT v2. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. This consists of the following elements: TYPE ST_CTRL_LIMITER_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. as soon as an error occurs. If the block is called in every cycle this corresponds to the task cycle time of the calling task.

This temporal arrangement reduces the maximum power necessary required for the actuators. in this extended block. in addition to the mark-to-space ratio. Both the minimum switch on time and the minimum switch off time can be parameterised.BECHHOFF 130 FUNCTION_BLOCK FB_CTRL_MULTIPLE_PWM_OUT This block creates PWM modulated output signals from a number of input signals in such a way that the temporal relationships between the output signals are arranged so that as few outputs as possible are switched on at any one time. Description of the output behaviour (1): TwinCAT PLC Library: Controller Toolbox .

The programmer can specify the parameterisable times for the individual channels in the ar_stWaitTimesConfig array. Under no circumstances the structures contained in the last-named array may not be changed in the PLC program. The function block writes the output bits into the ar_stPwmOutputs array. The internal data required by the block is stored in the ar_stPwmDataVars array.BECHHOFF 131 Description of the output behaviour (2): The programmer must create the following arrays in the PLC if this function block is to be used: ar_fPwmInput : ARRAY[1.. : E_CTRL_MODE.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_OUTPUTS. TwinCAT PLC Library: Controller Toolbox .. ar_stWaitTimesConfig : ARRAY[1. ar_stPwmDataVars : ARRAY[1... The input magnitudes for the individual channels of the PWM block are written into the ar_fPwmInput array.nNumberOfPwmOutputs] OF FLOAT.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_TIMES. This procedure is also illustrated in the example program listed below. ar_stPwmOutputs : ARRAY[1.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_DATA. VAR_INPUT VAR_INPUT eMode END_VAR eMode : Input that specifies the block's operating mode.

: Number of PWM outputs. pPwmData_ADR nPwmData_SIZEOF END_STRUCT END_TYPE : POINTER TO ST_CTRL_MULTIPLE_PWM_OUT_DATA. (* PLC/PWM cycle time in seconds *) tPWMPeriod : TIME. : BOOL. nPwmTimesConfig_SIZEOF : UINT. : Size of the PWM times array in bytes... : Address of the PWM times array. nPwmOutputArray_SIZEOF : UINT. pPwmOutputArray_ADR : POINTER TO ST_CTRL_MULTIPLE_PWM_OUT_OUTPUTS. : ST_CTRL_PWM_OUT_EXT_PARAMS. : Becomes TRUE. tTaskCycleTime : Cycle time with which the function block is called. pPwmInputArray_ADR : POINTER TO FLOAT := 0.BECHHOFF 132 VAR_OUTPUT VAR_OUTPUT eState bError eErrorId END_VAR eState eErrorId bError : State of the function block. : E_CTRL_ERRORCODES. (* controller cycle time in seconds *) nNumberOfPwmOutputs : USINT. nPwmInputArray_SIZEOF : UINT. : E_CTRL_STATE. : Size of the PWM input array in bytes.n] : Address of the PWM input array. : Address of the internal PWM data array. This consists of the following elements: TYPE ST_CTRL_MULTIPLE_PWM_OUT_PARAMS : STRUCT tTaskCycleTime : TIME. pPwmTimesConfig_ADR : POINTER TO ST_CTRL_MULTIPLE_PWM_OUT_TIMES. tPWMPeriod nNumberOfPwmOutputs pPwmInputArray_ADR nPwmInputArray_SIZEOF pPwmTimesConfig_ADR nPwmTimesConfig_SIZEOF pPwmData_ADR : Period of the PWM signal. [1. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PWM element. TwinCAT PLC Library: Controller Toolbox . as soon as an error occurs. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : UINT. : Supplies the error number when the bError output is set.

END_STRUCT END_TYPE bPwmOutBitPos bPwmOutBitNeg : PWM signal.. : PWM signal. ar_stWaitTimesConfig : ARRAY[1. This must not be written to. (* min. : A TRUE at this output indicates that the waiting time between the switching actions of the output signals is active.. END_VAR VAR ar_fPwmInput : ARRAY[1. END_STRUCT END_TYPE Example: PROGRAM PRG_MULTIPLE_PWM_OUT_TEST VAR CONSTANT nNumberOfPwmOutputs : USINT := 3.nNumberOfPwmOutputs] OF FLOAT.0. (* min.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_OUTPUTS.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_DATA. bPwmOutBitNeg : BOOL. : TIME.. when fPwmInput < 0.. : Waiting time between the switching actions between a positive and negative output signal. This output can be used to hold an I-component that may be present in the prior controller constant during this time. when fPwmInput > 0. : Minimum switch-off time of the PWM output. TwinCAT PLC Library: Controller Toolbox . switch off time *) : TIME. bWaitTimeActive TYPE ST_CTRL_MULTIPLE_PWM_OUT_DATA : STRUCT Internal structure. (* min. TYPE ST_CTRL_MULTIPLE_PWM_OUT_TIMES : STRUCT tMinOnTime tMinOffTime tMinWaitTime END_STRUCT END_TYPE tMinOnTime tMinOffTime tMinWaitTime : Minimum switch-on time of the PWM output. bWaitTimeActive : BOOL. ar_stPwmOutputs : ARRAY[1. waiting time when switching from pos to neg or vv*) TYPE ST_CTRL_MULTIPLE_PWM_OUT_OUTPUTS : STRUCT bPwmOutBitPos : BOOL.nNumberOfPwmOutputs] OF ST_CTRL_MULTIPLE_PWM_OUT_TIMES.BECHHOFF 133 pPwmData_SIZEOF : Size of the internal PWM data array in bytes.0. ar_stPwmDataVars : ARRAY[1. switch on time *) : TIME.

pPwmData_ADR stParams. : FLOAT.nPwmOutputArray_SIZEOF := SIZEOF( ar_stPwmOutputs ). : FLOAT.BECHHOFF 134 eMode stParams eErrorId bError fbPwm_Out bInit fIn1 fIn2 fIn3 bOut1_pos bOut1_neg bOut2_pos bOut2_neg bOut3_pos bOut3_neg END_VAR : E_CTRL_MODE. := ADR( ar_stPwmDataVars ). IF bInit THEN (* set values in the local arrays *) ar_stWaitTimesConfig[1].tMinOffTime := T#300ms.pPwmInputArray_ADR := ADR( ar_fPwmInput ).nNumberOfPwmOutputs := nNumberOfPwmOutputs.5s. : FB_CTRL_MULTIPLE_PWM_OUT. : E_CTRL_ERRORCODES. : ST_CTRL_MULTIPLE_PWM_OUT_PARAMS.tMinOnTime := T#400ms. TwinCAT PLC Library: Controller Toolbox .tMinOffTime := T#200ms. : BOOL := TRUE. bInit := FALSE. stParams. ar_stWaitTimesConfig[1]. ar_fPwmInput[3] := fIn3.5s. : BOOL.5s. stParams. : BOOL.tMinWaitTime := T#5.nPwmInputArray_SIZEOF := SIZEOF( ar_fPwmInput ). : BOOL. END_IF (* set the addresses *) stParams.pPwmTimesConfig_ADR := ADR( ar_stWaitTimesConfig).tMinOnTime := T#400ms.tMinWaitTime := T#3. stParams.pPwmOutputArray_ADR := ADR( ar_stPwmOutputs ). : BOOL. : BOOL. stParams.tMinOffTime := T#250ms. (* set values in the parameter struct *) stParams. : BOOL. stParams. fbPwm_Out( eMode := eMode. (* set the ctrl-mode *) eMode := eCTRL_MODE_ACTIVE. stParams.tMinOnTime := T#500ms. ar_stWaitTimesConfig[2].tTaskCycleTime := T#2ms. ar_stWaitTimesConfig[3]. : BOOL. ar_fPwmInput[2] := fIn2.tPWMPeriod := T#2s.nPwmData_SIZEOF ar_fPwmInput[1] := fIn1. := SIZEOF( ar_stPwmDataVars ). : FLOAT. ar_stWaitTimesConfig[2].nPwmTimesConfig_SIZEOF := SIZEOF( ar_stWaitTimesConfig).tMinWaitTime := T#4. ar_stWaitTimesConfig[3]. ar_stWaitTimesConfig[3]. stParams. ar_stWaitTimesConfig[2]. stParams. ar_stWaitTimesConfig[1].

bPwmOutBitNeg. bOut2_pos := ar_stPwmOutputs[2]. TwinCAT PLC Library: Controller Toolbox .lib TcControllerToolbox.lb6 TcControllerToolbox. If this parameter is FALSE. bError => bError. These two signals therefore make it possible to control two different actuators. the pulse width modulated signal is made available at the bPwmOutBitPos output.BECHHOFF 135 stParams := stParams. The mark-to-space ratio is specified at the input in %.lbx FUNCTION_BLOCK FB_CTRL_PWM_OUT This block creates a PWM modulated signal on the basis of the input signal. is effective even in the current PWM cycle. then a new input value is only adopted at the start of a new PWM cycle.bPwmOutBitPos. the range from -100% to 100% is available. in other words. bOut3_pos := ar_stPwmOutputs[3]. Description of the output behaviour: This block creates a PWM signal at the outputs with a mark-to-space ratio corresponding to the fPwmInput input.8 TwinCAT v2.bPwmOutBitNeg. bOut1_neg := ar_stPwmOutputs[1]. the signal is output at bPwmOutBitNeg.bPwmOutBitPos. depending on the arithmetic sign. bOut3_neg := ar_stPwmOutputs[3]. eErrorId => eErrorId). If the specified mark-to-space ratio is negative.bPwmOutBitNeg. If a positive value is specified. bOut2_neg := ar_stPwmOutputs[2]. The new input value.bPwmOutBitPos.9 from Build 947 TwinCAT v2.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. bOut1_pos := ar_stPwmOutputs[1]. Development Environment TwinCAT v2. If the bInstantPWMUpdate is set to TRUE it is possible to adopt a new input value instantly.

. : State of the function block. TwinCAT PLC Library: Controller Toolbox . : Input that specifies the block's operating mode.0] *) eMode END_VAR fPwmInput eMode : Input value. : BOOL. as soon as an error occurs. : ST_CTRL_PWM_OUT_PARAMS. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the PWM element. when fPwmInput > 0. (* PWM output bit *) (* PWM output bit *) : E_CTRL_STATE. bInstantPWMUpdate : If this flag is TRUE. tPWMPeriod : Period of the PWM signal. : BOOL.BECHHOFF 136 VAR_INPUT VAR_INPUT fPwmInput [-100. : Supplies the error number when the bError output is set.0. (* controller output = PMW input VAR_OUTPUT VAR_OUTPUT bPwmOutBitPos bPwmOutBitNeg eState bError eErrorId END_VAR bPwmOutBitPos bPwmOutBitNeg eState eErrorId bError : PWM signal. : Becomes TRUE. when fPwmInput < 0. If the block is called in every cycle this corresponds to the task cycle time of the calling task. : E_CTRL_ERRORCODES. (* PWM period duration [TIME] *) bInstantPWMUpdate END_STRUCT END_TYPE : BOOL. 100. tTaskCycleTime : Cycle time with which the function block is called. even in the present PWM cycle. : PWM signal.0 . then a new input value is immediately adopted. This consists of the following elements: TYPE ST_CTRL_PWM_OUT_PARAMS: STRUCT tTaskCycleTime : TIME (* task cycle time [TIME] *) tPWMPeriod : TIME. : E_CTRL_MODE. : BOOL.0. : FLOAT..

BECHHOFF

137

Development Environment TwinCAT v2.8 TwinCAT v2.9 from Build 947 TwinCAT v2.9 from Build 956

Target System PC (i386) BC BX

PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.lb6 TcControllerToolbox.lbx

FUNCTION_BLOCK FB_CTRL_PWM_OUT_EXT

This block creates a PWM modulated signal on the basis of the input signal. Both the minimum switch on time and the minimum switch off time can be parameterised, in addition to the mark-to-space ratio, in this extended block.

Description of the output behaviour (1):

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

138

Description of the output behaviour (2):

VAR_INPUT
VAR_INPUT fPwmInput [-100.0 ... 100.0] *) eMode END_VAR
fPwmInput eMode : Input value for the function block. : Input that specifies the block's operating mode.

: FLOAT; : E_CTRL_MODE;

(* NEW: controller output = PMW input

VAR_OUTPUT
VAR_OUTPUT bPwmOutBitPos bPwmOutBitNeg eState bError eErrorId END_VAR : BOOL; : BOOL; : E_CTRL_STATE; : BOOL; : E_CTRL_ERRORCODES; (* PWM output bit *) (* PWM output bit *)

TwinCAT PLC Library: Controller Toolbox

BECHHOFF

139

bPwmOutBitPos bPwmOutBitNeg

: PWM signal, when fPwmInput > 0.0. : PWM signal, when fPwmInput < 0.0.

bWaitTimeActive : A TRUE at this output indicates that the waiting time between the switching actions of the output signals is active. This output can be used to hold an I component that may be present in the prior controller constant during this time. eState eErrorId bError : State of the function block. : Supplies the error number when the bError output is set. : Becomes TRUE, as soon as an error occurs.

VAR_IN_OUT
VAR_IN_OUT stParams END_VAR
stParams : Parameter structure of the PWM element. This consists of the following elements: TYPE ST_CTRL_PWM_OUT_EXT_PARAMS : STRUCT tTaskCycleTime : TIME; (* PLC/PWM cycle time in seconds *) tPWMPeriod : TIME; (* controller cycle time in seconds *) tMinOnTime : TIME; (* min. switch on time *) tMinOffTime : TIME; (* min. switch off time *) tMinWaitTime : TIME; (* min. waiting time when switching from pos to neg or vv*) END_STRUCT END_TYPE tTaskCycleTime : Cycle time with which the function block is called. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tPWMPeriod tMinOnTime tMinOffTime tMinWaitTime : Period of the PWM signal. : Minimum time switched on : Minimum time switched off. : Waiting time between the switching actions between a positive and negative output signal. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.lb6 TcControllerToolbox.lbx

: ST_CTRL_PWM_OUT_EXT_PARAMS;

Development Environment TwinCAT v2.8 TwinCAT v2.9 from Build 947 TwinCAT v2.9 from Build 956

TwinCAT PLC Library: Controller Toolbox

(* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : BOOL. : ST_CTRL_SCALE_PARAMS. VAR_OUTPUT VAR_OUTPUT fOut eErrorId bError END_VAR fOut eErrorId bError : Scaled output value. : FLOAT. tCtrlCycleTime : Cycle time with which the control loop is processed. : Supplies the error number when the bError output is set. This consists of the following elements: TYPE ST_CTRL_SCALE_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. VAR_INPUT VAR_INPUT fIn END_VAR fIn : Input value for the function block. : FLOAT. The function block uses this input variable to calculate internally whether the state and the output variables TwinCAT PLC Library: Controller Toolbox . VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. This must be greater than or equal to the TaskCycleTime. : FLOAT. : E_CTRL_ERRORCODES. : FLOAT. as soon as an error occurs. : FLOAT. (* task cycle time [TIME] *) fInMin fInMax fOutMin fOutMax END_STRUCT END_TYPE : FLOAT. : Becomes TRUE.BECHHOFF 140 FUNCTION_BLOCK FB_CTRL_SCALE This function block makes it possible to adjust the signal in a linear manner between two value ranges.

9 from Build 947 TwinCAT v2. fInMin fInMax fOutMin fOutMax : Minimum of the input value. : Maximum of the input value. If the block is called in every cycle this corresponds to the task cycle time of the calling task.lbx Development Environment TwinCAT v2. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lib TcControllerToolbox.8 TwinCAT v2. : Minimum of the output value.9 from Build 956 TwinCAT PLC Library: Controller Toolbox . : Maximum of the output value.lb6 TcControllerToolbox.BECHHOFF 141 have to be updated in the current cycle. tTaskCycleTime : Cycle time with which the function block is called.

: BOOL. : FLOAT. TwinCAT PLC Library: Controller Toolbox . fCtrlOutMax ] *) bUpperLimitSwitch bLowerLimitSwitch fManSyncValue bSync eMode END_VAR : BOOL. (* controller output = SERVO_MOTOR_OUT input [ fCtrlOutMin ..BECHHOFF 142 FUNCTION_BLOCK FB_CTRL_SERVO_MOTOR_OUT This function block generates pulses with which a servomotor can be driven to a defined position. : BOOL. Behaviour of the output: VAR_INPUT VAR_INPUT fIn : FLOAT. : E_CTRL_MODE..

Warning: Once the synchronisation process is completed. : State of the function block. which must agree with the actual position.. fManSyncValue : Input with which the internal state of the current motor setting can be adjusted. 0%) to open (e... This consists of the following elements: TYPE ST_CTRL_SERVO_MOTOR_OUT_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. fCtrlOutMax ] (controller output). fCtrlOutMax ] in which the motor is currently positioned. : Becomes TRUE. bLowerLimitSwitch : Limit switch: TRUE if the lower stop has been reached.. (* PWM output bit *) : FLOAT. bSync : A rising edge at this input sets the internal motor position.. or whose value is adopted in manual mode. "eCTRL_STATE_ACTIVE" mode is automatically activated! VAR_OUTPUT VAR_OUTPUT bOutBitPos bOutBitNeg fActualState eState eErrorId bError END_VAR bOutBitPos bOutBitNeg fActualState eState eErrorId bError : Output required to drive the motor in a positive direction. (* time to move from closed (e. (* Actual state of the motor [ 0% .g.. TwinCAT PLC Library: Controller Toolbox . eMode Special feature: : Input that specifies the block's operating mode. : BOOL. The block is then synchronised with this valve position. : Current motor setting over the range [ fCtrlOutMin . : E_CTRL_ERRORCODES. as soon as an error occurs. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. the output for closing the valve is set until the valve is closed safely. bUpperLimitSwitch : Limit switch: TRUE if the upper stop has been reached. this block has the mode "eCTRL_MODE_SYNC_MOVEMENT". 100%)*) : ST_CTRL_SERVO_MOTOR_OUT_PARAMS. : BOOL. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. 100%] *) : E_CTRL_STATE.g. : Supplies the error number when the bError output is set. (* task cycle time [TIME] *) tMovingTime : TIME. to the value fManSyncValue. (* PWM output bit *) : BOOL.BECHHOFF 143 fIn : Control value of the controller over the range [ fCtrlOutMin . : Output required to drive the motor in a negative direction. For synchronisation with the current valve position. In this mode.

: BOOL. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. tAdditionalMovingTimeAtLimits : Supplementary signal extension.lb6 TcControllerToolbox. : FLOAT := 0. (* output signal extension time *) tAdditionalMoveTimeAtLimits : TIME.8 TwinCAT v2. output to reliably reach the limits when the actuator is to be driven to +/-100%.BECHHOFF 144 tSignalExtension : TIME. : Control value for which the valve will be driven to 0%. (* wait time between pos and neg output pulses and vice versa *) tMinimumPulseTime bMoveOnLimitSwitch fCtrlOutMax fCtrlOutMin END_STRUCT END_TYPE : TIME.lbx TwinCAT PLC Library: Controller Toolbox . fCtrlOutMax fCtrlOutMin Development Environment TwinCAT v2.0. then when the control value is either fCtrlOutMin or fCtrlOutMax a signal will continue to be output until the corresponding limit switch is reached. : Signal extension by which each output pulse is extended in order to tSignalExtension compensate for the dead time. : FLOAT := 100. : Minimum length of an output pulse. tMovingTime : The time required to move the actuator from one stop to the other. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tMinWaitTimeBetweenDirectionChange tMinimumPulseTime : Minimum waiting time between positive and negative output pulses. (* add these moving time to ensure that the limits are reached*) tMinWaitTimeBetweenDirectionChange: TIME.9 from Build 947 TwinCAT v2. tTaskCycleTime : Cycle time with which the function block is called. (* minimum output pulse length *) (* controller output to move to the max limit *) (* controller output to move to the min limit *) tCtrlCycleTime : Cycle time with which the control loop is processed.9 from Build 956 : Control value for which the valve will be driven to 100%. bMoveOnLimitSwitch : If TRUE. This must be greater than or equal to the TaskCycleTime.lib TcControllerToolbox.0. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. Only effective if bMoveOnLimitSwitch is FALSE.

The parameters bDisablePosOut and bDisableNegOut can be used to deactivate the positive or negative output ? Heating operation only in winter. cooling operation only in summer. Description of the output behaviour: TwinCAT PLC Library: Controller Toolbox . The bInvertNegOutput parameter allows the native output to be inverted.BECHHOFF 145 FUNCTION_BLOCK FB_CTRL_SPLITRANGE This function block divides an input signal into positive and negative components.

: TRUE indicates that fIn > 0. : FLOAT. stParams : Parameter structure of the function block. as soon as an error occurs. VAR_IN_OUT VAR_IN_OUT END_VAR stParams : ST_CTRL_SPLITRANGE_PARAMS. : BOOL. : BOOL.0. : Negative part of fIn. VAR_OUTPUT VAR_OUTPUT fOutPos fOutNeg bOutPosIsActive : FLOAT.0. eErrorId bError END_VAR fOutPos fOutNeg bOutPosIsActive bOutNegIsActive eErrorId bError : E_CTRL_ERRORCODES. : BOOL. bOutNegIsActive : BOOL. This consists of the following elements: TYPE ST_CTRL_SPLITRANGE_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms. : TRUE indicates that fIn < 0. (* task cycle time [TIME] *) bInvertNegOutput bDisablePosOut bDisableNegOut END_STRUCT END_TYPE tCtrlCycleTime : BOOL. : Becomes TRUE. : FLOAT. : Cycle time with which the control loop is processed. : BOOL. The function block uses this input variable to calculate internally whether the state and TwinCAT PLC Library: Controller Toolbox . This must be greater than or equal to the TaskCycleTime. : Supplies the error number when the bError output is set. : Positive part of fIn.BECHHOFF 146 VAR_INPUT VAR_INPUT fIn END_VAR fIn : Input value for the function block. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms.

Development environment TwinCAT v2.lbx TwinCAT PLC Library: Controller Toolbox . bInvertNegOutput : fOutNeg is inverted when this parameter is TRUE.0.lb6 TcControllerToolbox. and always remains 0.9. build 947 onwards TwinCAT v2.lib TcControllerToolbox.BECHHOFF 147 the output variables have to be updated in the current cycle.9. If the block is called in every cycle this corresponds to the task cycle time of the calling task. build 956 onwards Target system type PC (i386) BC BX PLC libraries to be linked TcControllerToolbox. bDisableNegOut : The fOutNeg output is deactivated. tTaskCycleTime : Cycle time with which the function block is called.8 TwinCAT v2.0. and always remains 0. bDisablePosOut : The fOutPos output is deactivated.

: E_CTRL_MODE. : BOOL. TwinCAT PLC Library: Controller Toolbox . (* controller output = STEPPING_MOTOR_OUT input [ fCtrlOutMin . : BOOL. : FLOAT. fCtrlOutMax ] *) bUpperLimitSwitch bLowerLimitSwitch fManSyncValue bSync eMode END_VAR : BOOL.. Behaviour of the output: VAR_INPUT VAR_INPUT fIn : FLOAT..BECHHOFF 148 FUNCTION_BLOCK FB_CTRL_STEPPING_MOTOR_OUT This function block generates a control value for a stepper motor.

TwinCAT PLC Library: Controller Toolbox . or whose value is adopted in : A rising edge at this input will set the internal step counter to the step specified by fbManSyncValue. the output for closing the valve is set until the valve is closed safely. (* controller cycle time [TIME] *) tTaskCycleTime : TIME := T#0ms. : E_CTRL_ERRORCODES. : BOOL. : State of the function block. : Actual step at which the motor is positioned. (* Actual state of the motor [ 0 . : Output required to drive the motor in a negative direction. (* output signal to move to the minimum*) : DINT. this block has the mode "eCTRL_MODE_SYNC_MOVEMENT". : BOOL. For synchronisation with the current valve position. : Input that specifies the block's operating mode. : Becomes TRUE.. Warning: Once the synchronisation process is completed. The block is then synchronised with this valve position. nMaxMovingPulses ] : E_CTRL_STATE. bUpperLimitSwitch : Limit switch: TRUE if the upper stop has been reached. fManSyncValue manual mode. : Supplies the error number when the bError output is set. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. bSync eMode Special feature: : Input with which the internal state of the motor setting can be adjusted. (* output signal to move to the maximum *) : BOOL.. as soon as an error occurs. bLowerLimitSwitch : Limit switch: TRUE if the lower stop has been reached. In this mode. "eCTRL_STATE_ACTIVE" mode is automatically activated! VAR_OUTPUT VAR_OUTPUT bOutBitPos bOutBitNeg nActualStep *) eState eErrorId bError END_VAR bOutBitPos bOutBitNeg nActualStep eState eErrorId bError : Output required to drive the motor in a positive direction. (* task cycle time [TIME] *) : ST_CTRL_STEPPING_MOTOR_OUT_PARAMS. This consists of the following elements: TYPE ST_CTRL_STEPPING_MOTOR_OUT_PARAMS: STRUCT tCtrlCycleTime : TIME := T#0ms.BECHHOFF 149 fIn : Controller's control value (controller output).

lbx TwinCAT PLC Library: Controller Toolbox . fCtrlOutMax fCtrlOutMin Development Environment TwinCAT v2. This must be greater than or equal to the TaskCycleTime. (* add these pulses to ensure that the limits are reached*) : BOOL.0.lib TcControllerToolbox. *) : BOOL. then pulses are output when the control value is either 0% or 100% until the limit switch is reached. tOnTime tOffTime nMaxMovingPulses :Pulse length.0. This will result in braking. (* controller output to move to the min limit *) : Cycle time with which the control loop is processed. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. (* controller output to move to the max limit *) : FLOAT := 0. tTaskCycleTime : Cycle time with which the function block is called. (* if TRUE then a ouput is on when no pulses are generated *) : DINT.9 from Build 947 TwinCAT v2. nAdditionalPulsesAtLimits bMoveOnLimitSwitch fCtrlOutMax fCtrlOutMin END_STRUCT END_TYPE tCtrlCycleTime : FLOAT := 100.8 TwinCAT v2. (* necessary pulses to move from closed to open or v. then an output remains set when the drive is stationary. : Number of supplementary pulses that are output to reliably ensure that limits are bMoveOnLimitSwitch : If this is TRUE. (* delay between two impulses *) : DINT. nAdditionalPulsesAtLimits reached. (* impulse length *) : TIME. : Number of pulses required to travel from one limit to the other. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. : Control value for which the valve will be driven to 0%.9 from Build 956 : Control value for which the valve will be driven to 100%.BECHHOFF 150 tOnTime tOffTime nMaxMovingPulses bHoldWithOuputOn : TIME. bHoldWithOutputsOn : If this parameter is set to TRUE. If the block is called in every cycle this corresponds to the task cycle time of the calling task. v.lb6 TcControllerToolbox. : Pause length.

after which a new movement begins with a new set of parameters. Setpoint generation FUNCTION_BLOCK FB_CTRL_3PHASE_SETPOINT_GENERATOR(only on a PC system) This function block represents a 3-phase set value generator. alternatively.8. It is generally recommended that end position monitoring is included after the set value generator.BECHHOFF 151 3. Description: This function block generates a 3-phase set value profile in which the acceleration has a rectangular curve. : LREAL. and any subsequent task that may be pending is deleted. : BOOL. : BOOL. the current movement may first be completed. Braking is carried out using the deceleration specified in the current set of parameters. provided the generator is not already active and that the bStop and bReset inputs are FALSE. 1. If a positioning process is under way it is interrupted immediately. It is possible to specify a new parameter set while the generator is active. bReset TwinCAT PLC Library: Controller Toolbox . Warning 2. See the example. (eNewPosType := eCTRL_NEW_PARAMETER_TYPE_NotInstant). Specifying a new set of parameters may mean that the previous end position is exceeded. VAR_INPUT VAR_INPUT bStart bStop bReset fOverride END_VAR bStart bStop : Generation of the set values begins when a positive edge appears at the bStart input. it may become effective immediately (eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_Instant). : Resets the set value generator. : Generation of the set values is stopped by a positive edge at the bStop input. the : BOOL. Depending upon what type of parameter set is specified.

: Set position : Set velocity : Set acceleration : Direction of movement [-1. : BOOL. 100.BECHHOFF 152 fSetVelo and fSetAcc outputs are set to 0. 0.0. : This output becomes TRUE when the movement has been completed and the destination position TwinCAT PLC Library: Controller Toolbox . fStartPos := 0. : BOOL. fOverride : The set velocity can be scaled through an override in the range [ 0 .0.0. fTargetVelo := 0. fVelocity := 0. (* generated setpoint velocity *) : LREAL. bGeneratorActive bCommandBuffered : When this output is TRUE it indicates that the buffer store contains at a transport instruction that will begin when the current instruction has completed.0. fTargetPos := 0. Instead.0.0 % ]. eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant. If the override is 100%. and all internal states are cleared. the set position is set to the start position. bDone has been reached. The override implemented here does not scale the current runtime table when the override is changed. fStartVelo := 0. tCtrlCycleTime := T#0s. : BOOL.0. fDeceleration := 0.. : LREAL. (* generated setpoint position *) : LREAL.1%. (* generated setpoint acceleration *) (* generated direction *) bCommandBuffered bDone bCommandAborted : BOOL. an internal restart instruction is generated having a different set velocity.0. eErrorId bError END_VAR fSetPos fSetVelo fSetAcc nSetDirection : E_CTRL_ERRORCODES. 1]. then the generated profile uses the set velocity as specified in the parameter set.0. tTaskCycleTime := T#0s. An instruction in the buffer store is cleared if the following special case is specified as parameter set: fAcceleration := 0. VAR_OUTPUT VAR_OUTPUT fSetPos fSetVelo fSetAcc nSetDirection : INT. 1 --> movement direction is positive 0 --> generator is inactive -1 --> movement direction is negative : Indicates whether the generator is active. The override has a resolution of 0.

: LREAL. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. tTaskCycleTime : Cycle time with which the function block is called. (* task cycle time [TIME] *) tCtrlCycleTime : TIME. : Acceleration in units / second2. : fAcceleration fDeceleration eNewParameterType TYPE E_CTRL_NEW_PARAMETER_TYPE : ( eCTRL_NEW_PARAMETER_TYPE_NotInstant := 0. VAR_IN_OUT VAR_IN_OUT stParams : ST_CTRL_3PHASE_SETPOINT_GENERATOR_PARAMS.BECHHOFF 153 bCommandAborted : This output becomes TRUE when the current movement is interrupted. (* controller cycle time [TIME] *) fStartPos fStartVelo fVelocity fTargetPos fTargetVelo fAcceleration fDeceleration : LREAL. END_VAR stParams : Parameter structure of the set value generator. Warning:The target velocity is retained when the destination position has been reached (the bDone flag is set). TwinCAT PLC Library: Controller Toolbox .0 *) eNewParameterType : E_CTRL_NEW_PARAMETER_TYPE. This can be caused. (* >= 0. but after this point the position is no longer calculated (constant position at velocity ? 0. : LREAL. through a rising edge at the bStop input. : Becomes TRUE as soon as an error situation occurs. fStartPos fStartVelo fVelocity fTargetPos fTargetVelo : Starting position for the movement profile.0 *) : LREAL.0 *) : LREAL. This must be greater than or equal to the TaskCycleTime. : Velocity in units/second. END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. This consists of the following elements: TYPE ST_CTRL_RAMP_GENERATOR_PARAMS : STRUCT tTaskCycleTime : TIME. eCTRL_NEW_PARAMETER_TYPE_Instant := 1 ). : Destination position for the movement profile. (* > 0. (* > 0. eErrorId bError : Supplies the error number when the bError output is set. If the block is called in every task cycle this corresponds to the task cycle time of the calling task.0). : LREAL. for instance. : Deceleration in units / second2. : Starting velocity for the movement profile. : Target velocity of the movement profile. : LREAL.

A TRUE at the bCommandBuffered output indicates that the buffer store contains a non-instantaneous restart instruction. this set is adopted immediately.0.0.0. stParams.fStartPos := -500.0.0. the new set is not adopted immediately.fDeceleration := 2000. fOverride := 100. Positioning examples Positioning example 1: stParams.fTargetVelo := 0.fStartVelo := 0. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 154 END_TYPE eCTRL_NEW_PARAMETER_TYPE_Instant: When a restart instruction is issued with a new parameter set. after which positioning to the new destination is carried out with the new parameters. eCTRL_NEW_PARAMETER_TYPE_NotInstant: When a restart instruction is issued with a new parameter set.fVelocity := 1000. non-instantaneous parameter set. stParams.fAcceleration := 1000.0. In other words the current movement is first executed to completion. stParams.0. stParams.fTargetPos := 2500. An instruction that has already been stored can be overwritten or deleted by a further new. and the old parameters are discarded.0. stParams. In other words a transition from the current state of movement to the data represented by the new parameter set is calculated. stParams.

fTargetVelo := 0.fVelocity := 1000.fAcceleration := 1000. stParams. stParams.0.0.0. stParams.0.fDeceleration := 2000. stParams.fStartVelo := 0. stParams. Positioning example 3: stParams. TwinCAT PLC Library: Controller Toolbox . stParams.BECHHOFF 155 Positioning example 2: stParams. stParams.fVelocity := 1300.0. fOverride := 100.fAcceleration := 1000.0.0. stParams. stParams.fStartVelo := 0.0.0.0.0.fTargetVelo := 0. stParams.0. stParams.0.fStartPos := 1000. fOverride := 100.0.fAcceleration := 1000.0.fDeceleration := 2000. Parameter change if fSetPos > 1000. stParams. stParams.fStartPos := -500.0. eNewPosType := eCTRL_NEW_POS_TYPE_NotInstant stParams. stParams.fVelocity := 1000.0. stParams.0.fStartVelo := 0.fTargetPos := 0.fTargetVelo := 0.fTargetPos := -2500.0.0.0.0. stParams.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant.0.0. fOverride := 100.fDeceleration := 2000. stParams.fTargetPos := 2500. stParams.

fStartPos := -500. TwinCAT PLC Library: Controller Toolbox . stParams.0.0.fVelocity := 1300. stParams.0.fDeceleration := 2000.0.fAcceleration := 1000. fOverride := 100.0.fVelocity := 1000. stParams. stParams.0.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant.0.fTargetPos := 2500. stParams.fTargetPos := 0.0. stParams.0.fDeceleration := 2000.fAcceleration := 1000. stParams.fStartVelo := 0.0.fTargetVelo := 0.0.fTargetVelo := 0.fStartVelo := 0. stParams.0. Parameter change if fSetPos > 1000. eNewPosType := eCTRL_NEW_POS_TYPE_Instant stParams. fOverride := 100.0. stParams. stParams.0.0.BECHHOFF 156 Positioning example 4: stParams. stParams. stParams.0.

stParams.0.fTargetPos := 200. stParams.0.fTargetVelo := 0. stParams. Restart at point 4: stParams.fStartPos := -100. stParams.fTargetVelo := 150. stParams.0. stParams. stParams. stParams. stParams.0.0.0. stParams. Restart at point 3: stParams.fTargetPos := 200. stParams.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_Instant Restart at point 2: stParams.0.0.0.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant. TwinCAT PLC Library: Controller Toolbox .fVelocity := 250.fStartVelo := 0.fAcceleration := 500.fTargetPos := 400.eNewParameterType := eCTRL_NEW_PARAMETER_TYPE_NotInstant.BECHHOFF 157 Positioning example 5: Start at point 1: stParams.0.fDeceleration := 400.fTargetPos := 600.0.

0. stParams.fAcceleration := 1_000. Example: stParams.fStartPos := 0. END_IF It can clearly be seen in the following scope trace that the original destination position of 1000 mm is exceeded.0.fTargetPos := 400.fTargetPos := 1000.eNewPosType := eCTRL_NEW_POS_TYPE_Instant.0. TwinCAT PLC Library: Controller Toolbox .0.0 THEN stParams.0.fAcceleration := 1000.0.0.fDeceleration := 500. stParams. the reason being that the new parameter set had a reduced deceleration. stParams.BECHHOFF 158 Warning: If a new parameter set of type "eCTRL_NEW_POS_TYPE_Instant" in which the deceleration is reduced is given to the block it is possible that the old destination position will be exceeded.fDeceleration := 1000.0.0. stParams. stParams. stParams.fVelocity := 500. IF fSetPos > 800.fVelocity := 500. stParams. stParams.

taking the form of a ramp as it moves from the current value to the presently active final value. Behaviour of the output value: TwinCAT PLC Library: Controller Toolbox .BECHHOFF 159 Development environment TwinCAT v2. The starting value is adopted when a rising edge appears at bEnable.e. As long as the signal bEnable remains TRUE the final value can be changed. calculation of the ramp then begins. The slope of the ramp (i. Description: This function block generates a ramp connecting the starting value fStart and the final value fTarget. and the output value changes.lib FUNCTION_BLOCK FB_CTRL_RAMP_GENERATOR The function block provides a parameterisable ramp generator.8 Target system type PC (i386) PLC libraries to be linked TcControllerToolbox. the velocity) is given in units/s by means of the fVeloPos and fVeloNeg parameters.

: E_CTRL_STATE. fTarget END_VAR bEnable fStart fTarget : Start of ramp generation. TwinCAT PLC Library: Controller Toolbox . : BOOL. : FLOAT. eState eErrorId bError : State of the function block. : Becomes TRUE as soon as an error situation occurs. : Finishing value for the ramp. bValueReached : This output indicates by going TRUE that the output fOut has reached the value fTarget.BECHHOFF 160 VAR_INPUT VAR_INPUT bEnable : BOOL. : Supplies the error number when the bError output is set. fStart : FLOAT. : E_CTRL_ERRORCODES. (* target value *) VAR_OUTPUT VAR_OUTPUT fOut bValueReached eState eErrorId bError END_VAR fOut : Output of the ramp generator. : Starting value for the ramp. : BOOL. : FLOAT.

9 from Build 956 FUNCTION_BLOCK FB_CTRL_RAMP_GENERATOR_EXT This function block represents a parameterisable ramp generator. (* velocity ramp by time range: > 0. (* controller cycle time [TIME] *) fVeloPos fVeloNeg END_STRUCT END_TYPE : FLOAT. In contrast to FB_CTRL_RAMP_GENERATOR it supports the E_CTRL_MODEs. : Velocity in unit/s. (* RAMP_Generator parameter struct *) END_VAR stParams : Parameter structure of the ramp generator.lib TcControllerToolbox. This consists of the following elements: TYPE ST_CTRL_RAMP_GENERATOR_PARAMS : STRUCT tTaskCycleTime : TIME. If the block is called in every task cycle this corresponds to the task cycle time of the calling task. Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox.lbx Development Environment TwinCAT v2. (* task cycle time [TIME] *) tCtrlCycleTime : TIME. (* velocity ramp by time range: > 0. with which the output is changed from a higher value to a lower one. fVeloPos fVeloNeg : Velocity in unit/s.BECHHOFF 161 VAR_IN_OUT VAR_IN_OUT stParams : ST_CTRL_RAMP_GENERATOR_PARAMS. TwinCAT PLC Library: Controller Toolbox .lb6 TcControllerToolbox.8 TwinCAT v2.0 *) tCtrlCycleTime : Cycle time with which the control loop is processed. tTaskCycleTime : Cycle time with which the function block is called. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.0 *) : FLOAT. This must be greater than or equal to the TaskCycleTime. with which the output is changed from a lower value to a higher one.9 from Build 947 TwinCAT v2.

The current velocity is output at fVeloOut. : Input magnitude to which the output in eCTRL_MODE_MANUAL is set. The starting value is adopted when eCTRL_MODE_RESET changes to eCTRL_MODE_ACTIVE. and calculation of the ramp begins. : FLOAT. : BOOL. : Finishing value for the ramp.BECHHOFF 162 Description: This function block generates a ramp connecting the starting value fStartValue and the final value fTargetValue. Behaviour of the output value: VAR_INPUT VAR_INPUT fStartValue fTargetValue fManValue bHold eMode END_VAR fStartValue fTargetValue fManValue bHold eMode : Starting value for the ramp. : E_CTRL_MODE. As long as the block remains in eCTRL_MODE_ACTIVE the target value can be changed. : Input that specifies the block's operating mode. : FLOAT.e. The slope of the ramp (i. taking the form of a ramp as it moves from the current value to the presently active target value. It is possible to use this for feed forward in the control loop. and the output value changes. : Calculation of the ramp is halted at the current value. the velocity) is given in units/s by means of the fVeloPos and fVeloNeg parameters. TwinCAT PLC Library: Controller Toolbox . : FLOAT.

(* controller cycle time [TIME] *) fVeloPos fVeloNeg END_STRUCT END_TYPE tCtrlCycleTime : FLOAT. tTaskCycleTime : Cycle time with which the function block is called. This consists of the following elements: TYPE ST_CTRL_RAMP_GENERATOR_EXT_PARAMS : STRUCT tTaskCycleTime : TIME. with which the output is changed from a higher value to a lower one. : E_CTRL_ERRORCODES.0) in unit/s. This must be greater than or equal to the TaskCycleTime. : BOOL.BECHHOFF 163 VAR_OUTPUT VAR_OUTPUT fOut fVeloOut bValueReached eState eErrorId bError END_VAR fOut fVeloOut : Output of the ramp generator. (* task cycle time [TIME] *) tCtrlCycleTime : TIME. : Becomes TRUE as soon as an error situation occurs. END_VAR stParams : Parameter structure of the ramp generator. : Supplies the error number when the bError output is set. : FLOAT. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. with which the output is changed from a lower value to a higher one. fVeloPos fVeloNeg : Velocity (>0. (* velocity ramp by time range: > 0. eState eErrorId bError : State of the function block. bValueReached : This output indicates by going TRUE that the output fOut has reached the value fTargetValue. : BOOL. : FLOAT. : E_CTRL_STATE. : Velocity (>0. VAR_IN_OUT VAR_IN_OUT stParams: ST_CTRL_RAMP_GENERATOR_EXT_PARAMS. (* velocity ramp by time range: > 0.0 *) : Cycle time with which the control loop is processed. If the block is called in every task cycle this corresponds to the task cycle time of the calling task.0) in unit/s.0 *) : FLOAT. : Current velocity of the ramp generator. TwinCAT PLC Library: Controller Toolbox .

lib TcControllerToolbox. and so forth. Behaviour of the output value: Example table: 18 20 22 24 The first line of the table corresponds to Index 1.BECHHOFF 164 Development environment TwinCAT v2. TwinCAT PLC Library: Controller Toolbox .9. at the second to Index 2. Changing from one set value to another can be implemented continuously or discontinuously.8 TwinCAT v2.lb6 TcControllerToolbox. build 956 onwards Target system type PC (i386) BC BX PLC libraries to be linked TcControllerToolbox. build 947 onwards TwinCAT v2.9.lbx FUNCTION_BLOCK FB_CTRL_SETPOINT_GENERATOR The function block provides a set value generator that outputs the set value selected from a table.

: SETPOINT_TABLE_ELEMENT. : E_CTRL_STATE. i. : BOOL. : E_CTRL_MODE. eState eErrorId bError : State of the function block. : Supplies the error number when the bError output is set.BECHHOFF 165 Description: The individual set values are stored in the array.. The velocity of a continuous transition is specified by the fVeloPos and fVeloNeg parameters. This consists of the following elements: TYPE ST_CTRL_SETPOINT_GENERATOR_PARAMS: TwinCAT PLC Library: Controller Toolbox .. : FLOAT. : Becomes TRUE. and can be used as the set value for the controller. The bValueReached output indicates that the chosen set value has been reached. bValueReached : The output is TRUE when the selected set value has been reached. the ramp leading to the selected value has finished. (* parameters *) END_VAR stParams : Parameter structure of the ramp generator. : E_CTRL_ERRORCODES. : BOOL. : Input that specifies the block's operating mode. n] *). VAR_IN_OUT VAR_IN_OUT stParams : ST_CTRL_SETPOINT_GENERATOR_PARAMS. (*[1 . as soon as an error occurs.e. : Input whose value is output in manual mode. The array must be made known to the block through the appropriate parameters. Changing from one value to another can be implemented in a linear fashion or as a jump. VAR_INPUT VAR_INPUT nSetpointIndex : INT fManValue eMode END_VAR nSetpointIndex fManValue eMode : Index of the selected set value. VAR_OUTPUT VAR_OUTPUT fOut bValueReached eState eErrorId bError END_VAR fOut : Output of the set value generator. This is then made available at the output. One of the set values stored in the table is selected by means of the nSetpointIndex input.

with which the output is changed from a higher value to a lower one. pDataTable_ADR : Address of the data array. pDataTable_NumberOfRows : Number of lines in the data array. nDataTable_NumberOfRows : UINT := 0. bDisableRamping: A continuous output value is not calculated if this parameter is TRUE.BECHHOFF 166 STRUCT tCtrlCycleTime tTaskCycleTime : TIME := T#0ms. (* task cycle time [TIME] *) pDataTable_ADR : POINTER TO INTERPOLATION_TABLE_ELEMENT := 0. The output simply jumps between the two values. (* velocity ramp by time range > 0. tTaskCycleTime : Cycle time with which the function block is called. fVeloPos fVeloNeg bDisableRamping END_STRUCT END_TYPE : FLOAT. This must be greater than or equal to the TaskCycleTime.0 *) : FLOAT. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle. pDataTable_SIZEOF : Size of the data array. TwinCAT PLC Library: Controller Toolbox .0 *) : BOOL := FALSE. with which the output is changed from a lower value to a higher one. fVeloPos fVeloNeg : Velocity in unit/s. (* velocity ramp by time range > 0. nDataTable_SIZEOF : UINT := 0. (* controller cycle time [TIME] *) : TIME := T#0ms. : Velocity in unit/s. If the block is called in every cycle this corresponds to the task cycle time of the calling task. tCtrlCycleTime : Cycle time with which the control loop is processed.

Output signals: TwinCAT PLC Library: Controller Toolbox . sine and sawtooth signal forms.BECHHOFF 167 FUNCTION_BLOCK FB_CTRL_SIGNAL_GENERATOR The function block provides a signal generator offering triangular.

: E_CTRL_STATE. : Supplies the error number when the bError output is set. : Becomes TRUE.BECHHOFF 168 VAR_INPUT VAR_INPUT fManValue eMode END_VAR fManValue eMode : Input whose value is present at the output in manual mode. : FLOAT. : ST_CTRL_SIGNAL_GENERATOR_PARAMS. This must be greater than or equal to the TwinCAT PLC Library: Controller Toolbox . as soon as an error occurs. END_STRUCT END_TYPE tCtrlCycleTime : Cycle time with which the control loop is processed. tStart : TIME := T#0s. : E_CTRL_MODE. (* controller cycle time *) tTaskCycleTime : TIME := T#0ms. VAR_OUTPUT VAR_OUTPUT fOut eState eErrorId bError END_VAR fOut eState eErrorId bError : Output of the signal generator. : FLOAT. fOffset : FLOAT := 0. : E_CTRL_ERRORCODES. : Input that specifies the block's operating mode. This consists of the following elements: TYPE ST_CTRL_I_PARAMS : STRUCT tCtrlCycleTime : TIME := T#0ms. : State of the function block. fAmplitude : FLOAT. VAR_IN_OUT VAR_IN_OUT stParams END_VAR stParams : Parameter structure of the function block. (* task cycle time *) eSignalType : E_CTRL_SIGNAL_TYPE. : BOOL. tCylceDuration : TIME.0.

tStart : The moment of time within a period at which following the signal curve will begin when switching into eCTRL_MODE_ACTIVE occurs. tTaskCycleTime : Cycle time with which the function block is called.BECHHOFF 169 TaskCycleTime. The function block uses this input variable to calculate internally whether the state and the output variables have to be updated in the current cycle.lbx := 0. := 1.9 from Build 956 Target System PC (i386) BC BX PLC libraries to include TcControllerToolbox. If the block is called in every cycle this corresponds to the task cycle time of the calling task. END_TYPE Development Environment TwinCAT v2. : Offset to be added to the signal curve. See E_CTRL_SIGNAL_TYPE below. TYPE E_CTRL_SIGNAL_TYPE : ( eCTRL_TRIANGLE eCTRL_SINUS eCTRL_SAWTOOTH ).lb6 TcControllerToolbox. eSignalType tCycleDuration fAmplitude fOffset : Selection of the type of signal.lib TcControllerToolbox.8 TwinCAT v2. : Period of the generated signal curve. : Amplitude of the generated signal curve. := 2 TwinCAT PLC Library: Controller Toolbox .9 from Build 947 TwinCAT v2.

(* mode selftest *) eCTRL_MODE_SYNC_MOVEMENT := 7 (* mode synchronize *) ). TYPE FLOAT : REAL. the function blocks in the library only work with the FLOAT data type. This data type is defined as LREAL or as REAL in a supplementary library.lib" is linked for BC systems. (* mode tuning *) eCTRL_MODE_SELFTEST := 6. (* mode active *) eCTRL_MODE_RESET := 3. END_TYPE E_CTRL_MODE: TYPE E_CTRL_MODE : ( eCTRL_MODE_IDLE := 0. (* state passive *) := 2. (* mode idle *) eCTRL_MODE_PASSIVE := 1.lib" is linked for BX systems. FLOAT: The library is structured in such a way that it can run either on a PC. BX or on a BC system. TYPE FLOAT : LREAL. (* state reset *) TwinCAT PLC Library: Controller Toolbox . (* mode manual *) eCTRL_MODE_TUNE := 5.lib" is linked for PC systems. (* state active *) := 3.BECHHOFF 170 Appendix Definition of the structures and enums All the structures and enums used in the Controller Toolbox are described in this appendix. The supplementary library "TcFloatPC. (* state idle *) := 1. (* mode reset *) eCTRL_MODE_MANUAL := 4. END_TYPE The supplementary library "TcFloatBX. TYPE FLOAT : REAL. END_TYPE The supplementary library "TcFloatBC. (* mode passive *) eCTRL_MODE_ACTIVE := 2. To achieve this portability. END_TYPE E_CTRL_STATE : TYPE E_CTRL_STATE : ( eCTRL_STATE_IDLE eCTRL_STATE_PASSIVE eCTRL_STATE_ACTIVE eCTRL_STATE_RESET := 0.

(* invalid parameter *) := 16. (* state tuning *) := 6.BECHHOFF 171 eCTRL_STATE_MANUAL eCTRL_STATE_TUNING eCTRL_STATE_SELFTEST := 4. (* invalid parameter *) := 12. (* state manual *) := 5. (* no error *) := 1. (* invalid parameter *) := 9. (* state tuning *) := 7. (* invalid parameter *) := 14. (* invalid parameter *) := 6. (* invalid parameter *) := 17. (* invalid parameter *) := 7. (* invalid ctrl cycle time *) := 3. (* invalid parameter *) := 21. (* invalid parameter *) := 18. (* invalid parameter *) := 20. (* invalid parameter *) := 13. (* invalid parameter *) := 10. (* invalid task cycle time *) := 2. (* invalid parameter *) := 5. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fHystereisisRange eCTRL_ERROR_INVALIDPARAM_fPosOutOn_Off eCTRL_ERROR_INVALIDPARAM_fNegOutOn_Off eCTRL_ERROR_INVALIDPARAM_TableDescription eCTRL_ERROR_INVALIDPARAM_TableData eCTRL_ERROR_INVALIDPARAM_DataTableADR eCTRL_ERROR_INVALIDPARAM_T0 eCTRL_ERROR_INVALIDPARAM_T1 eCTRL_ERROR_INVALIDPARAM_T2 eCTRL_ERROR_INVALIDPARAM_T3 eCTRL_ERROR_INVALIDPARAM_Theta eCTRL_ERROR_INVALIDPARAM_nOrder eCTRL_ERROR_INVALIDPARAM_Tt eCTRL_ERROR_INVALIDPARAM_Tu TwinCAT PLC Library: Controller Toolbox . END_TYPE E_CTRL_ERRORCODES: TYPE E_CTRL_ERRORCODES : ( eCTRL_ERROR_NOERROR eCTRL_ERROR_INVALIDTASKCYCLETIME eCTRL_ERROR_INVALIDCTRLCYCLETIME eCTRL_ERROR_INVALIDPARAM eCTRL_ERROR_INVALIDPARAM_Tv eCTRL_ERROR_INVALIDPARAM_Td eCTRL_ERROR_INVALIDPARAM_Tn eCTRL_ERROR_INVALIDPARAM_Ti := 0. (* identification *) := 8 := 9 (* state error *) (* state synchronizing movement *) eCTRL_STATE_IDENTIFICATION eCTRL_STATE_ERROR eCTRL_STATE_SYNC_MOVEMENT ). (* invalid parameter *) := 11. (* invalid parameter *) := 19. (* invalid parameter *) := 4. (* invalid parameter *) := 15. (* invalid parameter *) := 8.

(* invalid parameter *) := 23. (* invalid parameter *) := 39. (* internal error *) eCTRL_ERROR_INVALIDPARAM_nParameterChangeCycleTicks TwinCAT PLC Library: Controller Toolbox . eCTRL_ERROR_INVALIDPARAM_fOuterWindowIsLessThanfInnerWindow (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fDeadBandInput eCTRL_ERROR_INVALIDPARAM_fDeadBandOutput eCTRL_ERROR_INVALIDPARAM_PWM_Cycletime eCTRL_ERROR_INVALIDPARAM_no_Parameterset eCTRL_ERROR_INVALIDPARAM_fOutOn eCTRL_ERROR_INVALIDPARAM_fOutOff eCTRL_ERROR_INVALIDPARAM_fGain eCTRL_ERROR_INVALIDPARAM_fOffset eCTRL_ERROR_MODE_NOT_SUPPORTED := 29. (* invalid parameter *) := 37. (* invalid parameter *) := 43.BECHHOFF 172 eCTRL_ERROR_INVALIDPARAM_Tg eCTRL_ERROR_INVALIDPARAM_infinite_slope eCTRL_ERROR_INVALIDPARAM_fMaxIsLessThanfMin := 22. eCTRL_ERROR_INVALIDPARAM_fOutMaxLimitIsLessThanfOutMinLimit (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fOuterWindow eCTRL_ERROR_INVALIDPARAM_fInnerWindow := 26. (* invalid parameter *) := 30. (* invalid parameter *) := 27. (* invalid mode: mode not supported *) eCTRL_ERROR_INVALIDPARAM_Tv_heating eCTRL_ERROR_INVALIDPARAM_Td_heating eCTRL_ERROR_INVALIDPARAM_Tn_heating eCTRL_ERROR_INVALIDPARAM_Tv_cooling eCTRL_ERROR_INVALIDPARAM_Td_cooling eCTRL_ERROR_INVALIDPARAM_Tn_cooling eCTRL_ERROR_RANGE_NOT_SUPPORTED := 38. (* internal error *) := 49. (* invalid parameter *) := 45. (* invalid parameter *) eCTRL_ERROR_ParameterEstimationFailed eCTRL_ERROR_NoiseLevelToHigh eCTRL_ERROR_INTERNAL_ERROR_0 eCTRL_ERROR_INTERNAL_ERROR_1 eCTRL_ERROR_INTERNAL_ERROR_2 eCTRL_ERROR_INTERNAL_ERROR_3 eCTRL_ERROR_INTERNAL_ERROR_4 := 46. (* invalid parameter *) := 35. (* invalid parameter *) := 34. (* invalid parameter *) := 33. (* internal error *) := 52. (* invalid parameter *) := 24. (* invalid parameter *) := 40. (* internal error *) := 50. (* invalid parameter *) := 41. (* invalid parameter *) := 36. (* invalid parameter *) := 42. (* internal error *) := 51. (* invalid parameter *) := 48. (* invalid parameter *) := 31. (* invalid parameter *) := 47. (* invalid parameter *) := 28. (* invalid parameter *) := 32. (* invalid parameter *) := 25. (* invalid parameter *) := 44.

(* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fMaxLimitIsGreaterThan100 := 83. (*invalid parameter*) eCTRL_ERROR_INVALIDPARAM_fStepSize := 84. (* invalid parameter *) := 62. (* invalid parameter *) := 65. (* internal error *) := 56. (* invalid parameter *) := 79. (* internal error *) := 58. (* MEMSET failed *) := 71. (* invalid parameter *) := 80. (* invalid parameter *) := 64. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fThreshold eCTRL_ERROR_MEMCPY eCTRL_ERROR_MEMSET eCTRL_ERROR_INVALIDPARAM_nNumberOfColumns eCTRL_ERROR_FileClose eCTRL_ERROR_FileOpen eCTRL_ERROR_FileWrite eCTRL_ERROR_INVALIDPARAM_fVeloNeg eCTRL_ERROR_INVALIDPARAM_fVeloPos eCTRL_ERROR_INVALIDPARAM_DeadBandInput eCTRL_ERROR_INVALIDPARAM_DeadBandOutput eCTRL_ERROR_INVALIDPARAM_CycleDuration eCTRL_ERROR_INVALIDPARAM_tStart := 68. (* File Close failed *) := 73.BECHHOFF 173 eCTRL_ERROR_INTERNAL_ERROR_5 eCTRL_ERROR_INTERNAL_ERROR_6 eCTRL_ERROR_INTERNAL_ERROR_7 eCTRL_ERROR_INTERNAL_ERROR_8 eCTRL_ERROR_INTERNAL_ERROR_9 eCTRL_ERROR_INVALIDPARAM_WorkArrayADR eCTRL_ERROR_INVALIDPARAM_tOnTiime eCTRL_ERROR_INVALIDPARAM_tOffTiime eCTRL_ERROR_INVALIDPARAM_nMaxMovingPulses := 53. (* invalid parameter *) := 69. (* invalid parameter *) := 76. (* internal error *) := 57. (* invalid parameter *) := 78. (* internal error *) := 55. (* internal error *) := 54. (* invalid parameter *) := 61. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fMinLimitIsLessThanZero:= 82. (* File Write failed *) := 75. (* File Open failed *) := 74. (* invalid parameter *) := 60. (* invalid parameter *) := 72. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_tAdditionalMoveTimeAtLimits := 67. (* invalid parameter *) := 66. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_StepHeigthTuningToLow:= 81. (* MEMCPY failed *) := 70. (* invalid parameter *) := 77. (* invalid parameter *) := 59. (* invalid parameter *) TwinCAT PLC Library: Controller Toolbox . (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nAdditionalPulsesAtLimits eCTRL_ERROR_INVALIDPARAM_fCtrlOutMax_Min eCTRL_ERROR_INVALIDPARAM_fDeltaMax eCTRL_ERROR_INVALIDPARAM_tMovingTime eCTRL_ERROR_INVALIDPARAM_tDeadTime := 63.

(* invalid parameter *) := 100. (* invalid parameter *) eCTRL_ERROR_SIZEOF := 95. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nNumeratorArray_SIZEOF := 97. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nDenominatorArray_SIZEOF := 98. (* invalid parameter *) := 90. (* File Delete failed *) eCTRL_ERROR_INVALIDPARAM_nPwmInputArray_SIZEOF:= 91. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nPwmInternalData_SIZEOF := 94. (* invalid parameter *) := 106. (* invalid parameter *) := 103. (* invalid parameter *) := 108. (* invalid parameter *) := 110. (* invalid parameter *) := 88. (* invalid parameter *) eCTRL_ERROR_INVALIDPWMPeriod eCTRL_ERROR_INVALIDPARAM_tMinimumPulseTime eCTRL_ERROR_FileDelete eCTRL_ERROR_INVALIDPARAM_nNumberOfPwmOutputs := 87. (* invalid parameter *) := 109. (* invalid parameter *) := 104. (* SIZEOF failed *) eCTRL_ERROR_INVALIDPARAM_nOrderOfTheTransferfunction := 96. eCTRL_ERROR_INVALIDPARAM_fMinLimitIsGreaterThanfMaxLimit (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_DataTableSIZEOF := 105. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_a_n_IsZero eCTRL_ERROR_INVALIDPARAM_WorkArraySIZEOF eCTRL_ERROR_INVALIDPARAM_MOVINGRANGE_MIN_MAX eCTRL_ERROR_INVALIDPARAM_MOVINGTIME eCTRL_ERROR_INVALIDPARAM_DEADTIME := 99. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_OutputVectorDescription TwinCAT PLC Library: Controller Toolbox . (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nPwmWaitTimesConfig_SIZEOF := 93. (* invalid parameter *) := 89.BECHHOFF 174 eCTRL_ERROR_INVALIDPARAM_fOkRangeIsLessOrEqualZero := 85. (* invalid parameter *) := 102. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fForceRangeIsLessOrEqualfOkRange := 86. (* invalid parameter *) eCTRL_ERROR_TaskCycleTimeChanged eCTRL_ERROR_INVALIDPARAM_nMinMovingPulses eCTRL_ERROR_INVALIDPARAM_fAcceleration eCTRL_ERROR_INVALIDPARAM_fDeceleration := 107.(* invalid parameter *) := 101. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nPwmOutputArray_SIZEOF:= 92.

(* invalid parameter *) := 131. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nLogBuffer_SIZEOF eCTRL_ERROR_LogBufferOverflow eCTRL_ERROR_INVALIDPARAM_nLogBuffer_ADR := 128. (* internal error NT_GetTime *) eCTRL_ERROR_INVALIDPARAM_No3PhaseSolutionPossible:= 117. (* invalid parameter *) := 129. (* invalid parameter *) := 112. (* invalid parameter *) := 120 (* invalid parameter *) := 121. (* invalid parameter *) := 114.BECHHOFF 175 eCTRL_ERROR_INVALIDPARAM_StartAndTargetPos eCTRL_ERROR_INVALIDPARAM_fVelocity eCTRL_ERROR_INVALIDPARAM_fTargetPos eCTRL_ERROR_INVALIDPARAM_fStartPos eCTRL_ERROR_INVALIDPARAM_fMovingLength eCTRL_ERROR_NT_GetTime := 111. (* invalid parameter *) := 135. (* invalid parameter *) := 122. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nCoefficientsArray_b_SIZEOF := 126. (* invalid parameter *) := 134. (* invalid parameter *) := 116. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nCoefficientsArray_b_ADR := 132. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nDigitalFiterData_ADR:= 137. (* invalid parameter *) := 130. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nCoefficientsArray_a_ADR eCTRL_ERROR_INVALIDPARAM_nPwmWaitTimesConfig_ADR TwinCAT PLC Library: Controller Toolbox . (* invalid parameter *) := 119. (* invalid parameter *) := 113. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nPwmInputArray_ADR eCTRL_ERROR_INVALIDPARAM_nPwmOutputArray_ADR := 133. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nPwmInternalData_ADR := 136. (* invalid parameter *) := 115. eCTRL_ERROR_INVALIDPARAM_nOrderOfTheTransferfunction_SIZEOF (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nFilterOrder := 124. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nDigitalFiterData_SIZEOF := 127. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_fStartVelo eCTRL_ERROR_INVALIDPARAM_fTargetVelo eCTRL_ERROR_INVALID_NEW_PARAMETER_TYPE eCTRL_ERROR_INVALIDPARAM_fBaseTime := 118. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nCoefficientsArray_a_SIZEOF := 125.

END_TYPE E_CTRL_SIGNAL_TYPE: TYPE E_CTRL_SIGNAL_TYPE : ( eCTRL_TRIANGLE := 0. and can thus be run on any Windows NT PC without additional hardware. This project contains programs using the individual function blocks. The example program uses simulations of controlled systems. The control system is simulated for all of these programs. • The TwinCAT system is started through the TwinCAT icon on the taskbar. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nTransferfunction2Data_ADR := 141 (* invalid parameter *) ). with which the basic functionality is illustrated.zip. Install and start the example project The TcControllerToolbox offers the programmer transfer elements with which a very wide variety of controllers can be implemented. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nTransferfunction1Data_ADR := 140. (* invalid parameter *) eCTRL_ERROR_INVALIDPARAM_nDenominatorArray_ADR:= 139. The illustrations include some examples and also the construction of more complex control systems. END_TYPE Example project The ways in which the blocks in the TcControllerToolbox function are illustrated in an example project. • Save and unpack the example program from TcControllerToolboxExamples. eCTRL_SAWTOOTH := 2 ). so that no hardware is necessary for the project.BECHHOFF 176 eCTRL_ERROR_INVALIDPARAM_nNumeratorArray_ADR := 138. TwinCAT PLC Library: Controller Toolbox . eCTRL_SINUS := 1.

Load the PLC project via the menu Online . translated and started. or click "Force Values" in the online menu.scp can be used for this purpose.Run TwinCAT ScopeView allows the signal curves from the individual examples to be displayed graphically. Because the example project contains a number of different examples. • • • • Load the PRO file Compile the PLC project via the menu Project . This specification of the Scope file to be used for each particular example can be found in the comments in the project's MAIN program. Press the F7 key.Login into the runtime system Start the program via the menu Online . TwinCAT PLC Library: Controller Toolbox . The settings supplied in TcControllerToolboxExamples_Scope_x. • • Load the SCP file into TwinCAT ScopeView Start recording via the menu or via the F5 key. it is necessary to set the variable nExampleSelector to the appropriate example number in the MAIN program. • Double-click on the nExampleSelector variable • • Enter the number of the example.BECHHOFF 177 The TcControllerToolbox_Examples.pro example program is loaded into TwinCAT PLC Control. OK.Rebuild All.

scp TcControllerToolboxExamples_Scope_1.scp 10 11 12 13 14 15 16 TcControllerToolboxExamples_Scope_3.scp TcControllerToolboxExamples_Scope_1.scp 20 TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_4.scp TcControllerToolboxExamples_Scope_5.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.BECHHOFF 178 Assigning the program numbers The programs are selected through the nExampleSelector variable in MAIN.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_5.scp TcControllerToolboxExamples_Scope_5.scp 21 22 23 24 25 26 TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_5.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.scp TwinCAT PLC Library: Controller Toolbox . Function block to which the example relates Base FB_CTRL_P FB_CTRL_I FB_CTRL_D FB_CTRL_HYSTERESIS FB_CTRL_TRANSFERFUNCTION_1 FB_CTRL_TRANSFERFUNCTION_2 Controller FB_CTRL_2POINT FB_CTRL_3POINT FB_CTRL_3POINT_EXT FB_CTRL_nPOINT FB_CTRL_PI FB_CTRL_PID FB_CTRL_PID_EXT Filter / Controlled System Simulation FB_CTRL_ACTUAL_VALUE_FILTE R FB_CTRL_ARITHMETIC_MEAN FB_CTRL_MOVING_AVERAGE FB_CTRL_PT1 FB_CTRL_PT2 FB_CTRL_PT2oscillation FB_CTRL_PT3 nExampleSelecto Scope File r 1 2 3 4 5 6 TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_5.scp TcControllerToolboxExamples_Scope_2.scp TcControllerToolboxExamples_Scope_1.

scp 80 81 TcControllerToolboxExamples_Scope_6.scp 30 31 TcControllerToolboxExamples_Scope_1.scp 50 51 52 53 54 55 TcControllerToolboxExamples_Scope_1.BECHHOFF 179 FB_CTRL_PTn FB_CTRL_PTt FB_CTRL_TuTg Interpolation FB_CTRL_INTERPOLATION FB_CTRL_NORMALIZE Monitoring / Alarming FB_CTRL_CHECK_IF_IN_BAND FB_CTRL_LOG_DATA Output to Controlling Equipment FB_CTRL_DEADBAND FB_CTRL_LIMITER FB_CTRL_PWM_OUT FB_CTRL_PWM_OUT_EXT FB_CTRL_MULTIPLE_PWM_OUT FB_CTRL_SCALE Setpointgeneration FB_CTRL_RAMP_GENERATOR FB_CTRL_SETPOINT_GENERATO R FB_CTRL_SIGNAL_GENERATOR Controlled System Examples FB_CTRL_PID_SPLITRANGE FB_CTRL_PI_PID 27 28 29 TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_9.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.scp 40 41 TcControllerToolboxExamples_Scope_8.scp 62 TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_7.scp 60 61 TcControllerToolboxExamples_Scope_1.scp TwinCAT PLC Library: Controller Toolbox .scp TcControllerToolboxExamples_Scope_1.scp TcControllerToolboxExamples_Scope_11.scp TcControllerToolboxExamples_Scope_9.scp TcControllerToolboxExamples_Scope_10.

The comments in the individual programs should make them clear and easy to understand. TwinCAT PLC Library: Controller Toolbox .BECHHOFF 180 Program Structure The Main module calls up the corresponding example program in accordance with the variable nExampleSelector.